Skip to content

Commit 718ee7e

Browse files
committed
Merge branch 'feature/CG-825' into 'master'
feat(services): add new service elasticSearchDomain Closes CG-825 See merge request auto-cloud/cloudgraph/provider/cloudgraph-provider-aws!215
2 parents 179edba + 324905f commit 718ee7e

21 files changed

Lines changed: 775 additions & 46 deletions

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ CloudGraph AWS Provider will ask you what regions you would like to crawl and wi
105105
| elastiCacheReplicationGroup | kms |
106106
| elasticBeanstalkApp | elasticBeanstalkEnv |
107107
| elasticBeanstalkEnv | elasticBeanstalkApp |
108+
| elasticSearchDomain | kms, securityGroup, subnet, vpc |
108109
| elb | cloudfront, ecsService, securityGroup, subnet, vpc |
109110
| emrCluster | kms, subnet |
110111
| emrInstance | ebs, ec2 |
@@ -125,7 +126,7 @@ CloudGraph AWS Provider will ask you what regions you would like to crawl and wi
125126
| iot | |
126127
| kinesisFirehose | kinesisStream, s3 |
127128
| kinesisStream | kinesisFirehose |
128-
| kms | cloudtrail, cloudwatchLog, codebuild, efs, eksCluster, elastiCacheReplicationGroup, emrCluster, lambda, sns, redshiftCluster |
129+
| kms | cloudtrail, cloudwatchLog, codebuild, efs, eksCluster, elastiCacheReplicationGroup, elasticSearchDomain, emrCluster, lambda, sns, redshiftCluster |
129130
| lambda | appSync, cognitoUserPool, kms, securityGroup, subnet, vpc |
130131
| managedAirflow | iamRole, securityGroups, subnet, s3 |
131132
| nacl | vpc |
@@ -142,14 +143,14 @@ CloudGraph AWS Provider will ask you what regions you would like to crawl and wi
142143
| sageMakerExperiment | |
143144
| s3 | cloudfront, cloudtrail, kinesisFirehose, managedAirflow |
144145
| secretsManager | |
145-
| securityGroup | alb, asg, clientVpnEndpoint, codebuild, ecsService, lambda, ec2, elb, rdsCluster, rdsDbInstance, eksCluster, elastiCacheCluster, managedAirflow |
146+
| securityGroup | alb, asg, clientVpnEndpoint, codebuild, ecsService, lambda, ec2, elasticSearchDomain, elb, rdsCluster, rdsDbInstance, eksCluster, elastiCacheCluster, managedAirflow |
146147
| ses | |
147148
| sns | kms, cloudtrail, cloudwatch |
148149
| sqs | |
149-
| subnet | alb, asg, codebuild, ec2, ecsService, efsMountTarget, elastiCacheCluster, elb, lambda, managedAirflow, natGateway, networkInterface, routeTable, vpc, eksCluster, emrCluster, flowLog |
150+
| subnet | alb, asg, codebuild, ec2, ecsService, efsMountTarget, elastiCacheCluster, elasticSearchDomain, elb, lambda, managedAirflow, natGateway, networkInterface, routeTable, vpc, eksCluster, emrCluster, flowLog |
150151
| transitGateway | routeTable, transitGatewayAttachment, vpnConnection |
151152
| transitGatewayAttachment | routeTable, transitGateway, vpc, vpnConnection |
152-
| vpc | alb, codebuild, ec2, eip, elb, ecsService, efsMountTarget, eksCluster igw, elastiCacheCluster, lambda, nacl, natGateway, networkInterface, rdsDbInstance, redshiftCluster, route53HostedZone, routeTable, subnet, flowLog, vpnGateway, transitGatewayAttachment |
153+
| vpc | alb, codebuild, ec2, eip, elb, ecsService, efsMountTarget, eksCluster igw, elastiCacheCluster, elasticSearchDomain, lambda, nacl, natGateway, networkInterface, rdsDbInstance, redshiftCluster, route53HostedZone, routeTable, subnet, flowLog, vpnGateway, transitGatewayAttachment |
153154
| vpnConnection | customerGateway, transitGateway, transitGatewayAttachment, vpnGateway |
154155
| vpnGateway | vpc, vpnConnection |
155156
| wafV2WebAcl | |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"@fast-csv/parse": "^4.3.6",
3737
"@graphql-tools/load-files": "6.3.2",
3838
"@graphql-tools/merge": "8.0.1",
39-
"aws-sdk": "2.982.0",
39+
"aws-sdk": "^2.1084.0",
4040
"chalk": "4.1.2",
4141
"cuid": "2.1.8",
4242
"dotenv": "10.0.0",

