Skip to content

Commit

Permalink
feat(CG-1339): add kms connection to ebs snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouse51 committed Mar 6, 2023
1 parent a446229 commit beac5fd
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/services/ebs/connections.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import isEmpty from 'lodash/isEmpty'

import EC2, {
import {
Volume,
Snapshot,
TagList,
Expand All @@ -10,7 +10,6 @@ import { ServiceConnection } from '@cloudgraph/sdk'

import services from '../../enums/services'


/**
* EBS
*/
Expand All @@ -34,7 +33,6 @@ export default ({
const {
VolumeId: id,
SnapshotId: snapshotId,
Tags: tags,
} = volume

/**
Expand Down
64 changes: 64 additions & 0 deletions src/services/ebsSnapshot/connections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import isEmpty from 'lodash/isEmpty'

import {
Snapshot,
TagList,
} from 'aws-sdk/clients/ec2'

import { ServiceConnection } from '@cloudgraph/sdk'

import services from '../../enums/services'


/**
* EBS Snapshot
*/

export default ({
service: snapshot,
data,
region,
account,
}: {
account: string
data: { name: string; data: { [property: string]: any[] } }[]
service: Snapshot & {
region: string
Tags?: TagList
}
region: string
}): { [key: string]: ServiceConnection[] } => {
const connections: ServiceConnection[] = []

const {
SnapshotId: id,
KmsKeyId: kmsKeyId,
} = snapshot

/**
* Find KMS
* related to the cloudTrail
*/
const kmsKeys = data.find(({ name }) => name === services.kms)
if (kmsKeys?.data?.[region]) {
const kmsKeyInRegion = kmsKeys.data[region].filter(
kmsKey => kmsKey.Arn === kmsKeyId
)

if (!isEmpty(kmsKeyInRegion)) {
for (const kms of kmsKeyInRegion) {
connections.push({
id: kms.KeyId,
resourceType: services.kms,
relation: 'child',
field: 'kms',
})
}
}
}

const snapshotResult = {
[id]: connections,
}
return snapshotResult
}
3 changes: 3 additions & 0 deletions src/services/ebsSnapshot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { Service } from '@cloudgraph/sdk'
import BaseService from '../base'
import format from './format'
import getData from './data'
import getConnections from './connections'
import mutation from './mutation'

export default class EBSSnapshot extends BaseService implements Service {
format = format.bind(this)

getData = getData.bind(this)

getConnections = getConnections.bind(this)

mutation = mutation
}
1 change: 1 addition & 0 deletions src/services/ebsSnapshot/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type awsEbsSnapshot implements awsBaseService @key(fields: "arn") {
storageTier: String @search(by: [hash, regexp])
restoreExpiryTime: String @search(by: [hash, regexp])
ebs: [awsEbs] @hasInverse(field: ebsSnapshots)
kms: [awsKms] @hasInverse(field: ebsSnapshots)
}

type awsEbsPermission
Expand Down
1 change: 1 addition & 0 deletions src/services/kms/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ type awsKms implements awsBaseService @key(fields: "id") {
rdsDbInstance: [awsRdsDbInstance] @hasInverse(field: kms)
managedAirflows: [awsManagedAirflow] @hasInverse(field: kms)
s3: [awsS3] @hasInverse(field: kms)
ebsSnapshots: [awsEbsSnapshot] @hasInverse(field: kms)
}

0 comments on commit beac5fd

Please sign in to comment.