Skip to content

Commit cd5f784

Browse files
authored
Merge pull request #117 from cloudgraphdev/feature/CG-1339-add-aws-ebs-snapshot
feat(CG-1339): add aws ebs snapshot
2 parents b6cffe6 + 38a9d5e commit cd5f784

File tree

19 files changed

+508
-2
lines changed

19 files changed

+508
-2
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ CloudGraph AWS Provider will ask you what regions you would like to crawl and wi
9494
| customerGateway | vpnConnection |
9595
| dynamodb | appSync, iamRole, kms |
9696
| dmsReplicationInstance | securityGroup, subnet, vpc, kms |
97-
| ebs | asg, ec2, emrInstance |
97+
| ebs | asg, ec2, emrInstance, ebsSnapshot |
98+
| ebsSnapshot | ebs, kms |
9899
| ec2 | alb, asg, ebs, eip, emrInstance, eksCluster, elasticBeanstalkEnv, iamInstanceProfile, iamRole, networkInterface, securityGroup, subnet, systemsManagerInstance, vpc, ecsContainer |
99100
| ecr | |
100101
| ecsCluster | cloudwatchLog, ecsService, ecsTask, ecsTaskSet, kms, s3 |
@@ -134,7 +135,7 @@ CloudGraph AWS Provider will ask you what regions you would like to crawl and wi
134135
| iot | |
135136
| kinesisFirehose | kinesisStream, s3, iamRole |
136137
| kinesisStream | kinesisFirehose |
137-
| kms | cloudtrail, cloudwatchLog, codebuild, ecsCluster, efs, eksCluster, elastiCacheReplicationGroup, elasticSearchDomain, emrCluster, managedAirflow, lambda, rdsCluster, rdsClusterSnapshot, rdsDbInstance, sns, sageMakerNotebookInstance, secretsManager, dmsReplicationInstance, redshiftCluster, s3 |
138+
| kms | cloudtrail, cloudwatchLog, codebuild, ecsCluster, efs, eksCluster, elastiCacheReplicationGroup, elasticSearchDomain, emrCluster, managedAirflow, lambda, rdsCluster, rdsClusterSnapshot, rdsDbInstance, sns, sageMakerNotebookInstance, secretsManager, dmsReplicationInstance, redshiftCluster, s3, ebsSnapshot |
138139
| lambda | appSync, cognitoUserPool, kms, s3, secretsManager, securityGroup, subnet, vpc, iamRole |
139140
| managedAirflow | cloudwatchLog, iamRole, kms, securityGroups, subnet, s3 |
140141
| managedPrefixList | |

