Skip to content

Commit d6dc132

Browse files
committed
fix(aws): fixes for beta release review
1 parent e8aa724 commit d6dc132

File tree

8 files changed

+92
-85
lines changed

8 files changed

+92
-85
lines changed

src/services/docdbCluster/data.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
import CloudGraph from '@cloudgraph/sdk'
22
import DOCDB, {
33
DBCluster,
4-
TagListMessage,
5-
DescribeDBClustersMessage,
64
DBClusterMessage,
75
DBSubnetGroup,
86
DBSubnetGroupMessage,
7+
DescribeDBClustersMessage,
98
} from 'aws-sdk/clients/docdb'
9+
import { Config } from 'aws-sdk/lib/config'
1010
import { AWSError } from 'aws-sdk/lib/error'
1111
import groupBy from 'lodash/groupBy'
1212
import isEmpty from 'lodash/isEmpty'
13-
import { Config } from 'aws-sdk/lib/config'
1413
import awsLoggerText from '../../properties/logger'
15-
import { TagMap, AwsTag } from '../../types'
16-
import { convertAwsTagsToTagMap } from '../../utils/format'
17-
import AwsErrorLog from '../../utils/errorLog'
14+
import { TagMap } from '../../types'
1815
import { initTestEndpoint } from '../../utils'
16+
import AwsErrorLog from '../../utils/errorLog'
1917

2018
const lt = { ...awsLoggerText }
2119
const { logger } = CloudGraph
@@ -75,9 +73,14 @@ const describeDBSubnetGroups = async (
7573
})
7674
return resolve([])
7775
}
78-
if (!isEmpty(data)) {
79-
resolve(data.DBSubnetGroups)
76+
if (isEmpty(data)) {
77+
return resolve([])
78+
}
79+
const { DBSubnetGroups = [] } = data || {}
80+
if (isEmpty(DBSubnetGroups)) {
81+
return resolve([])
8082
}
83+
resolve(DBSubnetGroups)
8184
}
8285
)
8386
} catch (error) {

src/services/eksCluster/data.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ const listClustersForRegion = async ({
6666
} else {
6767
resolve(clusterList)
6868
}
69-
7069
}
7170
)
7271
} catch (error) {
@@ -164,9 +163,9 @@ const listNodegroups = async ({
164163

165164
if (nextToken) {
166165
listAllNodeGroups(nextToken)
166+
} else {
167+
resolve(nodeGroupsList)
167168
}
168-
169-
resolve(nodeGroupsList)
170169
}
171170
)
172171
} catch (error) {

src/services/elasticBeanstalkApplication/data.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import CloudGraph from '@cloudgraph/sdk'
77
import { Config } from 'aws-sdk'
88
import { ApplicationDescription } from 'aws-sdk/clients/elasticbeanstalk'
9+
import { groupBy } from 'lodash'
910
import isEmpty from 'lodash/isEmpty'
1011
import awsLoggerText from '../../properties/logger'
1112
import { AwsTag, TagMap } from '../../types'
@@ -19,6 +20,7 @@ const serviceName = 'ElasticBeanstalkApp'
1920
const errorLog = new AwsErrorLog(serviceName)
2021

2122
export interface RawAwsElasticBeanstalkApp extends ApplicationDescription {
23+
region: string
2224
Tags?: TagMap
2325
}
2426

@@ -64,12 +66,13 @@ export const getResourceTags = async (
6466
}
6567
resolveTags(convertAwsTagsToTagMap(tags as AwsTag[]))
6668
})
67-
.catch(err =>
69+
.catch(err => {
6870
errorLog.generateAwsErrorLog({
6971
functionName: 'elasticBeanstalk:listTagsForResource',
7072
err,
7173
})
72-
)
74+
resolveTags({})
75+
})
7376
})
7477

