Skip to content

Commit e1dc9d6

Browse files
committed
Merge branch 'feature/CG-996' into 'master'
feat(services): add new service rds cluster snapshot Closes CG-996 See merge request auto-cloud/cloudgraph/provider/cloudgraph-provider-aws!226
2 parents cb56aff + 24dee5e commit e1dc9d6

20 files changed

Lines changed: 395 additions & 5 deletions

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,15 @@ CloudGraph AWS Provider will ask you what regions you would like to crawl and wi
127127
| iot | |
128128
| kinesisFirehose | kinesisStream, s3 |
129129
| kinesisStream | kinesisFirehose |
130-
| kms | cloudtrail, cloudwatchLog, codebuild, efs, eksCluster, elastiCacheReplicationGroup, elasticSearchDomain, emrCluster, lambda, sns, sageMakerNotebookInstance, dmsReplicationInstance, redshiftCluster |
130+
| kms | cloudtrail, cloudwatchLog, codebuild, efs, eksCluster, elastiCacheReplicationGroup, elasticSearchDomain, emrCluster, lambda, rdsClusterSnapshot, sns, sageMakerNotebookInstance, dmsReplicationInstance, redshiftCluster |
131131
| lambda | appSync, cognitoUserPool, kms, securityGroup, subnet, vpc |
132132
| managedAirflow | iamRole, securityGroups, subnet, s3 |
133133
| nacl | vpc |
134134
| natGateway | networkInterface, subnet, vpc |
135135
| networkInterface | ec2, eip, efsMountTarget, natGateway, sageMakerNotebookInstance, subnet, vpc, flowLog |
136136
| organization |
137-
| rdsCluster | appSync, rdsDbInstance, securityGroup |
137+
| rdsCluster | appSync, rdsClusterSnapshot, rdsDbInstance, securityGroup |
138+
| rdsClusterSnapshot | kms, rdsCluster, vpc |
138139
| rdsDbInstance | rdsCluster, securityGroup, vpc, subnet |
139140
| redshiftCluster | kms, vpc |
140141
| route53Record | alb, apiGatewayRestApi, elb, route53HostedZone |
@@ -154,7 +155,7 @@ CloudGraph AWS Provider will ask you what regions you would like to crawl and wi
154155
| systemsManagerDocument | |
155156
| transitGateway | routeTable, transitGatewayAttachment, vpnConnection |
156157
| transitGatewayAttachment | routeTable, transitGateway, vpc, vpnConnection |
157-
| vpc | alb, codebuild, dmsReplicationInstance, ec2, eip, elb, ecsService, efsMountTarget, eksCluster igw, elastiCacheCluster, elasticSearchDomain, lambda, nacl, natGateway, networkInterface, rdsDbInstance, redshiftCluster, route53HostedZone, routeTable, subnet, flowLog, vpnGateway, transitGatewayAttachment |
158+
| vpc | alb, codebuild, dmsReplicationInstance, ec2, eip, elb, ecsService, efsMountTarget, eksCluster igw, elastiCacheCluster, elasticSearchDomain, lambda, nacl, natGateway, networkInterface, rdsClusterSnapshot, rdsDbInstance, redshiftCluster, route53HostedZone, routeTable, subnet, flowLog, vpnGateway, transitGatewayAttachment |
158159
| vpnConnection | customerGateway, transitGateway, transitGatewayAttachment, vpnGateway |
159160
| vpnGateway | vpc, vpnConnection |
160161
| wafV2WebAcl | |

