Skip to content

Commit cf03793

Browse files
committed
Merge branch 'alpha' into feature/CG-1072
2 parents 745f168 + a4d4ed0 commit cf03793

File tree

7 files changed

+229
-103
lines changed

7 files changed

+229
-103
lines changed

README.md

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

src/services/iamRole/schema.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ type awsIamRole implements awsBaseService @key(fields: "id") {
2828
appSync: [awsAppSync] @hasInverse(field: iamRoles)
2929
lambda: [awsLambda] @hasInverse(field: iamRole)
3030
kinesisFirehose: [awsKinesisFirehose] @hasInverse(field: iamRole)
31+
rdsClusterMonitoringRole: [awsRdsCluster]
32+
@hasInverse(field: monitoringIamRole)
33+
rdsClusterIamRoles: [awsRdsCluster] @hasInverse(field: iamRoles)
3134
}

src/services/kms/schema.graphql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,10 @@ 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)
5056
}

src/services/rdsCluster/connections.ts

Lines changed: 110 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { DBInstance, DBCluster } from 'aws-sdk/clients/rds'
55

66
import services from '../../enums/services'
77
import { RawAwsRdsClusterSnapshot } from '../rdsClusterSnapshot/data'
8+
import { RawAwsIamRole } from '../iamRole/data'
9+
import { AwsKms } from '../kms/data'
10+
import { globalRegionName } from '../../enums/regions'
811

912
export 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
}

src/services/rdsCluster/format.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import { RawAwsRdsCluster } from './data'
2-
import {
3-
AwsRdsCluster,
4-
} from '../../types/generated'
2+
import { AwsRdsCluster } from '../../types/generated'
53
import { formatTagsFromMap } from '../../utils/format'
64

75
export default ({
86
service,
97
account,
10-
region
11-
}:
12-
{
8+
region,
9+
}: {
1310
service: RawAwsRdsCluster
1411
account: string
1512
region: string

src/services/rdsCluster/schema.graphql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ type awsRdsCluster implements awsBaseService @key(fields: "arn") {
3333
snapshots: [awsRdsClusterSnapshot] @hasInverse(field: cluster)
3434
securityGroups: [awsSecurityGroup] @hasInverse(field: rdsCluster)
3535
appSync: [awsAppSync] @hasInverse(field: rdsCluster)
36+
monitoringIamRole: [awsIamRole] @hasInverse(field: rdsClusterMonitoringRole)
37+
iamRoles: [awsIamRole] @hasInverse(field: rdsClusterIamRoles)
38+
storageEncryptedKms: [awsKms] @hasInverse(field: rdsClusterStorageEncryption)
39+
activityStreamKms: [awsKms] @hasInverse(field: rdsClusterActivityStream)
40+
performanceInsightsKms: [awsKms]
41+
@hasInverse(field: rdsClusterPerformanceInsights)
3642
}
37-
38-
# TODO: create connection to iam roles using AssociatedRoles property AND DomainMemberships AND MonitoringRole
39-
# TODO: create connection to kms using all kms related fields

src/types/generated.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3070,6 +3070,8 @@ export type AwsIamRole = AwsBaseService & {
30703070
maxSessionDuration?: Maybe<Scalars['Int']>;
30713071
name?: Maybe<Scalars['String']>;
30723072
path?: Maybe<Scalars['String']>;
3073+
rdsClusterIamRoles?: Maybe<Array<Maybe<AwsRdsCluster>>>;
3074+
rdsClusterMonitoringRole?: Maybe<Array<Maybe<AwsRdsCluster>>>;
30733075
sageMakerNotebookInstances?: Maybe<Array<Maybe<AwsSageMakerNotebookInstance>>>;
30743076
systemsManagerInstances?: Maybe<Array<Maybe<AwsSystemsManagerInstance>>>;
30753077
tags?: Maybe<Array<Maybe<AwsRawTag>>>;
@@ -3200,7 +3202,10 @@ export type AwsKms = AwsBaseService & {
32003202
lambda?: Maybe<Array<Maybe<AwsLambda>>>;
32013203
origin?: Maybe<Scalars['String']>;
32023204
policy?: Maybe<AwsIamJsonPolicy>;
3205+
rdsClusterActivityStream?: Maybe<Array<Maybe<AwsRdsCluster>>>;
3206+
rdsClusterPerformanceInsights?: Maybe<Array<Maybe<AwsRdsCluster>>>;
32033207
rdsClusterSnapshots?: Maybe<Array<Maybe<AwsRdsClusterSnapshot>>>;
3208+
rdsClusterStorageEncryption?: Maybe<Array<Maybe<AwsRdsCluster>>>;
32043209
redshiftCluster?: Maybe<Array<Maybe<AwsRedshiftCluster>>>;
32053210
sageMakerNotebookInstances?: Maybe<Array<Maybe<AwsSageMakerNotebookInstance>>>;
32063211
secretsManager?: Maybe<Array<Maybe<AwsSecretsManager>>>;
@@ -3485,6 +3490,7 @@ export type AwsRawTag = {
34853490
};
34863491

34873492
export type AwsRdsCluster = AwsBaseService & {
3493+
activityStreamKms?: Maybe<Array<Maybe<AwsKms>>>;
34883494
allocatedStorage?: Maybe<Scalars['Int']>;
34893495
appSync?: Maybe<Array<Maybe<AwsAppSync>>>;
34903496
backupRetentionPeriod?: Maybe<Scalars['Int']>;
@@ -3505,17 +3511,21 @@ export type AwsRdsCluster = AwsBaseService & {
35053511
hostedZoneId?: Maybe<Scalars['String']>;
35063512
httpEndpointEnabled?: Maybe<Scalars['Boolean']>;
35073513
iamDbAuthenticationEnabled?: Maybe<Scalars['Boolean']>;
3514+
iamRoles?: Maybe<Array<Maybe<AwsIamRole>>>;
35083515
instances?: Maybe<Array<Maybe<AwsRdsDbInstance>>>;
35093516
kmsKey?: Maybe<Scalars['String']>;
3517+
monitoringIamRole?: Maybe<Array<Maybe<AwsIamRole>>>;
35103518
multiAZ?: Maybe<Scalars['Boolean']>;
35113519
percentProgress?: Maybe<Scalars['String']>;
3520+
performanceInsightsKms?: Maybe<Array<Maybe<AwsKms>>>;
35123521
port?: Maybe<Scalars['Int']>;
35133522
readerEndpoint?: Maybe<Scalars['String']>;
35143523
replicationSourceIdentifier?: Maybe<Scalars['String']>;
35153524
resourceId?: Maybe<Scalars['String']>;
35163525
securityGroups?: Maybe<Array<Maybe<AwsSecurityGroup>>>;
35173526
snapshots?: Maybe<Array<Maybe<AwsRdsClusterSnapshot>>>;
35183527
status?: Maybe<Scalars['String']>;
3528+
storageEncryptedKms?: Maybe<Array<Maybe<AwsKms>>>;
35193529
subnets?: Maybe<Scalars['String']>;
35203530
tags?: Maybe<Array<Maybe<AwsRawTag>>>;
35213531
username?: Maybe<Scalars['String']>;

0 commit comments

Comments
 (0)