7578
const getApplications = async (
@@ -97,25 +100,25 @@ export default async ({
97100
new Promise(async resolve => {
98101
const { credentials } = config
99102
let numberOfApps = 0
100-
const output: { [property: string]: RawAwsElasticBeanstalkApp[] } = {}
103+
const appsData: RawAwsElasticBeanstalkApp[] = []
101104

102-
// First we get all applications for all regions
103-
await Promise.all(
104-
regions.split(',').map(region => {
105-
const eb = new ElasticBeanstalkClient({
106-
credentials,
107-
region,
108-
})
109-
output[region] = []
110-
return new Promise<void>(async resolveRegion => {
111-
const apps = (await getApplications(eb)) || []
112-
output[region] = apps
105+
const regionPromises = regions.split(',').map(region => {
106+
const eb = new ElasticBeanstalkClient({
107+
credentials,
108+
region,
109+
})
110+
return new Promise<void>(async resolveRegion => {
111+
const apps = (await getApplications(eb)) || []
112+
if (!isEmpty(apps)) {
113+
appsData.push(...apps.map(val => ({ ...val, region })))
113114
numberOfApps += apps.length
114-
resolveRegion()
115-
})
115+
}
116+
resolveRegion()
116117
})
117-
)
118+
})
119+
120+
await Promise.all(regionPromises)
118121
errorLog.reset()
119122
logger.debug(lt.fetchedElasticBeanstalkApps(numberOfApps))
120-
resolve(output)
123+
resolve(groupBy(appsData, 'region'))
121124
})

src/services/elasticBeanstalkEnvironment/data.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
EnvironmentDescription,
1515
EnvironmentResourceDescription,
1616
} from 'aws-sdk/clients/elasticbeanstalk'
17+
import { groupBy } from 'lodash'
1718
import isEmpty from 'lodash/isEmpty'
1819
import awsLoggerText from '../../properties/logger'
1920
import { TagMap } from '../../types'
@@ -31,6 +32,7 @@ export interface RawAwsElasticBeanstalkEnv extends EnvironmentDescription {
3132
resources?: EnvironmentResourceDescription
3233
settings?: ConfigurationSettingsDescription[]
3334
Tags?: TagMap
35+
region: string
3436
}
3537

3638
const listEnvironments = async (
@@ -175,27 +177,25 @@ export default async ({
175177
new Promise(async resolve => {
176178
const { credentials } = config
177179
let numberOfEnvs = 0
178-
const output: {
179-
[property: string]: RawAwsElasticBeanstalkEnv[]
180-
} = {}
181-
182-
// First we get all applications for all regions
183-
await Promise.all(
184-
regions.split(',').map(region => {
185-
const eb = new ElasticBeanstalkClient({
186-
credentials,
187-
region,
188-
})
189-
output[region] = []
190-
return new Promise<void>(async resolveRegion => {
191-
const envs = (await getEnvironments(eb)) || []
192-
output[region] = envs
180+
const envsData: RawAwsElasticBeanstalkEnv[] = []
181+
182+
const regionPromises = regions.split(',').map(region => {
183+
const eb = new ElasticBeanstalkClient({
184+
credentials,
185+
region,
186+
})
187+
return new Promise<void>(async resolveRegion => {
188+
const envs = (await getEnvironments(eb)) || []
189+
if (!isEmpty(envs)) {
190+
envsData.push(...envs.map(val => ({ ...val, region })))
193191
numberOfEnvs += envs.length
194-
resolveRegion()
195-
})
192+
}
193+
resolveRegion()
196194
})
197-
)
195+
})
196+
197+
await Promise.all(regionPromises)
198198
errorLog.reset()
199199
logger.debug(lt.fetchedElasticBeanstalkEnvs(numberOfEnvs))
200-
resolve(output)
200+
resolve(groupBy(envsData, 'region'))
201201
})

src/services/sesDomain/data.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const serviceName = 'SES Domain'
2020
const errorLog = new AwsErrorLog(serviceName)
2121
const endpoint = initTestEndpoint(serviceName)
2222

23-
2423
/**
2524
* SES Domains
2625
*/
@@ -48,20 +47,20 @@ export default async ({
4847
ses.listIdentities(
4948
{ IdentityType: 'Domain' },
5049
(err: AWSError, data: ListIdentitiesResponse) => {
51-
/**
52-
* No Data for the region
53-
*/
54-
if (isEmpty(data)) {
55-
return resolveRegion()
56-
}
57-
5850
if (err) {
5951
errorLog.generateAwsErrorLog({
6052
functionName: 'sesDomain:listIdentities',
6153
err,
6254
})
6355
}
6456

57+
/**
58+
* No Data for the region
59+
*/
60+
if (isEmpty(data)) {
61+
return resolveRegion()
62+
}
63+
6564
const { Identities }: { Identities: string[] } = data
6665

6766
/**
@@ -87,15 +86,15 @@ export default async ({
8786
) => {
8887
if (err) {
8988
errorLog.generateAwsErrorLog({
90-
functionName: 'sesDomain:getIdentityVerificationAttributes',
89+
functionName:
90+
'sesDomain:getIdentityVerificationAttributes',
9191
err,
9292
})
9393
}
9494

9595
if (!isEmpty(identities)) {
9696
sesData.push(
9797
...Identities.map(Identity => ({
98-
9998
Identity,
10099
...identities[Identity],
101100
region,

src/services/sesEmail/data.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ export default async ({
4747
ses.listIdentities(
4848
{ IdentityType: 'EmailAddress' },
4949
(err: AWSError, data: ListIdentitiesResponse) => {
50-
/**
51-
* No Data for the region
52-
*/
53-
if (isEmpty(data)) {
54-
return resolveRegion()
55-
}
56-
5750
if (err) {
5851
errorLog.generateAwsErrorLog({
5952
functionName: 'sesEmail:listIdentities',
6053
err,
6154
})
6255
}
6356

57+
/**
58+
* No Data for the region
59+
*/
60+
if (isEmpty(data)) {
61+
return resolveRegion()
62+
}
63+
6464
const { Identities }: { Identities: string[] } = data
6565

6666
/**
@@ -86,15 +86,15 @@ export default async ({
8686
) => {
8787
if (err) {
8888
errorLog.generateAwsErrorLog({
89-
functionName: 'sesEmail:getIdentityVerificationAttributes',
89+
functionName:
90+
'sesEmail:getIdentityVerificationAttributes',
9091
err,
9192
})
9293
}
9394

9495
if (!isEmpty(identities)) {
9596
sesData.push(
9697
...Identities.map(Identity => ({
97-
9898
Identity,
9999
...identities[Identity],
100100
region,

src/services/systemsManagerParameter/data.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from '@aws-sdk/client-ssm'
77
import CloudGraph from '@cloudgraph/sdk'
88
import { Config } from 'aws-sdk'
9+
import { groupBy } from 'lodash'
910
import isEmpty from 'lodash/isEmpty'
1011
import awsLoggerText from '../../properties/logger'
1112
import AwsErrorLog from '../../utils/errorLog'
@@ -16,6 +17,10 @@ const serviceName = 'SystemsManagerParameter'
1617
const errorLog = new AwsErrorLog(serviceName)
1718
const MAX_ITEMS = 50
1819

20+
export interface RawAwsParameterMetadata extends ParameterMetadata {
21+
region: string
22+
}
23+
1924
const listParameters = async (ssm: SSMClient): Promise<ParameterMetadata[]> =>
2025
new Promise(async resolve => {
2126
const parameters: ParameterMetadata[] = []
@@ -64,26 +69,24 @@ export default async ({
6469
}: {
6570
regions: string
6671
config: Config
67-
}): Promise<{ [property: string]: ParameterMetadata[] }> =>
72+
}): Promise<{ [property: string]: RawAwsParameterMetadata[] }> =>
6873
new Promise(async resolve => {
6974
const { credentials } = config
70-
const output: { [property: string]: ParameterMetadata[] } = {}
75+
const paramsData: RawAwsParameterMetadata[] = []
7176

72-
await Promise.all(
73-
regions.split(',').map(region => {
74-
const ssm = new SSMClient({
75-
credentials,
76-
region,
77-
})
78-
output[region] = []
79-
return new Promise<void>(async resolveRegion => {
80-
const params = (await listParameters(ssm)) || []
81-
output[region] = params
82-
resolveRegion()
83-
})
77+
const regionPromises = regions.split(',').map(async region => {
78+
const ssm = new SSMClient({
79+
credentials,
80+
region,
8481
})
85-
)
82+
const params = (await listParameters(ssm)) || []
83+
if (!isEmpty(params)) {
84+
paramsData.push(...params.map(val => ({ ...val, region })))
85+
}
86+
})
87+
88+
await Promise.all(regionPromises)
8689
errorLog.reset()
8790

88-
resolve(output)
91+
resolve(groupBy(paramsData, 'region'))
8992
})

src/services/systemsManagerParameter/format.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ParameterMetadata } from '@aws-sdk/client-ssm'
21
import { AwsSystemsManagerParameter } from '../../types/generated'
32
import { ssmParameterArn } from '../../utils/generateArns'
3+
import { RawAwsParameterMetadata } from './data'
44

55
/**
66
* Systems Manager Parameter
@@ -12,7 +12,7 @@ export default ({
1212
}: {
1313
account: string
1414
region: string
15-
service: ParameterMetadata
15+
service: RawAwsParameterMetadata
1616
}): AwsSystemsManagerParameter => {
1717
const { Name: name } = parameter
1818

0 commit comments

Comments
 (0)