src/enums/schemasMap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default {
4343
[services.elastiCacheReplicationGroup]: 'awsElastiCacheReplicationGroup',
4444
[services.elasticBeanstalkApp]: 'awsElasticBeanstalkApp',
4545
[services.elasticBeanstalkEnv]: 'awsElasticBeanstalkEnv',
46+
[services.elasticSearchDomain]: 'awsElasticSearchDomain',
4647
[services.elb]: 'awsElb',
4748
[services.flowLog]: 'awsFlowLog',
4849
[services.glueJob]: 'awsGlueJob',

src/enums/serviceMap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import SageMakerExperiment from '../services/sageMakerExperiment'
8787
import ManagedAirflow from '../services/managedAirflow'
8888
import WafV2WebAcl from '../services/wafV2WebAcl'
8989
import GuardDutyDetector from '../services/guardDutyDetector'
90+
import ElasticSearchDomain from '../services/elasticSearchDomain'
9091

9192
/**
9293
* serviceMap is an object that contains all currently supported services for AWS
@@ -124,6 +125,7 @@ export default {
124125
[services.elasticBeanstalkEnv]: ElasticBeanstalkEnv,
125126
[services.elastiCacheCluster]: ElastiCacheCluster,
126127
[services.elastiCacheReplicationGroup]: ElastiCacheReplicationGroup,
128+
[services.elasticSearchDomain]: ElasticSearchDomain,
127129
[services.elb]: ELB,
128130
[services.flowLog]: FlowLog,
129131
[services.glueJob]: GlueJob,

src/enums/services.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default {
3838
elasticBeanstalkEnv: 'elasticBeanstalkEnv',
3939
elastiCacheCluster: 'elastiCacheCluster',
4040
elastiCacheReplicationGroup: 'elastiCacheReplicationGroup',
41+
elasticSearchDomain: 'elasticSearchDomain',
4142
elb: 'elb',
4243
flowLog: 'flowLog',
4344
glueJob: 'glueJob',
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { ServiceConnection } from '@cloudgraph/sdk'
2+
3+
import services from '../../enums/services'
4+
import { RawAwsElasticSearchDomain } from './data'
5+
import { AwsSecurityGroup } from '../securityGroup/data'
6+
import { AwsKms } from '../kms/data'
7+
8+
export default ({
9+
service: domain,
10+
data,
11+
region,
12+
}: {
13+
service: RawAwsElasticSearchDomain
14+
data: Array<{ name: string; data: { [property: string]: any[] } }>
15+
region: string
16+
}): {
17+
[property: string]: ServiceConnection[]
18+
} => {
19+
const {
20+
DomainId,
21+
VPCOptions: { SecurityGroupIds = [] } = {},
22+
EncryptionAtRestOptions: { KmsKeyId } = {},
23+
} = domain
24+
const connections: ServiceConnection[] = []
25+
26+
/**
27+
* Find any securityGroup related data
28+
*/
29+
const sgs = data.find(({ name }) => name === services.sg)
30+
if (sgs?.data?.[region]) {
31+
const dataAtRegion: AwsSecurityGroup[] = sgs.data[region].filter(
32+
({ GroupId }: AwsSecurityGroup) => SecurityGroupIds.includes(GroupId)
33+
)
34+
for (const sg of dataAtRegion) {
35+
connections.push({
36+
id: sg.GroupId,
37+
resourceType: services.sg,
38+
relation: 'child',
39+
field: 'securityGroups',
40+
})
41+
}
42+
}
43+
44+
/**
45+
* Find any kms related data
46+
*/
47+
const keys = data.find(({ name }) => name === services.kms)
48+
if (keys?.data?.[region]) {
49+
const dataAtRegion: AwsKms[] = keys.data[region].filter(
50+
({ Arn }: AwsKms) => Arn === KmsKeyId
51+
)
52+
for (const key of dataAtRegion) {
53+
connections.push({
54+
id: key.KeyId,
55+
resourceType: services.kms,
56+
relation: 'child',
57+
field: 'kms',
58+
})
59+
}
60+
}
61+
62+
const natResult = {
63+
[DomainId]: connections,
64+
}
65+
return natResult
66+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { Config } from 'aws-sdk/lib/config'
2+
import ES from 'aws-sdk/clients/es'
3+
import isEmpty from 'lodash/isEmpty'
4+
import groupBy from 'lodash/groupBy'
5+
import { convertToPromise, fetchAllPaginatedData } from '../../utils/fetchUtils'
6+
import { initTestEndpoint } from '../../utils'
7+
import { convertAwsTagsToTagMap } from '../../utils/format'
8+
import AwsErrorLog from '../../utils/errorLog'
9+
import { TagMap } from '../../types'
10+
11+
const serviceName = 'elasticSearchDomain'
12+
const errorLog = new AwsErrorLog(serviceName)
13+
const endpoint = initTestEndpoint(serviceName)
14+
15+
export interface RawAwsElasticSearchDomain extends ES.ElasticsearchDomainStatus {
16+
region: string
17+
Tags: TagMap
18+
}
19+
20+
/**
21+
* ElasticSearchDomain
22+
*/
23+
24+
export default async ({
25+
regions,
26+
config,
27+
}: {
28+
regions: string
29+
config: Config
30+
}): Promise<{ [region: string]: RawAwsElasticSearchDomain[] }> => {
31+
const result: RawAwsElasticSearchDomain[] = []
32+
33+
const activeRegions = regions.split(',')
34+
35+
for (const region of activeRegions) {
36+
const client = new ES({ ...config, region, endpoint })
37+
let elasticSearchDomainData: ES.DomainInfo[]
38+
try {
39+
elasticSearchDomainData = await fetchAllPaginatedData({
40+
getResourcesFn: convertToPromise({
41+
sdkContext: client,
42+
fnName: 'listDomainNames',
43+
}),
44+
accessor: '',
45+
})
46+
} catch (err) {
47+
errorLog.generateAwsErrorLog({ functionName: 'listDomainNames', err })
48+
}
49+
if (!isEmpty(elasticSearchDomainData)) {
50+
const domainNames = elasticSearchDomainData.map(({ DomainName }) => DomainName)
51+
let elasticSearchDomainDetails: ES.ElasticsearchDomainStatusList
52+
try {
53+
elasticSearchDomainDetails = await fetchAllPaginatedData({
54+
getResourcesFn: convertToPromise({
55+
sdkContext: client,
56+
fnName: 'describeElasticsearchDomains',
57+
}),
58+
initialParams: {
59+
DomainNames: domainNames
60+
},
61+
accessor: '',
62+
})
63+
} catch (err) {
64+
errorLog.generateAwsErrorLog({ functionName: 'listDomainNames', err })
65+
}
66+
for (const domain of elasticSearchDomainDetails) {
67+
const tags = await client.listTags({ ARN: domain.ARN }).promise()
68+
result.push({ ...domain, Tags: convertAwsTagsToTagMap(tags?.TagList ?? []), region })
69+
}
70+
}
71+
}
72+
errorLog.reset()
73+
return groupBy(result, 'region')
74+
}

0 commit comments

Comments
 (0)