11import { ServiceConnection } from '@cloudgraph/sdk'
22import { isEmpty } from 'lodash'
33import { SecurityGroup } from 'aws-sdk/clients/ec2'
4- import { DBInstance , DBCluster } from 'aws-sdk/clients/rds'
4+ import { DBInstance } from 'aws-sdk/clients/rds'
55
66import services from '../../enums/services'
77import { RawAwsRdsCluster } from './data'
8+ import { RawAwsRoute53HostedZone } from '../route53HostedZone/data'
89import { RawAwsRdsClusterSnapshot } from '../rdsClusterSnapshot/data'
910import { RawAwsIamRole } from '../iamRole/data'
1011import { RawAwsSubnet } from '../subnet/data'
@@ -33,6 +34,7 @@ export default ({
3334 ActivityStreamKmsKeyId,
3435 PerformanceInsightsKMSKeyId,
3536 VpcSecurityGroups,
37+ HostedZoneId : hostedZoneId ,
3638 } = service
3739 const sgIds = VpcSecurityGroups . map (
3840 ( { VpcSecurityGroupId } ) => VpcSecurityGroupId
@@ -125,47 +127,19 @@ export default ({
125127 } = data . find ( ( { name } ) => name === services . kms )
126128
127129 if ( kms ?. data ?. [ region ] ) {
128- // set storage encryption kms key
129- let kmsInRegion : AwsKms [ ] = kms . data [ region ] . filter (
130- ( { Arn } : AwsKms ) => Arn === KmsKeyId
130+ const kmsInRegion : AwsKms [ ] = kms . data [ region ] . filter (
131+ ( { Arn } : AwsKms ) =>
132+ Arn === KmsKeyId ||
133+ Arn === ActivityStreamKmsKeyId ||
134+ Arn === PerformanceInsightsKMSKeyId
131135 )
132136 if ( ! isEmpty ( kmsInRegion ) ) {
133137 for ( const instance of kmsInRegion ) {
134138 connections . push ( {
135139 id : instance . KeyId ,
136140 resourceType : services . kms ,
137141 relation : 'child' ,
138- field : 'storageEncryptedKms' ,
139- } )
140- }
141- }
142-
143- // set activity stream kms key
144- kmsInRegion = kms . data [ region ] . filter (
145- ( { Arn } : AwsKms ) => Arn === ActivityStreamKmsKeyId
146- )
147- if ( ! isEmpty ( kmsInRegion ) ) {
148- for ( const instance of kmsInRegion ) {
149- connections . push ( {
150- id : instance . KeyId ,
151- resourceType : services . kms ,
152- relation : 'child' ,
153- field : 'activityStreamKms' ,
154- } )
155- }
156- }
157-
158- // set performance insights kms key
159- kmsInRegion = kms . data [ region ] . filter (
160- ( { Arn } : AwsKms ) => Arn === PerformanceInsightsKMSKeyId
161- )
162- if ( ! isEmpty ( kmsInRegion ) ) {
163- for ( const instance of kmsInRegion ) {
164- connections . push ( {
165- id : instance . KeyId ,
166- resourceType : services . kms ,
167- relation : 'child' ,
168- field : 'performanceInsightsKms' ,
142+ field : 'kms' ,
169143 } )
170144 }
171145 }
@@ -181,10 +155,12 @@ export default ({
181155 } = data . find ( ( { name } ) => name === services . iamRole )
182156
183157 if ( iamRoles ?. data ?. [ globalRegionName ] ) {
184- let iamRolesInRegion : RawAwsIamRole [ ] = iamRoles . data [
158+ const iamRolesInRegion : RawAwsIamRole [ ] = iamRoles . data [
185159 globalRegionName
186- ] . filter ( ( { Arn } : RawAwsIamRole ) =>
187- associatedRoles . find ( r => r . RoleArn === Arn )
160+ ] . filter (
161+ ( { Arn } : RawAwsIamRole ) =>
162+ Arn === monitoringRoleArn ||
163+ associatedRoles . find ( r => r . RoleArn === Arn )
188164 )
189165 if ( ! isEmpty ( iamRolesInRegion ) ) {
190166 for ( const instance of iamRolesInRegion ) {
@@ -196,36 +172,29 @@ export default ({
196172 } )
197173 }
198174 }
199- iamRolesInRegion = iamRoles . data [ globalRegionName ] . filter (
200- ( { Arn } : RawAwsIamRole ) => Arn === monitoringRoleArn
201- )
202- if ( ! isEmpty ( iamRolesInRegion ) ) {
203- for ( const instance of iamRolesInRegion ) {
204- connections . push ( {
205- id : instance . Arn ,
206- resourceType : services . iamRole ,
207- relation : 'child' ,
208- field : 'monitoringIamRole' ,
209- } )
210- }
211- }
212175 }
213176
214177 /**
215- * Find KMS
178+ * Find Route53 hosted zones
216179 */
217- const kmsKeys = data . find ( ( { name } ) => name === services . kms )
218- if ( kmsKeys ?. data ?. [ region ] ) {
219- const kmsKeyInRegion = kmsKeys . data [ region ] . filter (
220- kmsKey => kmsKey . Arn === KmsKeyId
221- )
222- if ( ! isEmpty ( kmsKeyInRegion ) ) {
223- for ( const kms of kmsKeyInRegion ) {
180+ const route53HostedZones : {
181+ name : string
182+ data : { [ property : string ] : RawAwsRoute53HostedZone [ ] }
183+ } = data . find ( ( { name } ) => name === services . route53HostedZone )
184+
185+ if ( route53HostedZones ?. data ?. [ region ] ) {
186+ const instancesInRegion : RawAwsRoute53HostedZone [ ] =
187+ route53HostedZones . data [ region ] . filter (
188+ ( { Id } : RawAwsRoute53HostedZone ) => Id === hostedZoneId
189+ )
190+ if ( ! isEmpty ( instancesInRegion ) ) {
191+ for ( const instance of instancesInRegion ) {
192+ const { Id : id } = instance
224193 connections . push ( {
225- id : kms . KeyId ,
226- resourceType : services . kms ,
194+ id,
195+ resourceType : services . route53HostedZone ,
227196 relation : 'child' ,
228- field : 'kms ' ,
197+ field : 'route53HostedZone ' ,
229198 } )
230199 }
231200 }
0 commit comments