Skip to content

Commit beac5fd

Browse files
committed
feat(CG-1339): add kms connection to ebs snapshot
1 parent a446229 commit beac5fd

File tree

5 files changed

+70
-3
lines changed

5 files changed

+70
-3
lines changed

src/services/ebs/connections.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import isEmpty from 'lodash/isEmpty'
22

3-
import EC2, {
3+
import {
44
Volume,
55
Snapshot,
66
TagList,
@@ -10,7 +10,6 @@ import { ServiceConnection } from '@cloudgraph/sdk'
1010

1111
import services from '../../enums/services'
1212

13-
1413
/**
1514
* EBS
1615
*/
@@ -34,7 +33,6 @@ export default ({
3433
const {
3534
VolumeId: id,
3635
SnapshotId: snapshotId,
37-
Tags: tags,
3836
} = volume
3937

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

src/services/ebsSnapshot/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 EBSSnapshot 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/ebsSnapshot/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type awsEbsSnapshot implements awsBaseService @key(fields: "arn") {
1717
storageTier: String @search(by: [hash, regexp])
1818
restoreExpiryTime: String @search(by: [hash, regexp])
1919
ebs: [awsEbs] @hasInverse(field: ebsSnapshots)
20+
kms: [awsKms] @hasInverse(field: ebsSnapshots)
2021
}
2122

2223
type awsEbsPermission

src/services/kms/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@ type awsKms implements awsBaseService @key(fields: "id") {
5252
rdsDbInstance: [awsRdsDbInstance] @hasInverse(field: kms)
5353
managedAirflows: [awsManagedAirflow] @hasInverse(field: kms)
5454
s3: [awsS3] @hasInverse(field: kms)
55+
ebsSnapshots: [awsEbsSnapshot] @hasInverse(field: kms)
5556
}

0 commit comments

Comments
 (0)