Skip to content

Commit 585a58e

Browse files
authored
Merge pull request #18 from cloudgraphdev/feature/CG-1062
Feature/cg 1062
2 parents e02ebdf + 592400d commit 585a58e

File tree

9 files changed

+117
-7
lines changed

9 files changed

+117
-7
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ CloudGraph AWS Provider will ask you what regions you would like to crawl and wi
8181
| cloudfront | elb, s3 |
8282
| cloudtrail | cloudwatch, cloudwatchLog, kms, s3, sns |
8383
| cloudwatch | cloudtrail, cloudwatchLog, sns |
84-
| cloudwatchLog | cloudtrail, cloudwatch, kms |
84+
| cloudwatchLog | cloudtrail, cloudwatch, ecsCluster, kms |
8585
| codebuild | iamRole, kms, vpc, securityGroup, subnet |
8686
| cognitoIdentityPool | |
8787
| cognitoUserPool | appSync, lambda |
@@ -92,7 +92,7 @@ CloudGraph AWS Provider will ask you what regions you would like to crawl and wi
9292
| ebs | asg, ec2, emrInstance |
9393
| ec2 | alb, asg, ebs, eip, emrInstance, eksCluster, elasticBeanstalkEnv, iamInstanceProfile, iamRole, networkInterface, securityGroup, subnet, systemsManagerInstance, vpc, ecsContainer |
9494
| ecr | |
95-
| ecsCluster | ecsService, ecsTask, ecsTaskSet |
95+
| ecsCluster | cloudwatchLog, ecsService, ecsTask, ecsTaskSet, kms, s3 |
9696
| ecsContainer | ecsTask, ec2 |
9797
| ecsService | ecsCluster, ecsTaskDefinition, ecsTaskSet, elb, iamRole, securityGroup, subnet, vpc |
9898
| ecsTask | ecsContainer, ecsCluster, ecsTaskDefinition |
@@ -128,7 +128,7 @@ CloudGraph AWS Provider will ask you what regions you would like to crawl and wi
128128
| iot | |
129129
| kinesisFirehose | kinesisStream, s3 |
130130
| kinesisStream | kinesisFirehose |
131-
| kms | cloudtrail, cloudwatchLog, codebuild, dynamodb, efs, eksCluster, elastiCacheReplicationGroup, elasticSearchDomain, emrCluster, lambda, rdsClusterSnapshot, sns, sageMakerNotebookInstance, dmsReplicationInstance, redshiftCluster |
131+
| kms | cloudtrail, cloudwatchLog, codebuild, ecsCluster, efs, eksCluster, elastiCacheReplicationGroup, elasticSearchDomain, emrCluster, lambda, rdsClusterSnapshot, sns, sageMakerNotebookInstance, dmsReplicationInstance, redshiftCluster |
132132
| lambda | appSync, cognitoUserPool, kms, securityGroup, subnet, vpc |
133133
| managedAirflow | iamRole, securityGroups, subnet, s3 |
134134
| nacl | vpc |
@@ -145,7 +145,7 @@ CloudGraph AWS Provider will ask you what regions you would like to crawl and wi
145145
| sageMakerExperiment | |
146146
| sageMakerNotebookInstance | iamRole, kms, networkInterface, subnet, securityGroup |
147147
| sageMakerProject | |
148-
| s3 | cloudfront, cloudtrail, kinesisFirehose, managedAirflow |
148+
| s3 | cloudfront, cloudtrail, ecsCluster, kinesisFirehose, managedAirflow |
149149
| secretsManager | |
150150
| securityGroup | alb, asg, clientVpnEndpoint, codebuild, dmsReplicationInstance, ecsService, lambda, ec2, elasticSearchDomain, elb, rdsCluster, rdsDbInstance, eksCluster, elastiCacheCluster, managedAirflow, sageMakerNotebookInstance |
151151
| ses | |

src/services/cloudwatchLogs/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type awsCloudwatchLog @key(fields: "arn") {
1313
kms: [awsKms] @hasInverse(field: cloudwatchLog)
1414
cloudwatch: [awsCloudwatch] @hasInverse(field: cloudwatchLog)
1515
cloudtrail: [awsCloudtrail] @hasInverse(field: cloudwatchLog)
16+
ecsCluster: [awsEcsCluster] @hasInverse(field: cloudwatchLog)
1617
}
1718

1819
type awsMetricFilter

