Skip to content

Commit 4745e2f

Browse files
committed
Merge branch 'feature/CG-884' into 'master'
feat(account): Created global schema to put together AWS services. Closes CG-884 See merge request auto-cloud/cloudgraph/provider/cloudgraph-provider-aws!218
2 parents 5a1d5c1 + 8601b6c commit 4745e2f

24 files changed

Lines changed: 615 additions & 252 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"terraform:cleanup": "rimraf ./tests/terraform/{.terraform,.terraform.lock.hcl,tfplan} ./tests/terraform/*.{tfstate,tfplan,backup}"
3333
},
3434
"dependencies": {
35-
"@cloudgraph/sdk": "0.10.7",
35+
"@cloudgraph/sdk": "0.14.2",
3636
"@fast-csv/parse": "^4.3.6",
3737
"@graphql-tools/load-files": "6.3.2",
3838
"@graphql-tools/merge": "8.0.1",

src/enums/schemasMap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import services from './services'
44
* schemasMap is an object that contains schemas name by resource
55
*/
66
export default {
7+
account: 'awsAccount',
78
[services.alb]: 'awsAlb',
89
[services.apiGatewayResource]: 'awsApiGatewayResource',
910
[services.apiGatewayRestApi]: 'awsApiGatewayRestApi',

src/enums/serviceAliases.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import services from './services'
2+
3+
export default {
4+
[services.alb]: 'albs',
5+
[services.apiGatewayResource]: 'apiGatewayResources',
6+
[services.apiGatewayRestApi]: 'apiGatewayRestApis',
7+
[services.apiGatewayStage]: 'apiGatewayStages',
8+
[services.asg]: 'asgs',
9+
[services.athenaDataCatalog]: 'athenaDataCatalogs',
10+
[services.cloud9]: 'cloud9Environments',
11+
[services.cloudFormationStack]: 'cloudFormationStacks',
12+
[services.cloudFormationStackSet]: 'cloudFormationStackSets',
13+
[services.cloudfront]: 'cloudfrontDistributions',
14+
[services.cloudwatchLog]: 'cloudwatchLogs',
15+
[services.codebuild]: 'codebuilds',
16+
[services.configurationRecorder]: 'configurationRecorders',
17+
[services.dmsReplicationInstance]: 'dmsReplicationInstances',
18+
[services.ec2Instance]: 'ec2Instances',
19+
[services.ecsCluster]: 'ecsClusters',
20+
[services.ecsContainer]: 'ecsContainers',
21+
[services.ecsService]: 'ecsServices',
22+
[services.ecsTask]: 'ecsTasks',
23+
[services.ecsTaskDefinition]: 'ecsTaskDefinitions',
24+
[services.ecsTaskSet]: 'ecsTaskSets',
25+
[services.eksCluster]: 'eksClusters',
26+
[services.elastiCacheCluster]: 'elastiCacheClusters',
27+
[services.elastiCacheReplicationGroup]: 'elastiCacheReplicationGroups',
28+
[services.elasticBeanstalkApp]: 'elasticBeanstalkApps',
29+
[services.elasticBeanstalkEnv]: 'elasticBeanstalkEnvs',
30+
[services.elasticSearchDomain]: 'elasticSearchDomains',
31+
[services.elb]: 'elbs',
32+
[services.emrCluster]: 'emrClusters',
33+
[services.emrInstance]: 'emrInstances',
34+
[services.emrStep]: 'emrSteps',
35+
[services.flowLog]: 'flowLogs',
36+
[services.glueJob]: 'glueJobs',
37+
[services.glueRegistry]: 'glueRegistries',
38+
[services.guardDutyDetector]: 'guardDutyDetectors',
39+
[services.iamGroup]: 'iamGroups',
40+
[services.iamOpenIdConnectProvider]: 'iamOpenIdConnectProviders',
41+
[services.iamPasswordPolicy]: 'iamPasswordPolicies',
42+
[services.iamPolicy]: 'iamPolicies',
43+
[services.iamRole]: 'iamRoles',
44+
[services.iamSamlProvider]: 'iamSamlProviders',
45+
[services.iamServerCertificate]: 'iamServerCertificates',
46+
[services.iamUser]: 'iamUsers',
47+
[services.kinesisStream]: 'kinesisStreams',
48+
[services.lambda]: 'lambdaFunctions',
49+
[services.nat]: 'natGateway',
50+
[services.networkInterface]: 'networkInterfaces',
51+
[services.organization]: 'organizations',
52+
[services.rdsCluster]: 'rdsClusters',
53+
[services.rdsDbInstance]: 'rdsDbInstances',
54+
[services.redshiftCluster]: 'redshiftClusters',
55+
[services.route53HostedZone]: 'route53HostedZones',
56+
[services.route53Record]: 'route53Records',
57+
[services.routeTable]: 'routeTables',
58+
[services.sageMakerExperiment]: 'sageMakerExperiments',
59+
[services.sageMakerNotebookInstance]: 'sageMakerNotebookInstances',
60+
[services.sageMakerProject]: 'sageMakerProjects',
61+
[services.secretsManager]: 'secretsManager',
62+
[services.sg]: 'securityGroups',
63+
[services.subnet]: 'subnets',
64+
[services.systemsManagerDocument]: 'systemsManagerDocuments',
65+
[services.systemsManagerInstance]: 'systemsManagerInstances',
66+
[services.transitGatewayAttachment]: 'transitGatewayAttachments',
67+
[services.vpnConnection]: 'vpnConnections',
68+
}

src/enums/serviceMap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Account from '../services/account'
12
import ALB from '../services/alb'
23
import APIGatewayResource from '../services/apiGatewayResource'
34
import APIGatewayRestApi from '../services/apiGatewayRestApi'
@@ -98,6 +99,7 @@ import SystemsManagerDocument from '../services/systemsManagerDocument'
9899
* serviceMap is used by the serviceFactory to produce instances of service classes
99100
*/
100101
export default {
102+
account: Account,
101103
[services.appSync]: AppSync,
102104
[services.alb]: ALB,
103105
[services.apiGatewayResource]: APIGatewayResource,

src/enums/services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default {
7474
route53Record: 'route53Record',
7575
routeTable: 'routeTable',
7676
sageMakerExperiment: 'sageMakerExperiment',
77-
sageMakerNotebookInstance: 'sageMakerNotebookInstance',
77+
sageMakerNotebookInstance: 'sageMakerNotebookInstance',
7878
sageMakerProject: 'sageMakerProject',
7979
s3: 's3',
8080
secretsManager: 'secretsManager',
@@ -90,5 +90,5 @@ export default {
9090
vpc: 'vpc',
9191
vpnConnection: 'vpnConnection',
9292
vpnGateway: 'vpnGateway',
93-
wafV2WebAcl: 'wafV2WebAcl'
93+
wafV2WebAcl: 'wafV2WebAcl',
9494
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Entity, ServiceConnection } from '@cloudgraph/sdk'
2+
import { flatMap } from 'lodash'
3+
import services from '../../enums/services'
4+
import aliases from '../../enums/serviceAliases'
5+
6+
export default ({
7+
service,
8+
data,
9+
}: {
10+
service: { id: string; regions: string[] }
11+
data: Entity[]
12+
}): {
13+
[property: string]: ServiceConnection[]
14+
} => {
15+
const { id: accountId } = service
16+
const connections: ServiceConnection[] = []
17+
const connectTo = Object.values(services)
18+
19+
for (const serviceName of connectTo) {
20+
const instances: {
21+
name: string
22+
data: { [property: string]: any[] }
23+
} = data.find(({ name }) => name === serviceName)
24+
25+
if (instances?.data) {
26+
const filtered = flatMap(instances.data).filter(
27+
i => i.accountId === accountId
28+
)
29+
30+
for (const instance of filtered) {
31+
if (instance) {
32+
connections.push({
33+
id: instance.id,
34+
resourceType: serviceName,
35+
relation: 'child',
36+
field: aliases[serviceName] ? aliases[serviceName] : serviceName,
37+
})
38+
}
39+
}
40+
}
41+
}
42+
43+
return {
44+
[accountId]: connections,
45+
}
46+
}

src/services/account/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Service } from '@cloudgraph/sdk'
2+
import BaseService from '../base'
3+
import mutation from './mutation'
4+
5+
export default class AwsAccount extends BaseService implements Service {
6+
format = ({ service }: { service: any }): any => service
7+
8+
getData
9+
10+
mutation = mutation
11+
}

src/services/account/mutation.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default `mutation($input: [AddawsAccountInput!]!) {
2+
addawsAccount(input: $input, upsert: true) {
3+
numUids
4+
}
5+
}`
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
type awsAccount @key(fields: "id") {
2+
id: String! @id @search(by: [hash])
3+
regions: [String] @search(by: [hash])
4+
albs: [awsAlb]
5+
apiGatewayResources: [awsApiGatewayResource]
6+
apiGatewayRestApis: [awsApiGatewayRestApi]
7+
apiGatewayStages: [awsApiGatewayStage]
8+
appSync: [awsAppSync]
9+
asgs: [awsAsg]
10+
athenaDataCatalogs: [awsAthenaDataCatalog]
11+
billing: [awsBilling]
12+
clientVpnEndpoint: [awsClientVpnEndpoint]
13+
cloud9Environments: [awsCloud9Environment]
14+
cloudFormationStacks: [awsCloudFormationStack]
15+
cloudFormationStackSets: [awsCloudFormationStackSet]
16+
cloudfrontDistributions: [awsCloudfront]
17+
cloudtrail: [awsCloudtrail]
18+
cloudwatch: [awsCloudwatch]
19+
cloudwatchLogs: [awsCloudwatchLog]
20+
codebuilds: [awsCodebuild]
21+
cognitoIdentityPool: [awsCognitoIdentityPool]
22+
cognitoUserPool: [awsCognitoUserPool]
23+
configurationRecorders: [awsConfigurationRecorder]
24+
customerGateway: [awsCustomerGateway]
25+
dmsReplicationInstances: [awsDmsReplicationInstance]
26+
dynamodb: [awsDynamoDbTable]
27+
ebs: [awsEbs]
28+
ec2Instances: [awsEc2]
29+
ecr: [awsEcr]
30+
ecsClusters: [awsEcsCluster]
31+
ecsContainers: [awsEcsContainer]
32+
ecsServices: [awsEcsService]
33+
ecsTasks: [awsEcsTask]
34+
ecsTaskDefinitions: [awsEcsTaskDefinition]
35+
ecsTaskSets: [awsEcsTaskSet]
36+
efs: [awsEfs]
37+
efsMountTarget: [awsEfsMountTarget]
38+
eip: [awsEip]
39+
eksClusters: [awsEksCluster]
40+
elastiCacheClusters: [awsElastiCacheCluster]
41+
elastiCacheReplicationGroups: [awsElastiCacheReplicationGroup]
42+
elasticBeanstalkApps: [awsElasticBeanstalkApp]
43+
elasticBeanstalkEnvs: [awsElasticBeanstalkEnv]
44+
elasticSearchDomains: [awsElasticSearchDomain]
45+
elbs: [awsElb]
46+
emrClusters: [awsEmrCluster]
47+
emrInstances: [awsEmrInstance]
48+
emrSteps: [awsEmrStep]
49+
flowLogs: [awsFlowLog]
50+
glueJobs: [awsGlueJob]
51+
glueRegistries: [awsGlueRegistry]
52+
guardDutyDetectors: [awsGuardDutyDetector]
53+
iamGroups: [awsIamGroup]
54+
iamOpenIdConnectProviders: [awsIamOpenIdConnectProvider]
55+
iamPasswordPolicies: [awsIamPasswordPolicy]
56+
iamPolicies: [awsIamPolicy]
57+
iamRoles: [awsIamRole]
58+
iamSamlProviders: [awsIamSamlProvider]
59+
iamServerCertificates: [awsIamServerCertificate]
60+
iamUsers: [awsIamUser]
61+
igw: [awsIgw]
62+
iot: [awsIotThingAttribute]
63+
kinesisFirehose: [awsKinesisFirehose]
64+
kinesisStream: [awsKinesisStream]
65+
kms: [awsKms]
66+
lambdaFunctions: [awsLambda]
67+
managedAirflows: [awsManagedAirflow]
68+
nacl: [awsNetworkAcl]
69+
natGateway: [awsNatGateway]
70+
networkInterfaces: [awsNetworkInterface]
71+
organizations: [awsOrganization]
72+
rdsClusters: [awsRdsCluster]
73+
rdsDbInstances: [awsRdsDbInstance]
74+
redshiftClusters: [awsRedshiftCluster]
75+
route53HostedZones: [awsRoute53HostedZone]
76+
route53Records: [awsRoute53Record]
77+
routeTables: [awsRouteTable]
78+
s3: [awsS3]
79+
sageMakerExperiments: [awsSageMakerExperiment]
80+
sageMakerNotebookInstances: [awsSageMakerNotebookInstance]
81+
sageMakerProjects: [awsSageMakerProject]
82+
secretsManager: [awsSecretsManager]
83+
securityGroups: [awsSecurityGroup]
84+
systemsManagerDocuments: [awsSystemsManagerDocument]
85+
systemsManagerInstances: [awsSystemsManagerInstance]
86+
ses: [awsSes]
87+
sns: [awsSns]
88+
sqs: [awsSqs]
89+
subnets: [awsSubnet]
90+
transitGateway: [awsTransitGateway]
91+
transitGatewayAttachments: [awsTransitGatewayAttachment]
92+
vpc: [awsVpc]
93+
vpnConnection: [awsVpnConnection]
94+
vpnGateway: [awsVpnGateway]
95+
wafV2WebAcl: [awsWafV2WebAcl]
96+
}

0 commit comments

Comments
 (0)