-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CG-1339): add kms connection to ebs snapshot
- Loading branch information
Showing
5 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters