Skip to content

Commit 15ca93f

Browse files
committed
feat(services): add new connection wafV2WebAcl <-> cloudfront
1 parent adbe084 commit 15ca93f

4 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/services/cloudfront/connections.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { RawAwsS3 } from '../s3/data'
77
import { RawAwsElb } from '../elb/data'
88
import { RawAwsCloudfront } from './data'
99
import { elbArn } from '../../utils/generateArns'
10+
import { RawAwsWafV2WebAcl } from '../wafV2WebAcl/data'
1011

1112
/**
1213
* Cloudfront
@@ -22,7 +23,7 @@ export default ({
2223
}): { [key: string]: ServiceConnection[] } => {
2324
const connections: ServiceConnection[] = []
2425
const {
25-
summary: { Id: id },
26+
summary: { Id: id, WebACLId },
2627
config: {
2728
Origins: { Items: originData = [] },
2829
},
@@ -100,6 +101,33 @@ export default ({
100101
})
101102
}
102103

104+
/**
105+
* Find wafV2WebAcls
106+
* related to this Cloudfront distribution
107+
*/
108+
const acls: {
109+
name: string
110+
data: { [property: string]: RawAwsWafV2WebAcl[] }
111+
} = data.find(({ name }) => name === services.wafV2WebAcl)
112+
113+
if (acls?.data) {
114+
const allAcls = Object.values(acls.data).flat()
115+
const dataInRegion: RawAwsWafV2WebAcl[] = allAcls.filter(
116+
({ ARN }: RawAwsWafV2WebAcl) => ARN === WebACLId
117+
)
118+
119+
if (!isEmpty(dataInRegion)) {
120+
for (const acl of dataInRegion) {
121+
connections.push({
122+
id: acl.Id,
123+
resourceType: services.wafV2WebAcl,
124+
relation: 'child',
125+
field: 'webAcl',
126+
})
127+
}
128+
}
129+
}
130+
103131
const cloudfrontResult = {
104132
[id]: connections,
105133
}

src/services/cloudfront/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type awsCloudfront @key(fields: "id") {
2222
elb: [awsElb] @hasInverse(field: cloudfrontDistribution)
2323
s3: [awsS3] @hasInverse(field: cloudfrontDistribution)
2424
tags: [awsRawTag]
25+
webAcl: [awsWafV2WebAcl] @hasInverse(field: cloudfront)
2526
}
2627

2728
type awsCloudfrontOriginData {

src/services/wafV2WebAcl/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type awsWafV2WebAcl @key(fields: "arn") {
1515
postProcessFirewallManagerRuleGroups: [awsWafV2FirewallManagerRuleGroup]
1616
customResponseBodies: [awsWafV2CustomResponseBody]
1717
loggingConfiguration: awsWafV2LoggingConfig
18+
cloudfront: [awsCloudfront] @hasInverse(field: webAcl)
1819
}
1920

2021
type awsWafV2Rule {

src/types/generated.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ export type AwsCloudfront = {
688688
status?: Maybe<Scalars['String']>;
689689
tags?: Maybe<Array<Maybe<AwsRawTag>>>;
690690
viewerCertificate?: Maybe<AwsCloudfrontViewerCertificate>;
691+
webAcl?: Maybe<Array<Maybe<AwsWafV2WebAcl>>>;
691692
webAclId?: Maybe<Scalars['String']>;
692693
};
693694

@@ -3072,7 +3073,7 @@ export type AwsIamRole = {
30723073
name?: Maybe<Scalars['String']>;
30733074
path?: Maybe<Scalars['String']>;
30743075
sageMakerNotebookInstances?: Maybe<Array<Maybe<AwsSageMakerNotebookInstance>>>;
3075-
systemManagerInstances?: Maybe<Array<Maybe<AwsSystemsManagerInstance>>>;
3076+
systemsManagerInstances?: Maybe<Array<Maybe<AwsSystemsManagerInstance>>>;
30763077
tags?: Maybe<Array<Maybe<AwsRawTag>>>;
30773078
};
30783079

@@ -4529,6 +4530,7 @@ export type AwsWafV2WebAcl = {
45294530
accountId: Scalars['String'];
45304531
arn: Scalars['String'];
45314532
capacity?: Maybe<Scalars['Int']>;
4533+
cloudfront?: Maybe<Array<Maybe<AwsCloudfront>>>;
45324534
customResponseBodies?: Maybe<Array<Maybe<AwsWafV2CustomResponseBody>>>;
45334535
defaultAction?: Maybe<AwsWafV2DefaultAction>;
45344536
description?: Maybe<Scalars['String']>;

0 commit comments

Comments
 (0)