@@ -5,6 +5,9 @@ import { DBInstance, DBCluster } from 'aws-sdk/clients/rds'
55
66import services from '../../enums/services'
77import { RawAwsRdsClusterSnapshot } from '../rdsClusterSnapshot/data'
8+ import { RawAwsIamRole } from '../iamRole/data'
9+ import { AwsKms } from '../kms/data'
10+ import { globalRegionName } from '../../enums/regions'
811
912export default ( {
1013 service,
@@ -21,6 +24,11 @@ export default ({
2124 const {
2225 DBClusterArn : id ,
2326 DBClusterIdentifier : clusterId ,
27+ MonitoringRoleArn : monitoringRoleArn ,
28+ AssociatedRoles : associatedRoles = [ ] ,
29+ KmsKeyId,
30+ ActivityStreamKmsKeyId,
31+ PerformanceInsightsKMSKeyId,
2432 VpcSecurityGroups,
2533 } = service
2634 const sgIds = VpcSecurityGroups . map (
@@ -55,14 +63,17 @@ export default ({
5563 /**
5664 * Find cluster snapshots
5765 */
58- const snapshots : {
66+ const snapshots : {
5967 name : string
6068 data : { [ property : string ] : RawAwsRdsClusterSnapshot [ ] }
6169 } = data . find ( ( { name } ) => name === services . rdsClusterSnapshot )
6270
6371 if ( snapshots ?. data ?. [ region ] ) {
64- const dataInRegion : RawAwsRdsClusterSnapshot [ ] = snapshots . data [ region ] . filter (
65- ( { DBClusterIdentifier } : RawAwsRdsClusterSnapshot ) => DBClusterIdentifier === clusterId
72+ const dataInRegion : RawAwsRdsClusterSnapshot [ ] = snapshots . data [
73+ region
74+ ] . filter (
75+ ( { DBClusterIdentifier } : RawAwsRdsClusterSnapshot ) =>
76+ DBClusterIdentifier === clusterId
6677 )
6778 if ( ! isEmpty ( dataInRegion ) ) {
6879 for ( const snapshot of dataInRegion ) {
@@ -101,6 +112,102 @@ export default ({
101112 }
102113 }
103114
115+ /**
116+ * Find KMS
117+ * related to this RDS Cluster
118+ */
119+ const kms : {
120+ name : string
121+ data : { [ property : string ] : AwsKms [ ] }
122+ } = data . find ( ( { name } ) => name === services . kms )
123+
124+ if ( kms ?. data ?. [ region ] ) {
125+ // set storage encryption kms key
126+ let kmsInRegion : AwsKms [ ] = kms . data [ region ] . filter (
127+ ( { Arn } : AwsKms ) => Arn === KmsKeyId
128+ )
129+ if ( ! isEmpty ( kmsInRegion ) ) {
130+ for ( const instance of kmsInRegion ) {
131+ connections . push ( {
132+ id : instance . KeyId ,
133+ resourceType : services . kms ,
134+ relation : 'child' ,
135+ field : 'storageEncryptedKms' ,
136+ } )
137+ }
138+ }
139+
140+ // set activity stream kms key
141+ kmsInRegion = kms . data [ region ] . filter (
142+ ( { Arn } : AwsKms ) => Arn === ActivityStreamKmsKeyId
143+ )
144+ if ( ! isEmpty ( kmsInRegion ) ) {
145+ for ( const instance of kmsInRegion ) {
146+ connections . push ( {
147+ id : instance . KeyId ,
148+ resourceType : services . kms ,
149+ relation : 'child' ,
150+ field : 'activityStreamKms' ,
151+ } )
152+ }
153+ }
154+
155+ // set performance insights kms key
156+ kmsInRegion = kms . data [ region ] . filter (
157+ ( { Arn } : AwsKms ) => Arn === PerformanceInsightsKMSKeyId
158+ )
159+ if ( ! isEmpty ( kmsInRegion ) ) {
160+ for ( const instance of kmsInRegion ) {
161+ connections . push ( {
162+ id : instance . KeyId ,
163+ resourceType : services . kms ,
164+ relation : 'child' ,
165+ field : 'performanceInsightsKms' ,
166+ } )
167+ }
168+ }
169+ }
170+
171+ /**
172+ * Find IAM Role
173+ * related to this RDS Cluster
174+ */
175+ const iamRoles : {
176+ name : string
177+ data : { [ property : string ] : RawAwsIamRole [ ] }
178+ } = data . find ( ( { name } ) => name === services . iamRole )
179+
180+ if ( iamRoles ?. data ?. [ globalRegionName ] ) {
181+ let iamRolesInRegion : RawAwsIamRole [ ] = iamRoles . data [
182+ globalRegionName
183+ ] . filter ( ( { Arn } : RawAwsIamRole ) =>
184+ associatedRoles . find ( r => r . RoleArn === Arn )
185+ )
186+ if ( ! isEmpty ( iamRolesInRegion ) ) {
187+ for ( const instance of iamRolesInRegion ) {
188+ connections . push ( {
189+ id : instance . Arn ,
190+ resourceType : services . iamRole ,
191+ relation : 'child' ,
192+ field : 'iamRoles' ,
193+ } )
194+ }
195+ }
196+ iamRolesInRegion = iamRoles . data [ globalRegionName ] . filter (
197+ ( { Arn } : RawAwsIamRole ) => Arn === monitoringRoleArn
198+ )
199+ if ( ! isEmpty ( iamRolesInRegion ) ) {
200+ for ( const instance of iamRolesInRegion ) {
201+ connections . push ( {
202+ id : instance . Arn ,
203+ resourceType : services . iamRole ,
204+ relation : 'child' ,
205+ field : 'monitoringIamRole' ,
206+ } )
207+ }
208+ }
209+ }
210+
104211 const rdsClusterResult = {
105212 [ id ] : connections ,
106213 }
0 commit comments