src/enums/resources.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default {
2323
sqsQueue: 'aws_sqs_queue',
2424
iamGroup: 'aws_iam_group',
2525
snsTopic: 'aws_sns_topic',
26+
ebsSnapshot: 'aws_ebs_snapshot',
2627
ebsVolume: 'aws_ebs_volume',
2728
iamPolicy: 'aws_iam_policy',
2829
vpnGateway: 'aws_vpn_gateway',

src/enums/schemasMap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default {
3131
[services.dmsReplicationInstance]: 'awsDmsReplicationInstance',
3232
[services.dynamodb]: 'awsDynamoDbTable',
3333
[services.ebs]: 'awsEbs',
34+
[services.ebsSnapshot]: 'awsEbsSnapshot',
3435
[services.ec2Instance]: 'awsEc2',
3536
[services.ecr]: 'awsEcr',
3637
[services.ecsCluster]: 'awsEcsCluster',

src/enums/serviceAliases.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default {
1717
[services.codebuild]: 'codebuilds',
1818
[services.configurationRecorder]: 'configurationRecorders',
1919
[services.dmsReplicationInstance]: 'dmsReplicationInstances',
20+
[services.ebsSnapshot]: 'ebsSnapshots',
2021
[services.ec2Instance]: 'ec2Instances',
2122
[services.ecsCluster]: 'ecsClusters',
2223
[services.ecsContainer]: 'ecsContainers',

src/enums/serviceMap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import CognitoIdentityPool from '../services/cognitoIdentityPool'
2323
import CognitoUserPool from '../services/cognitoUserPool'
2424
import DynamoDB from '../services/dynamodb'
2525
import EBS from '../services/ebs'
26+
import EBSSnapshot from '../services/ebsSnapshot'
2627
import EC2 from '../services/ec2'
2728
import EcsCluster from '../services/ecsCluster'
2829
import EcsContainer from '../services/ecsContainer'
@@ -133,6 +134,7 @@ export default {
133134
[services.cognitoUserPool]: CognitoUserPool,
134135
[services.configurationRecorder]: ConfigurationRecorder,
135136
[services.ebs]: EBS,
137+
[services.ebsSnapshot]: EBSSnapshot,
136138
[services.ec2Instance]: EC2,
137139
[services.ecr]: ECR,
138140
[services.efs]: EFS,

src/enums/services.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default {
2525
dmsReplicationInstance: 'dmsReplicationInstance',
2626
dynamodb: 'dynamodb',
2727
ebs: 'ebs',
28+
ebsSnapshot: 'ebsSnapshot',
2829
ec2Instance: 'ec2Instance',
2930
ecr: 'ecr',
3031
ecsCluster: 'ecsCluster',

src/properties/logger.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ export default {
249249
doneFetchingEbsData: '✅ Done fetching EBS Data ✅',
250250
fetchedEbsVolumes: (num: number): string => `Fetched ${num} EBS Volumes`,
251251
lookingForEbs: 'Looking for EBS volumes for EC2 instances...',
252+
/**
253+
* EBS Snapshot
254+
*/
255+
fetchingEbsSnapshotData: 'Fetching EBS Snapshot data for this AWS account via the AWS SDK...',
256+
doneFetchingEbsSnapshotData: '✅ Done fetching EBS Snapshot Data ✅',
257+
fetchedEbsSnapshots: (num: number): string => `Fetched ${num} EBS Snapshots`,
258+
lookingForEbsSnapshot: 'Looking for EBS Snapshots...',
252259
/**
253260
* EC2
254261
*/

src/services/ebs/connections.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import isEmpty from 'lodash/isEmpty'
2+
3+
import {
4+
Volume,
5+
Snapshot,
6+
TagList,
7+
} from 'aws-sdk/clients/ec2'
8+
9+
import { ServiceConnection } from '@cloudgraph/sdk'
10+
11+
import services from '../../enums/services'
12+
13+
/**
14+
* EBS
15+
*/
16+
17+
export default ({
18+
service: volume,
19+
data,
20+
region,
21+
account,
22+
}: {
23+
account: string
24+
data: { name: string; data: { [property: string]: any[] } }[]
25+
service: Volume & {
26+
region: string
27+
Tags?: TagList
28+
}
29+
region: string
30+
}): { [key: string]: ServiceConnection[] } => {
31+
const connections: ServiceConnection[] = []
32+
33+
const {
34+
VolumeId: id,
35+
SnapshotId: snapshotId,
36+
} = volume
37+
38+
/**
39+
* Find EBS Snapshot
40+
* related to this EBS Volume
41+
*/
42+
const ebsSnapshots: {
43+
name: string
44+
data: { [property: string]: Snapshot[] }
45+
} = data.find(({ name }) => name === services.ebsSnapshot)
46+
47+
if (ebsSnapshots?.data?.[region]) {
48+
const snapshotInRegion: Snapshot[] = ebsSnapshots.data[region].filter(
49+
({ SnapshotId }: Snapshot) => SnapshotId === snapshotId
50+
)
51+
52+
if (!isEmpty(snapshotInRegion)) {
53+
for (const sh of snapshotInRegion) {
54+
connections.push({
55+
id: sh.SnapshotId,
56+
resourceType: services.ebsSnapshot,
57+
relation: 'child',
58+
field: 'ebsSnapshots',
59+
})
60+
}
61+
}
62+
}
63+
64+
const ebsResult = {
65+
[id]: connections,
66+
}
67+
return ebsResult
68+
}

src/services/ebs/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ import { Service } from '@cloudgraph/sdk'
22
import BaseService from '../base'
33
import format from './format'
44
import getData from './data'
5+
import getConnections from './connections'
56
import mutation from './mutation'
67

78
export default class EBS extends BaseService implements Service {
89
format = format.bind(this)
910

1011
getData = getData.bind(this)
1112

13+
getConnections = getConnections.bind(this)
14+
1215
mutation = mutation
1316
}

src/services/ebs/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type awsEbs implements awsBaseService @key(fields: "arn") {
1515
ec2Instance: [awsEc2] @hasInverse(field: ebs)
1616
asg: [awsAsg] @hasInverse(field: ebs)
1717
emrInstance: [awsEmrInstance] @hasInverse(field: ebs)
18+
ebsSnapshots: [awsEbsSnapshot] @hasInverse(field: ebs)
1819
}
1920

2021
type awsEbsAttachment

0 commit comments

Comments
 (0)