Skip to content

Commit 6480e7f

Browse files
Christopher BrandtMarco Franceschi
authored andcommitted
feat(rdsCluster): add route53HostedZone connection
1 parent f501a4e commit 6480e7f

7 files changed

Lines changed: 56 additions & 95 deletions

File tree

README.md

Lines changed: 17 additions & 17 deletions
Large diffs are not rendered by default.

src/services/iamRole/schema.graphql

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ type awsIamRole implements awsBaseService @key(fields: "id") {
2929
appSync: [awsAppSync] @hasInverse(field: iamRoles)
3030
lambda: [awsLambda] @hasInverse(field: iamRole)
3131
kinesisFirehose: [awsKinesisFirehose] @hasInverse(field: iamRole)
32-
rdsClusterMonitoringRole: [awsRdsCluster]
33-
@hasInverse(field: monitoringIamRole)
34-
rdsClusterIamRoles: [awsRdsCluster] @hasInverse(field: iamRoles)
35-
cloudFormationStackSet: [awsCloudFormationStackSet] @hasInverse(field: iamRoles)
32+
rdsCluster: [awsRdsCluster] @hasInverse(field: iamRoles)
33+
cloudFormationStackSet: [awsCloudFormationStackSet]
34+
@hasInverse(field: iamRoles)
3635
asg: [awsAsg] @hasInverse(field: iamRole)
3736
}

src/services/kms/schema.graphql

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ type awsKms implements awsBaseService @key(fields: "id") {
4747
ecsCluster: [awsEcsCluster] @hasInverse(field: kms)
4848
dynamodb: [awsDynamoDbTable] @hasInverse(field: kms)
4949
cognitoUserPools: [awsCognitoUserPool] @hasInverse(field: kms)
50-
rdsClusterStorageEncryption: [awsRdsCluster]
51-
@hasInverse(field: storageEncryptedKms)
52-
rdsClusterActivityStream: [awsRdsCluster]
53-
@hasInverse(field: activityStreamKms)
54-
rdsClusterPerformanceInsights: [awsRdsCluster]
55-
@hasInverse(field: performanceInsightsKms)
5650
rdsCluster: [awsRdsCluster] @hasInverse(field: kms)
5751
rdsDbInstance: [awsRdsDbInstance] @hasInverse(field: kms)
5852
}

src/services/rdsCluster/connections.ts

Lines changed: 31 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { ServiceConnection } from '@cloudgraph/sdk'
22
import { isEmpty } from 'lodash'
33
import { SecurityGroup } from 'aws-sdk/clients/ec2'
4-
import { DBInstance, DBCluster } from 'aws-sdk/clients/rds'
4+
import { DBInstance } from 'aws-sdk/clients/rds'
55

66
import services from '../../enums/services'
77
import { RawAwsRdsCluster } from './data'
8+
import { RawAwsRoute53HostedZone } from '../route53HostedZone/data'
89
import { RawAwsRdsClusterSnapshot } from '../rdsClusterSnapshot/data'
910
import { RawAwsIamRole } from '../iamRole/data'
1011
import { 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
}

src/services/rdsCluster/schema.graphql

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ type awsRdsCluster implements awsBaseService @key(fields: "arn") {
3636
subnets: [awsSubnet] @hasInverse(field: rdsCluster)
3737
appSync: [awsAppSync] @hasInverse(field: rdsCluster)
3838
kms: [awsKms] @hasInverse(field: rdsCluster)
39-
monitoringIamRole: [awsIamRole] @hasInverse(field: rdsClusterMonitoringRole)
40-
iamRoles: [awsIamRole] @hasInverse(field: rdsClusterIamRoles)
41-
storageEncryptedKms: [awsKms] @hasInverse(field: rdsClusterStorageEncryption)
42-
activityStreamKms: [awsKms] @hasInverse(field: rdsClusterActivityStream)
43-
performanceInsightsKms: [awsKms]
44-
@hasInverse(field: rdsClusterPerformanceInsights)
39+
route53HostedZone: [awsRoute53HostedZone] @hasInverse(field: rdsCluster)
40+
iamRoles: [awsIamRole] @hasInverse(field: rdsCluster)
4541
}

src/services/route53HostedZone/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ type awsRoute53HostedZone implements awsBaseService @key(fields: "arn") {
33
comment: String @search(by: [hash, regexp, fulltext])
44
delegationSetId: String @search(by: [hash])
55
nameServers: [String] @search(by: [hash, regexp])
6+
rdsCluster: [awsRdsCluster] @hasInverse(field: route53HostedZone)
67
route53Record: [awsRoute53Record] @hasInverse(field: route53HostedZone) #change to plural
78
vpc: [awsVpc] @hasInverse(field: route53HostedZone)
89
}

src/types/generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3540,6 +3540,7 @@ export type AwsRdsCluster = AwsBaseService & {
35403540
readerEndpoint?: Maybe<Scalars['String']>;
35413541
replicationSourceIdentifier?: Maybe<Scalars['String']>;
35423542
resourceId?: Maybe<Scalars['String']>;
3543+
route53HostedZone?: Maybe<Array<Maybe<AwsRoute53HostedZone>>>;
35433544
securityGroups?: Maybe<Array<Maybe<AwsSecurityGroup>>>;
35443545
snapshots?: Maybe<Array<Maybe<AwsRdsClusterSnapshot>>>;
35453546
status?: Maybe<Scalars['String']>;
@@ -3686,6 +3687,7 @@ export type AwsRoute53HostedZone = AwsBaseService & {
36863687
delegationSetId?: Maybe<Scalars['String']>;
36873688
name?: Maybe<Scalars['String']>;
36883689
nameServers?: Maybe<Array<Maybe<Scalars['String']>>>;
3690+
rdsCluster?: Maybe<Array<Maybe<AwsRdsCluster>>>;
36893691
route53Record?: Maybe<Array<Maybe<AwsRoute53Record>>>;
36903692
vpc?: Maybe<Array<Maybe<AwsVpc>>>;
36913693
};

0 commit comments

Comments
 (0)