-
Notifications
You must be signed in to change notification settings - Fork 14
feat(cg-1342): support opsworks services #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zhouse51
wants to merge
5
commits into
alpha
Choose a base branch
from
feature/CG-1342-support-opsworks-service
base: alpha
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
636e359
feat(CG-1342): add opsworks stack, app, instance service
zhouse51 b180215
Merge branch 'alpha' into feature/CG-1342-support-opsworks-service
zhouse51 5cb3312
using appId instead of name to build the arn
zhouse51 2671268
Merge branch 'alpha' into feature/CG-1342-support-opsworks-service
m-pizarro 2b93682
feat(services): update account connections
m-pizarro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import CloudGraph from '@cloudgraph/sdk' | ||
import { AWSError } from 'aws-sdk/lib/error' | ||
import { Config } from 'aws-sdk/lib/config' | ||
import isEmpty from 'lodash/isEmpty' | ||
import flatMap from 'lodash/flatMap' | ||
import groupBy from 'lodash/groupBy' | ||
import awsLoggerText from '../../properties/logger' | ||
import { initTestEndpoint, setAwsRetryOptions } from '../../utils' | ||
import AwsErrorLog from '../../utils/errorLog' | ||
import { API_GATEWAY_CUSTOM_DELAY } from '../../config/constants' | ||
import OpsWorks, { App, DescribeAppsResult } from 'aws-sdk/clients/opsworks' | ||
import OpsWorksStack from '../opsworksStack' | ||
import { RawAwsOpsWorksStack } from '../opsworksStack/data' | ||
|
||
const lt = { ...awsLoggerText } | ||
const { logger } = CloudGraph | ||
const serviceName = 'OpsWorks Stack' | ||
const errorLog = new AwsErrorLog(serviceName) | ||
const endpoint = initTestEndpoint(serviceName) | ||
const customRetrySettings = setAwsRetryOptions({ | ||
baseDelay: API_GATEWAY_CUSTOM_DELAY, | ||
}) | ||
|
||
export const getOpsWorksAppsForRegion = async ( | ||
opsWorks: OpsWorks, | ||
StackId: string, | ||
): Promise<App[]> => | ||
new Promise(async resolve => { | ||
const listAllApps = (): void => { | ||
try { | ||
opsWorks.describeApps( | ||
{StackId}, | ||
(err: AWSError, data: DescribeAppsResult) => { | ||
if (err) { | ||
errorLog.generateAwsErrorLog({ | ||
functionName: 'opsWorks:describeApps', | ||
err, | ||
}) | ||
} | ||
|
||
if (isEmpty(data)) { | ||
return resolve([]) | ||
} | ||
|
||
const { Apps: apps = [] } = data || {} | ||
|
||
logger.debug(lt.fetchedOpsWorksApps(apps.length)) | ||
|
||
resolve(apps) | ||
} | ||
); | ||
} catch (error) { | ||
resolve([]) | ||
} | ||
} | ||
listAllApps() | ||
}) | ||
|
||
export interface RawAwsOpsWorksApp extends Omit<App, 'tags'> { | ||
region: string | ||
account | ||
} | ||
|
||
export default async ({ | ||
regions, | ||
config, | ||
account, | ||
}: { | ||
account: string | ||
regions: string | ||
config: Config | ||
}): Promise<{ | ||
[region: string]: RawAwsOpsWorksApp[] | ||
}> => | ||
new Promise(async resolve => { | ||
const opsWorksResult: RawAwsOpsWorksApp[] = [] | ||
const opsWorksStackClass = new OpsWorksStack({ logger: CloudGraph.logger }) | ||
const stacksResult = await opsWorksStackClass.getData({ | ||
...config, | ||
regions, | ||
}) | ||
const opsWorksStacks: RawAwsOpsWorksStack[] = flatMap(stacksResult) | ||
|
||
|
||
const regionPromises = regions.split(',').map(region => { | ||
const opsWorks = new OpsWorks({ | ||
...config, | ||
region, | ||
endpoint, | ||
...customRetrySettings, | ||
}) | ||
|
||
return new Promise<void>(async resolveOpsWorksData => { | ||
// Get OpsWorks Apps Data | ||
opsWorksStacks.map(async ({StackId}: RawAwsOpsWorksStack) => { | ||
const opsWorksApps = await getOpsWorksAppsForRegion(opsWorks, StackId) | ||
|
||
if (!isEmpty(opsWorksApps)) { | ||
for (const app of opsWorksApps) { | ||
opsWorksResult.push({ | ||
...app, | ||
region, | ||
account, | ||
}) | ||
} | ||
} | ||
}) | ||
|
||
resolveOpsWorksData() | ||
}) | ||
}) | ||
|
||
await Promise.all(regionPromises) | ||
errorLog.reset() | ||
|
||
resolve(groupBy(opsWorksResult, 'region')) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { generateUniqueId } from '@cloudgraph/sdk' | ||
|
||
import { RawAwsOpsWorksApp } from './data' | ||
import { AwsOpsWorksApp } from '../../types/generated' | ||
import { opsworksAppArn } from '../../utils/generateArns' | ||
|
||
export default ({ | ||
service, | ||
account: accountId, | ||
region, | ||
}: { | ||
service: RawAwsOpsWorksApp | ||
account: string | ||
region: string | ||
}): AwsOpsWorksApp => { | ||
const { | ||
AppId: appId, | ||
StackId: stackId, | ||
Shortname: shortname, | ||
Name: name, | ||
Description: description, | ||
DataSources: dataSources, | ||
Type: type, | ||
AppSource: appSource, | ||
Domains: domains, | ||
EnableSsl: enableSsl, | ||
SslConfiguration: sslConfiguration, | ||
Attributes: attributes, | ||
CreatedAt: createdAt, | ||
Environment: environment, | ||
} = service | ||
|
||
const arn = opsworksAppArn({ region, account: accountId, name: name }) | ||
|
||
return { | ||
id: appId, | ||
accountId, | ||
arn, | ||
region, | ||
stackId, | ||
shortname, | ||
name, | ||
description, | ||
dataSources: dataSources.map(ds => ({ | ||
id: generateUniqueId({ | ||
arn, | ||
...ds, | ||
}), | ||
type: ds.Type, | ||
arn: ds.Arn, | ||
databaseName: ds.DatabaseName, | ||
})), | ||
type, | ||
appSource: { | ||
type: appSource?.Type, | ||
url: appSource?.Url, | ||
username: appSource?.Username, | ||
password: appSource?.Password, | ||
sshKey: appSource?.SshKey, | ||
revision: appSource?.Revision, | ||
}, | ||
domains, | ||
enableSsl, | ||
sslConfiguration: { | ||
certificate: sslConfiguration?.Certificate, | ||
privateKey: sslConfiguration?.PrivateKey, | ||
chain: sslConfiguration?.Chain, | ||
}, | ||
attributes: Object.keys(attributes).map(key => ({ | ||
id: generateUniqueId({ | ||
arn, | ||
key, | ||
value: attributes[key], | ||
}), | ||
key, | ||
value: attributes[key], | ||
})), | ||
createdAt, | ||
environment: environment.map(e => ({ | ||
id: generateUniqueId({ | ||
arn, | ||
...e, | ||
}), | ||
key: e.Key, | ||
value: e.Value, | ||
secure: e.Secure, | ||
})) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Service } from '@cloudgraph/sdk' | ||
import BaseService from '../base' | ||
import format from './format' | ||
import getData from './data' | ||
import mutation from './mutation' | ||
|
||
export default class OpsWorksApp extends BaseService implements Service { | ||
format = format.bind(this) | ||
|
||
getData = getData.bind(this) | ||
|
||
mutation = mutation | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default `mutation($input: [AddawsOpsWorksAppInput!]!) { | ||
addawsOpsWorksApp(input: $input, upsert: true) { | ||
numUids | ||
} | ||
}` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
type awsOpsWorksAppDataSource | ||
@generate( | ||
query: { get: false, query: false, aggregate: false } | ||
mutation: { add: false, delete: false } | ||
subscription: false | ||
) { | ||
id: String! @id @search(by: [hash]) | ||
type: String @search(by: [hash, regexp]) | ||
arn: String @search(by: [hash, regexp]) | ||
databaseName: String @search(by: [hash, regexp]) | ||
} | ||
|
||
type awsOpsWorksAppSource | ||
@generate( | ||
query: { get: false, query: false, aggregate: false } | ||
mutation: { add: false, delete: false } | ||
subscription: false | ||
) { | ||
type: String @search(by: [hash, regexp]) | ||
url: String @search(by: [hash, regexp]) | ||
username: String @search(by: [hash, regexp]) | ||
password: String @search(by: [hash, regexp]) | ||
sshKey: String @search(by: [hash, regexp]) | ||
revision: String @search(by: [hash, regexp]) | ||
} | ||
|
||
type awsOpsWorksAppSslConfiguration | ||
@generate( | ||
query: { get: false, query: false, aggregate: false } | ||
mutation: { add: false, delete: false } | ||
subscription: false | ||
) { | ||
certificate: String @search(by: [hash, regexp]) | ||
privateKey: String @search(by: [hash, regexp]) | ||
chain: String @search(by: [hash, regexp]) | ||
} | ||
|
||
type awsOpsWorksAppAttribute | ||
@generate( | ||
query: { get: false, query: false, aggregate: false } | ||
mutation: { add: false, delete: false } | ||
subscription: false | ||
) { | ||
id: String! @id @search(by: [hash]) | ||
key: String @search(by: [hash, regexp]) | ||
value: String @search(by: [hash, regexp]) | ||
} | ||
|
||
type awsOpsWorksAppEnvironment | ||
@generate( | ||
query: { get: false, query: false, aggregate: false } | ||
mutation: { add: false, delete: false } | ||
subscription: false | ||
) { | ||
id: String! @id @search(by: [hash]) | ||
key: String @search(by: [hash, regexp]) | ||
value: String @search(by: [hash, regexp]) | ||
secure: Boolean @search | ||
} | ||
|
||
type awsOpsWorksApp implements awsBaseService @key(fields: "arn") { | ||
stackId: String @search(by: [hash, regexp]) | ||
shortname: String @search(by: [hash, regexp]) | ||
name: String @search(by: [hash, regexp]) | ||
description: String @search(by: [hash, regexp]) | ||
dataSources: [awsOpsWorksAppDataSource] | ||
type: String @search(by: [hash, regexp]) | ||
appSource: awsOpsWorksAppSource | ||
domains: [String] @search(by: [hash, regexp]) | ||
enableSsl: Boolean @search | ||
sslConfiguration: awsOpsWorksAppSslConfiguration | ||
attributes: [awsOpsWorksAppAttribute] | ||
createdAt: String @search(by: [hash, regexp]) | ||
environment: [awsOpsWorksAppEnvironment] | ||
opsWorksStacks: [awsOpsWorksStack] @hasInverse(field: opsWorksApps) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.