src/enums/schemasMap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export default {
7878
[services.vpnGateway]: 'awsVpnGateway',
7979
[services.sqs]: 'awsSqs',
8080
[services.rdsCluster]: 'awsRdsCluster',
81+
[services.rdsClusterSnapshot]: 'awsRdsClusterSnapshot',
8182
[services.rdsDbInstance]: 'awsRdsDbInstance',
8283
[services.redshiftCluster]: 'awsRedshiftCluster',
8384
[services.route53HostedZone]: 'awsRoute53HostedZone',

src/enums/serviceAliases.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export default {
5050
[services.networkInterface]: 'networkInterfaces',
5151
[services.organization]: 'organizations',
5252
[services.rdsCluster]: 'rdsClusters',
53+
[services.rdsClusterSnapshot]: 'rdsClusterSnapshots',
5354
[services.rdsDbInstance]: 'rdsDbInstances',
5455
[services.redshiftCluster]: 'redshiftClusters',
5556
[services.route53HostedZone]: 'route53HostedZones',

src/enums/serviceMap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import DmsReplicationInstance from '../services/dmsReplicationInstance'
9393
import SageMakerNotebookInstance from '../services/sageMakerNotebookInstance'
9494
import SystemsManagerInstance from '../services/systemsManagerInstance'
9595
import SystemsManagerDocument from '../services/systemsManagerDocument'
96+
import RdsClusterSnapshot from '../services/rdsClusterSnapshot'
9697

9798
/**
9899
* serviceMap is an object that contains all currently supported services for AWS
@@ -157,6 +158,7 @@ export default {
157158
[services.vpc]: VPC,
158159
[services.sqs]: SQS,
159160
[services.rdsCluster]: RDSCluster,
161+
[services.rdsClusterSnapshot]: RdsClusterSnapshot,
160162
[services.rdsDbInstance]: RDSDbInstance,
161163
[services.redshiftCluster]: RedshiftCluster,
162164
[services.route53HostedZone]: Route53HostedZone,

src/enums/services.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export default {
6868
networkInterface: 'networkInterface',
6969
organization: 'organization',
7070
rdsCluster: 'rdsCluster',
71+
rdsClusterSnapshot: 'rdsClusterSnapshot',
7172
rdsDbInstance: 'rdsDbInstance',
7273
redshiftCluster: 'redshiftCluster',
7374
route53HostedZone: 'route53HostedZone',

src/services/account/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type awsAccount @key(fields: "id") {
7070
networkInterfaces: [awsNetworkInterface]
7171
organizations: [awsOrganization]
7272
rdsClusters: [awsRdsCluster]
73+
rdsClusterSnapshots: [awsRdsClusterSnapshot]
7374
rdsDbInstances: [awsRdsDbInstance]
7475
redshiftClusters: [awsRedshiftCluster]
7576
route53HostedZones: [awsRoute53HostedZone]

src/services/kms/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ type awsKms @key(fields: "id"){
2929
elasticSearchDomains: [awsElasticSearchDomain] @hasInverse(field: kms)
3030
dmsReplicationInstances: [awsDmsReplicationInstance] @hasInverse(field: kms)
3131
sageMakerNotebookInstances: [awsSageMakerNotebookInstance] @hasInverse(field: kms)
32+
rdsClusterSnapshots: [awsRdsClusterSnapshot] @hasInverse(field: kms)
3233
}

src/services/rdsCluster/connections.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { SecurityGroup } from 'aws-sdk/clients/ec2'
44
import { DBInstance, DBCluster } from 'aws-sdk/clients/rds'
55

66
import services from '../../enums/services'
7+
import { RawAwsRdsClusterSnapshot } from '../rdsClusterSnapshot/data'
78

89
export default ({
910
service,
@@ -27,7 +28,7 @@ export default ({
2728
)
2829

2930
/**
30-
* Find instances
31+
* Find rds db instances
3132
*/
3233
const instances: {
3334
name: string
@@ -51,6 +52,30 @@ export default ({
5152
}
5253
}
5354

55+
/**
56+
* Find cluster snapshots
57+
*/
58+
const snapshots: {
59+
name: string
60+
data: { [property: string]: RawAwsRdsClusterSnapshot[] }
61+
} = data.find(({ name }) => name === services.rdsClusterSnapshot)
62+
63+
if (snapshots?.data?.[region]) {
64+
const dataInRegion: RawAwsRdsClusterSnapshot[] = snapshots.data[region].filter(
65+
({ DBClusterIdentifier }: RawAwsRdsClusterSnapshot) => DBClusterIdentifier === clusterId
66+
)
67+
if (!isEmpty(dataInRegion)) {
68+
for (const snapshot of dataInRegion) {
69+
connections.push({
70+
id: snapshot.DBClusterSnapshotIdentifier,
71+
resourceType: services.rdsClusterSnapshot,
72+
relation: 'child',
73+
field: 'snapshots',
74+
})
75+
}
76+
}
77+
}
78+
5479
/**
5580
* Find SecurityGroups
5681
*/

src/services/rdsCluster/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type awsRdsCluster @key(fields: "arn") {
3434
globalWriteForwardingRequested: Boolean @search
3535
tags: [awsRawTag]
3636
instances: [awsRdsDbInstance] @hasInverse(field: cluster)
37+
snapshots: [awsRdsClusterSnapshot] @hasInverse(field: cluster)
3738
securityGroups: [awsSecurityGroup] @hasInverse(field: rdsCluster)
3839
appSync: [awsAppSync] @hasInverse(field: rdsCluster)
3940
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { ServiceConnection } from '@cloudgraph/sdk'
2+
import { isEmpty } from 'lodash'
3+
import { RawAwsRdsClusterSnapshot } from './data'
4+
import services from '../../enums/services'
5+
6+
export default ({
7+
service,
8+
data,
9+
region,
10+
}: {
11+
account: string
12+
service: RawAwsRdsClusterSnapshot
13+
data: { name: string; data: { [property: string]: any[] } }[]
14+
region: string
15+
}): {
16+
[property: string]: ServiceConnection[]
17+
} => {
18+
const { DBClusterSnapshotIdentifier, KmsKeyId } = service
19+
const connections: ServiceConnection[] = []
20+
21+
/**
22+
* Find KMS
23+
*/
24+
const kmsKeys = data.find(({ name }) => name === services.kms)
25+
if (kmsKeys?.data?.[region]) {
26+
const kmsKeyInRegion = kmsKeys.data[region].filter(kmsKey => kmsKey.Arn === KmsKeyId)
27+
if (!isEmpty(kmsKeyInRegion)) {
28+
for (const kms of kmsKeyInRegion) {
29+
connections.push({
30+
id: kms.KeyId,
31+
resourceType: services.kms,
32+
relation: 'child',
33+
field: 'kms',
34+
})
35+
}
36+
}
37+
}
38+
39+
const result = {
40+
[DBClusterSnapshotIdentifier]: connections,
41+
}
42+
return result
43+
}

0 commit comments

Comments
 (0)