src/services/cognitoUserPool/connections.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export default ({
103103

104104
if (kmsKeyID && kms?.data?.[region]) {
105105
const kmsInRegion: AwsKms = kms.data[region].find(
106-
({ KeyId }: AwsKms) => kmsKeyID === KeyId
106+
({ KeyArn }: AwsKms) => kmsKeyID === KeyArn
107107
)
108108

109109
if (kmsInRegion) {
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { ServiceConnection } from '@cloudgraph/sdk'
2+
3+
import { isEmpty } from 'lodash'
4+
import services from '../../enums/services'
5+
import { RawAwsEcsCluster } from '../ecsCluster/data'
6+
import { RawAwsS3 } from '../s3/data'
7+
import { RawAwsLogGroup } from '../cloudwatchLogs/data'
8+
import { AwsKms } from '../kms/data'
9+
import { gets3BucketId } from '../../utils/ids'
10+
11+
export default ({
12+
service: ecsCluster,
13+
data,
14+
region,
15+
}: {
16+
service: RawAwsEcsCluster
17+
data: Array<{ name: string; data: { [property: string]: any[] } }>
18+
region: string
19+
}): {
20+
[property: string]: ServiceConnection[]
21+
} => {
22+
const {
23+
clusterArn: arn,
24+
configuration: {
25+
executeCommandConfiguration: { logConfiguration, kmsKeyId } = {},
26+
} = {},
27+
} = ecsCluster
28+
const connections: ServiceConnection[] = []
29+
30+
/**
31+
* Find S3
32+
* related to this ecs cluster
33+
*/
34+
const buckets = data.find(({ name }) => name === services.s3)
35+
if (buckets?.data?.[region]) {
36+
const dataAtRegion: RawAwsS3[] = buckets.data[region].filter(
37+
({ Name: name }: RawAwsS3) => name === logConfiguration?.s3BucketName
38+
)
39+
for (const bucket of dataAtRegion) {
40+
connections.push({
41+
id: gets3BucketId(bucket.Name),
42+
resourceType: services.s3,
43+
relation: 'child',
44+
field: 's3',
45+
})
46+
}
47+
}
48+
49+
/**
50+
* Find Cloudwatch Log Group
51+
* related to this ecs cluster
52+
*/
53+
const logGroups = data.find(({ name }) => name === services.cloudwatchLog)
54+
let logGroupsInRegion: RawAwsLogGroup[] = []
55+
if (logGroups?.data?.[region]) {
56+
logGroupsInRegion = logGroups.data[region].filter(
57+
({ logGroupName }: RawAwsLogGroup) =>
58+
logGroupName === logConfiguration?.cloudWatchLogGroupName
59+
)
60+
}
61+
62+
if (!isEmpty(logGroupsInRegion)) {
63+
for (const logGroup of logGroupsInRegion) {
64+
connections.push({
65+
id: logGroup.logGroupName,
66+
resourceType: services.cloudwatchLog,
67+
relation: 'child',
68+
field: 'cloudwatchLog',
69+
})
70+
}
71+
}
72+
73+
/**
74+
* Find MKS
75+
* related to this ecs cluster
76+
*/
77+
const kms = data.find(({ name }) => name === services.kms)
78+
if (kms?.data?.[region]) {
79+
const kmsInRegion: AwsKms = kms.data[region].find(
80+
({ KeyArn }: AwsKms) => KeyArn === kmsKeyId
81+
)
82+
83+
if (kmsInRegion) {
84+
connections.push({
85+
id: kmsInRegion.KeyId,
86+
resourceType: services.kms,
87+
relation: 'child',
88+
field: 'kms',
89+
})
90+
}
91+
}
92+
93+
const natResult = {
94+
[arn]: connections,
95+
}
96+
return natResult
97+
}

src/services/ecsCluster/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ import {Service} from '@cloudgraph/sdk'
22
import BaseService from '../base'
33
import format from './format'
44
import getData from './data'
5+
import getConnections from './connections'
56
import mutation from './mutation'
67

78
export default class EcsCluster extends BaseService implements Service {
89
format = format.bind(this)
910

1011
getData = getData.bind(this)
1112

13+
getConnections = getConnections.bind(this)
14+
1215
mutation = mutation
1316
}

src/services/ecsCluster/schema.graphql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ type awsEcsCluster implements awsBaseService @key(fields: "arn") {
1616
ecsService: [awsEcsService] @hasInverse(field: ecsCluster)
1717
ecsTask: [awsEcsTask] @hasInverse(field: ecsCluster)
1818
ecsTaskSet: [awsEcsTaskSet] @hasInverse(field: ecsCluster)
19+
s3: [awsS3] @hasInverse(field: ecsCluster)
20+
cloudwatchLog: [awsCloudwatchLog] @hasInverse(field: ecsCluster)
21+
kms: [awsKms] @hasInverse(field: ecsCluster)
1922
}
2023

21-
#TODO: add connections to cloudwatchLog, s3,
22-
2324
type AwsEcsExecuteCommandLogConfiguration
2425
@generate(
2526
query: { get: false, query: true, aggregate: false }

src/services/kms/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type awsKms implements awsBaseService @key(fields: "id") {
2828
sageMakerNotebookInstances: [awsSageMakerNotebookInstance]
2929
@hasInverse(field: kms)
3030
rdsClusterSnapshots: [awsRdsClusterSnapshot] @hasInverse(field: kms)
31+
ecsCluster: [awsEcsCluster] @hasInverse(field: kms)
3132
dynamodb: [awsDynamoDbTable] @hasInverse(field: kms)
3233
cognitoUserPools: [awsCognitoUserPool] @hasInverse(field: kms)
3334
}

src/services/s3/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type awsS3 implements awsBaseService @key(fields: "arn") {
2323
cloudfrontDistribution: [awsCloudfront] @hasInverse(field: s3) #change to plural
2424
cloudtrail: [awsCloudtrail] @hasInverse(field: s3) #change to plural
2525
managedAirflows: [awsManagedAirflow] @hasInverse(field: s3)
26+
ecsCluster: [awsEcsCluster] @hasInverse(field: s3)
2627
}
2728

2829
# TODO: use getBucketReplication and getBucketNotificationConfiguration to make connections to lambda, sns, iamRole, SQS

src/types/generated.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,7 @@ export type AwsCloudwatchLog = {
914914
cloudtrail?: Maybe<Array<Maybe<AwsCloudtrail>>>;
915915
cloudwatch?: Maybe<Array<Maybe<AwsCloudwatch>>>;
916916
creationTime?: Maybe<Scalars['String']>;
917+
ecsCluster?: Maybe<Array<Maybe<AwsEcsCluster>>>;
917918
id: Scalars['String'];
918919
kms?: Maybe<Array<Maybe<AwsKms>>>;
919920
kmsKeyId?: Maybe<Scalars['String']>;
@@ -1595,15 +1596,18 @@ export type AwsEcsCluster = AwsBaseService & {
15951596
attachments?: Maybe<Array<Maybe<AwsEcsAttachment>>>;
15961597
attachmentsStatus?: Maybe<Scalars['String']>;
15971598
capacityProviders?: Maybe<Array<Maybe<Scalars['String']>>>;
1599+
cloudwatchLog?: Maybe<Array<Maybe<AwsCloudwatchLog>>>;
15981600
clusterName?: Maybe<Scalars['String']>;
15991601
configuration?: Maybe<AwsEcsClusterConfiguration>;
16001602
defaultCapacityProviderStrategy?: Maybe<Array<Maybe<AwsEcsCapacityProviderStrategyItem>>>;
16011603
ecsService?: Maybe<Array<Maybe<AwsEcsService>>>;
16021604
ecsTask?: Maybe<Array<Maybe<AwsEcsTask>>>;
16031605
ecsTaskSet?: Maybe<Array<Maybe<AwsEcsTaskSet>>>;
1606+
kms?: Maybe<Array<Maybe<AwsKms>>>;
16041607
pendingTasksCount?: Maybe<Scalars['Int']>;
16051608
registeredContainerInstancesCount?: Maybe<Scalars['Int']>;
16061609
runningTasksCount?: Maybe<Scalars['Int']>;
1610+
s3?: Maybe<Array<Maybe<AwsS3>>>;
16071611
settings?: Maybe<Array<Maybe<AwsEcsClusterSettings>>>;
16081612
statistics?: Maybe<Array<Maybe<AwsEcsStatistics>>>;
16091613
status?: Maybe<Scalars['String']>;
@@ -3179,6 +3183,7 @@ export type AwsKms = AwsBaseService & {
31793183
description?: Maybe<Scalars['String']>;
31803184
dmsReplicationInstances?: Maybe<Array<Maybe<AwsDmsReplicationInstance>>>;
31813185
dynamodb?: Maybe<Array<Maybe<AwsDynamoDbTable>>>;
3186+
ecsCluster?: Maybe<Array<Maybe<AwsEcsCluster>>>;
31823187
efs?: Maybe<Array<Maybe<AwsEfs>>>;
31833188
eksCluster?: Maybe<Array<Maybe<AwsEksCluster>>>;
31843189
elastiCacheReplicationGroup?: Maybe<Array<Maybe<AwsElastiCacheReplicationGroup>>>;
@@ -3676,6 +3681,7 @@ export type AwsS3 = AwsBaseService & {
36763681
cloudtrail?: Maybe<Array<Maybe<AwsCloudtrail>>>;
36773682
corsConfiguration?: Maybe<Scalars['String']>;
36783683
crossRegionReplication?: Maybe<Scalars['String']>;
3684+
ecsCluster?: Maybe<Array<Maybe<AwsEcsCluster>>>;
36793685
encrypted?: Maybe<Scalars['String']>;
36803686
ignorePublicAcls?: Maybe<Scalars['String']>;
36813687
kinesisFirehose?: Maybe<Array<Maybe<AwsKinesisFirehose>>>;

0 commit comments

Comments
 (0)