Skip to content

Commit 554dff7

Browse files
committed
feat: Handle TODOs for ecs cluster
1 parent d79a230 commit 554dff7

8 files changed

Lines changed: 114 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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, 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 |

src/services/cloudwatchLogs/schema.graphql

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

1718
type awsMetricFilter
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+
({ KeyId }: AwsKms) => KeyId === 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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ type awsEcsCluster @key(fields: "arn") {
1919
ecsService: [awsEcsService] @hasInverse(field: ecsCluster)
2020
ecsTask: [awsEcsTask] @hasInverse(field: ecsCluster)
2121
ecsTaskSet: [awsEcsTaskSet] @hasInverse(field: ecsCluster)
22+
s3: [awsS3] @hasInverse(field: ecsCluster)
23+
cloudwatchLog: [awsCloudwatchLog] @hasInverse(field: ecsCluster)
24+
kms: [awsKms] @hasInverse(field: ecsCluster)
2225
}
2326

24-
#TODO: add connections to cloudwatchLog, s3,
25-
26-
type AwsEcsExecuteCommandLogConfiguration
27+
type AwsEcsExecuteCommandLogConfiguration
2728
@generate(
2829
query: { get: false, query: true, aggregate: false }
2930
mutation: { add: false, delete: false }

src/services/kms/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ type awsKms @key(fields: "id"){
3030
dmsReplicationInstances: [awsDmsReplicationInstance] @hasInverse(field: kms)
3131
sageMakerNotebookInstances: [awsSageMakerNotebookInstance] @hasInverse(field: kms)
3232
rdsClusterSnapshots: [awsRdsClusterSnapshot] @hasInverse(field: kms)
33+
ecsCluster: [awsEcsCluster] @hasInverse(field: kms)
3334
}

src/services/s3/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type awsS3 @key(fields: "arn") {
2727
cloudfrontDistribution: [awsCloudfront] @hasInverse(field: s3) #change to plural
2828
cloudtrail: [awsCloudtrail] @hasInverse(field: s3) #change to plural
2929
managedAirflows: [awsManagedAirflow] @hasInverse(field: s3)
30+
ecsCluster: [awsEcsCluster] @hasInverse(field: s3)
3031
}
3132

3233
# 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
@@ -960,6 +960,7 @@ export type AwsCloudwatchLog = {
960960
cloudtrail?: Maybe<Array<Maybe<AwsCloudtrail>>>;
961961
cloudwatch?: Maybe<Array<Maybe<AwsCloudwatch>>>;
962962
creationTime?: Maybe<Scalars['String']>;
963+
ecsCluster?: Maybe<Array<Maybe<AwsEcsCluster>>>;
963964
id: Scalars['String'];
964965
kms?: Maybe<Array<Maybe<AwsKms>>>;
965966
kmsKeyId?: Maybe<Scalars['String']>;
@@ -1650,16 +1651,19 @@ export type AwsEcsCluster = {
16501651
attachments?: Maybe<Array<Maybe<AwsEcsAttachment>>>;
16511652
attachmentsStatus?: Maybe<Scalars['String']>;
16521653
capacityProviders?: Maybe<Array<Maybe<Scalars['String']>>>;
1654+
cloudwatchLog?: Maybe<Array<Maybe<AwsCloudwatchLog>>>;
16531655
clusterName?: Maybe<Scalars['String']>;
16541656
configuration?: Maybe<AwsEcsClusterConfiguration>;
16551657
defaultCapacityProviderStrategy?: Maybe<Array<Maybe<AwsEcsCapacityProviderStrategyItem>>>;
16561658
ecsService?: Maybe<Array<Maybe<AwsEcsService>>>;
16571659
ecsTask?: Maybe<Array<Maybe<AwsEcsTask>>>;
16581660
ecsTaskSet?: Maybe<Array<Maybe<AwsEcsTaskSet>>>;
16591661
id: Scalars['String'];
1662+
kms?: Maybe<Array<Maybe<AwsKms>>>;
16601663
pendingTasksCount?: Maybe<Scalars['Int']>;
16611664
registeredContainerInstancesCount?: Maybe<Scalars['Int']>;
16621665
runningTasksCount?: Maybe<Scalars['Int']>;
1666+
s3?: Maybe<Array<Maybe<AwsS3>>>;
16631667
settings?: Maybe<Array<Maybe<AwsEcsClusterSettings>>>;
16641668
statistics?: Maybe<Array<Maybe<AwsEcsStatistics>>>;
16651669
status?: Maybe<Scalars['String']>;
@@ -3343,6 +3347,7 @@ export type AwsKms = {
33433347
deletionDate?: Maybe<Scalars['String']>;
33443348
description?: Maybe<Scalars['String']>;
33453349
dmsReplicationInstances?: Maybe<Array<Maybe<AwsDmsReplicationInstance>>>;
3350+
ecsCluster?: Maybe<Array<Maybe<AwsEcsCluster>>>;
33463351
efs?: Maybe<Array<Maybe<AwsEfs>>>;
33473352
eksCluster?: Maybe<Array<Maybe<AwsEksCluster>>>;
33483353
elastiCacheReplicationGroup?: Maybe<Array<Maybe<AwsElastiCacheReplicationGroup>>>;
@@ -3885,6 +3890,7 @@ export type AwsS3 = {
38853890
cloudtrail?: Maybe<Array<Maybe<AwsCloudtrail>>>;
38863891
corsConfiguration?: Maybe<Scalars['String']>;
38873892
crossRegionReplication?: Maybe<Scalars['String']>;
3893+
ecsCluster?: Maybe<Array<Maybe<AwsEcsCluster>>>;
38883894
encrypted?: Maybe<Scalars['String']>;
38893895
id: Scalars['String'];
38903896
ignorePublicAcls?: Maybe<Scalars['String']>;

0 commit comments

Comments
 (0)