Skip to content

Commit 896e813

Browse files
author
Marco Franceschi
committed
feat: Solved duplication issues
1 parent aca3e8f commit 896e813

5 files changed

Lines changed: 178 additions & 149 deletions

File tree

src/services/athenaDataCatalog/format.ts

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,7 @@ import { athenaDataCatalogArn } from '../../utils/generateArns'
88
/**
99
* AthenaDataCatalog
1010
*/
11-
const formatColumns = (column: Column) => {
12-
return {
13-
id: generateUniqueId({
14-
...column,
15-
}),
16-
name: column.Name,
17-
type: column.Type,
18-
comment: column.Comment,
19-
}
20-
}
21-
const formatMetadata = (metadata: TableMetadata) => {
22-
return {
23-
name: metadata.Name,
24-
createTime: metadata.CreateTime?.toISOString(),
25-
lastAccessTime: metadata.LastAccessTime?.toISOString(),
26-
tableType: metadata.TableType,
27-
columns: metadata.Columns?.map(formatColumns),
28-
partitionKeys: metadata.PartitionKeys?.map(formatColumns),
29-
parameters: Object.keys(metadata.Parameters ?? {}).map(key => ({
30-
id: generateUniqueId({
31-
...metadata,
32-
}),
33-
key,
34-
value: metadata.Parameters[key],
35-
})),
36-
}
37-
}
11+
3812
export default ({
3913
account,
4014
service: rawData,
@@ -45,15 +19,49 @@ export default ({
4519
region: string
4620
}): AwsAthenaDataCatalog => {
4721
const { CatalogName: catalogName, Type: type, databases = [] } = rawData
22+
const arn = athenaDataCatalogArn({ region, account, name: catalogName })
23+
24+
const formatColumns = (column: Column) => {
25+
return {
26+
id: generateUniqueId({
27+
arn,
28+
...column,
29+
}),
30+
name: column.Name,
31+
type: column.Type,
32+
comment: column.Comment,
33+
}
34+
}
35+
const formatMetadata = (metadata: TableMetadata) => {
36+
return {
37+
name: metadata.Name,
38+
createTime: metadata.CreateTime?.toISOString(),
39+
lastAccessTime: metadata.LastAccessTime?.toISOString(),
40+
tableType: metadata.TableType,
41+
columns: metadata.Columns?.map(formatColumns),
42+
partitionKeys: metadata.PartitionKeys?.map(formatColumns),
43+
parameters: Object.keys(metadata.Parameters ?? {}).map(key => ({
44+
id: generateUniqueId({
45+
arn,
46+
...metadata,
47+
}),
48+
key,
49+
value: metadata.Parameters[key],
50+
})),
51+
}
52+
}
53+
4854
const formattedDatabases = databases.map(val => ({
4955
id: generateUniqueId({
56+
arn,
5057
catalogName,
5158
...val,
5259
}),
5360
name: val.Name,
5461
description: val.Description,
5562
parameters: Object.keys(val.Parameters ?? {}).map(key => ({
5663
id: generateUniqueId({
64+
arn,
5765
catalogName,
5866
key,
5967
value: val.Parameters[key],
@@ -63,7 +71,7 @@ export default ({
6371
})),
6472
metadata: formatMetadata(val.metadata),
6573
}))
66-
const arn = athenaDataCatalogArn({ region, account, name: catalogName })
74+
6775
return {
6876
id: arn,
6977
arn,

src/services/cloudfront/format.ts

Lines changed: 93 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -17,94 +17,6 @@ import {
1717
} from '../../types/generated'
1818
import { RawAwsCloudfront } from './data'
1919

20-
export const createCacheBehavior = (
21-
cache: CacheBehavior
22-
): AwsCloudfrontCacheBehavior => {
23-
const {
24-
AllowedMethods: {
25-
Items: allowedMethods = [],
26-
CachedMethods: { Items: cachedMethods = [] } = { Items: [] },
27-
} = {},
28-
Compress: compress,
29-
DefaultTTL: defaultTtl,
30-
ForwardedValues: {
31-
Headers: { Items: headers } = {},
32-
QueryString: queryString,
33-
} = {},
34-
MaxTTL: maxTtl,
35-
MinTTL: minTtl,
36-
PathPattern: patternPath,
37-
SmoothStreaming: smoothStreaming,
38-
TargetOriginId: targetOriginId,
39-
ViewerProtocolPolicy: viewerProtocolPolicy,
40-
} = cache
41-
42-
const forwardedValues = {
43-
headers,
44-
queryString: queryString ? t.yes : t.no,
45-
}
46-
47-
return {
48-
id: generateUniqueId({
49-
...cache,
50-
}),
51-
allowedMethods,
52-
cachedMethods,
53-
compress: compress ? t.yes : t.no,
54-
defaultTtl: defaultTtl ? `${defaultTtl} ${t.seconds}` : null,
55-
forwardedValues,
56-
maxTtl: maxTtl ? `${maxTtl} ${t.seconds}` : null,
57-
minTtl: minTtl ? `${minTtl} ${t.seconds}` : null,
58-
patternPath,
59-
smoothStreaming: smoothStreaming ? t.yes : t.no,
60-
targetOriginId,
61-
viewerProtocolPolicy,
62-
}
63-
}
64-
65-
export const createDefaultCacheBehavior = (
66-
cache: DefaultCacheBehavior
67-
): AwsCloudfrontCacheBehavior => {
68-
const {
69-
AllowedMethods: {
70-
Items: allowedMethods = [],
71-
CachedMethods: { Items: cachedMethods = [] } = { Items: [] },
72-
} = {},
73-
Compress: compress,
74-
DefaultTTL: defaultTtl,
75-
ForwardedValues: {
76-
Headers: { Items: headers } = {},
77-
QueryString: queryString,
78-
} = {},
79-
MaxTTL: maxTtl,
80-
MinTTL: minTtl,
81-
SmoothStreaming: smoothStreaming,
82-
TargetOriginId: targetOriginId,
83-
ViewerProtocolPolicy: viewerProtocolPolicy,
84-
} = cache
85-
86-
const forwardedValues = {
87-
headers,
88-
queryString: queryString ? t.yes : t.no,
89-
}
90-
91-
return {
92-
id: generateUniqueId({
93-
...cache,
94-
}),
95-
allowedMethods,
96-
cachedMethods,
97-
compress: compress ? t.yes : t.no,
98-
defaultTtl: defaultTtl ? `${defaultTtl} ${t.seconds}` : null,
99-
forwardedValues,
100-
maxTtl: maxTtl ? `${maxTtl} ${t.seconds}` : null,
101-
minTtl: minTtl ? `${minTtl} ${t.seconds}` : null,
102-
smoothStreaming: smoothStreaming ? t.yes : t.no,
103-
targetOriginId,
104-
viewerProtocolPolicy,
105-
}
106-
}
107-
10820
/**
10921
* CloudFront
11022
*/
@@ -157,6 +69,96 @@ export default ({
15769
Tags = {},
15870
}: RawAwsCloudfront = service
15971

72+
const createCacheBehavior = (
73+
cache: CacheBehavior
74+
): AwsCloudfrontCacheBehavior => {
75+
const {
76+
AllowedMethods: {
77+
Items: allowedMethods = [],
78+
CachedMethods: { Items: cachedMethods = [] } = { Items: [] },
79+
} = {},
80+
Compress: compress,
81+
DefaultTTL: defaultTtl,
82+
ForwardedValues: {
83+
Headers: { Items: headers } = {},
84+
QueryString: queryString,
85+
} = {},
86+
MaxTTL: maxTtl,
87+
MinTTL: minTtl,
88+
PathPattern: patternPath,
89+
SmoothStreaming: smoothStreaming,
90+
TargetOriginId: targetOriginId,
91+
ViewerProtocolPolicy: viewerProtocolPolicy,
92+
} = cache
93+
94+
const forwardedValues = {
95+
headers,
96+
queryString: queryString ? t.yes : t.no,
97+
}
98+
99+
return {
100+
id: generateUniqueId({
101+
arn,
102+
...cache,
103+
}),
104+
allowedMethods,
105+
cachedMethods,
106+
compress: compress ? t.yes : t.no,
107+
defaultTtl: defaultTtl ? `${defaultTtl} ${t.seconds}` : null,
108+
forwardedValues,
109+
maxTtl: maxTtl ? `${maxTtl} ${t.seconds}` : null,
110+
minTtl: minTtl ? `${minTtl} ${t.seconds}` : null,
111+
patternPath,
112+
smoothStreaming: smoothStreaming ? t.yes : t.no,
113+
targetOriginId,
114+
viewerProtocolPolicy,
115+
}
116+
}
117+
118+
const createDefaultCacheBehavior = (
119+
cache: DefaultCacheBehavior
120+
): AwsCloudfrontCacheBehavior => {
121+
const {
122+
AllowedMethods: {
123+
Items: allowedMethods = [],
124+
CachedMethods: { Items: cachedMethods = [] } = { Items: [] },
125+
} = {},
126+
Compress: compress,
127+
DefaultTTL: defaultTtl,
128+
ForwardedValues: {
129+
Headers: { Items: headers } = {},
130+
QueryString: queryString,
131+
} = {},
132+
MaxTTL: maxTtl,
133+
MinTTL: minTtl,
134+
SmoothStreaming: smoothStreaming,
135+
TargetOriginId: targetOriginId,
136+
ViewerProtocolPolicy: viewerProtocolPolicy,
137+
} = cache
138+
139+
const forwardedValues = {
140+
headers,
141+
queryString: queryString ? t.yes : t.no,
142+
}
143+
144+
return {
145+
id: generateUniqueId({
146+
arn,
147+
...cache,
148+
}),
149+
allowedMethods,
150+
cachedMethods,
151+
compress: compress ? t.yes : t.no,
152+
defaultTtl: defaultTtl ? `${defaultTtl} ${t.seconds}` : null,
153+
forwardedValues,
154+
maxTtl: maxTtl ? `${maxTtl} ${t.seconds}` : null,
155+
minTtl: minTtl ? `${minTtl} ${t.seconds}` : null,
156+
smoothStreaming: smoothStreaming ? t.yes : t.no,
157+
targetOriginId,
158+
viewerProtocolPolicy,
159+
}
160+
}
161+
160162
const customErrorResponses: AwsCloudfrontCustomErrorResponse[] = cer.map(
161163
({
162164
ErrorCachingMinTTL: errorCachingMinTtl,
@@ -165,6 +167,7 @@ export default ({
165167
ResponsePagePath: responsePagePath,
166168
}) => ({
167169
id: generateUniqueId({
170+
arn,
168171
errorCachingMinTtl,
169172
errorCode,
170173
responseCode,
@@ -210,10 +213,12 @@ export default ({
210213
} = origin
211214
return {
212215
id: generateUniqueId({
216+
arn,
213217
...origin,
214218
}),
215219
customHeaders: customHeader.map(({ HeaderName, HeaderValue }) => ({
216220
id: generateUniqueId({
221+
arn,
217222
HeaderName,
218223
HeaderValue,
219224
}),

src/services/ebs/format.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ export default ({
3434
VolumeId: id,
3535
Tags: tags,
3636
} = rawData
37+
const arn = ebsVolumeArn({ region, account, id })
3738

3839
// Format volume permissions
3940
const volumePermissions = permissions.map(permission => {
4041
return {
41-
id: generateUniqueId({ ...permission }),
42+
id: generateUniqueId({ arn, ...permission }),
4243
group: permission.Group,
4344
userId: permission.UserId,
4445
}
@@ -61,7 +62,7 @@ export default ({
6162
const ebs = {
6263
id,
6364
accountId: account,
64-
arn: ebsVolumeArn({ region, account, id }),
65+
arn,
6566
region,
6667
attachments: volumeAttachments,
6768
iops,

src/services/kms/format.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,6 @@ import {
88
} from '../../types/generated'
99
import { formatTagsFromMap, formatIamJsonPolicy } from '../../utils/format'
1010

11-
export const formatAliases = (
12-
aliases?: AliasListEntry[]
13-
): AwsKmsAliasListEntry[] => {
14-
return (
15-
aliases?.map(a => ({
16-
id: generateUniqueId({
17-
...a,
18-
}),
19-
aliasName: a.AliasName,
20-
aliasArn: a.AliasArn,
21-
targetKeyId: a.TargetKeyId,
22-
creationDate: a.CreationDate?.toISOString(),
23-
lastUpdatedDate: a.LastUpdatedDate?.toISOString(),
24-
})) || []
25-
)
26-
}
27-
2811
/**
2912
* KMS
3013
*/
@@ -57,6 +40,24 @@ export default ({
5740
Aliases: aliases = [],
5841
} = key
5942

43+
const formatAliases = (
44+
aliases?: AliasListEntry[]
45+
): AwsKmsAliasListEntry[] => {
46+
return (
47+
aliases?.map(a => ({
48+
id: generateUniqueId({
49+
arn,
50+
...a,
51+
}),
52+
aliasName: a.AliasName,
53+
aliasArn: a.AliasArn,
54+
targetKeyId: a.TargetKeyId,
55+
creationDate: a.CreationDate?.toISOString(),
56+
lastUpdatedDate: a.LastUpdatedDate?.toISOString(),
57+
})) || []
58+
)
59+
}
60+
6061
return {
6162
accountId: account,
6263
arn,

0 commit comments

Comments
 (0)