Skip to content

Commit da61bcc

Browse files
authored
Merge pull request #50 from cloudgraphdev/feature/CG-1112
feat: Add cloudfront connection to cloudwatch service
2 parents 8dcd004 + 1452894 commit da61bcc

5 files changed

Lines changed: 44 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ CloudGraph AWS Provider will ask you what regions you would like to crawl and wi
8080
| cloud9 | |
8181
| cloudformationStack | cloudformationStack, iamRole, sns |
8282
| cloudformationStackSet | iamRole |
83-
| cloudfront | elb, s3 |
83+
| cloudfront | cloudwatch, elb, s3 |
8484
| cloudtrail | cloudwatch, cloudwatchLog, kms, s3, sns |
85-
| cloudwatch | cloudtrail, cloudwatchLog, sns |
85+
| cloudwatch | cloudfront, cloudtrail, cloudwatchLog, sns |
8686
| cloudwatchLog | cloudtrail, cloudwatch, ecsCluster, elasticSearchDomain, kms, managedAirflow, rdsDbInstance |
8787
| codebuild | iamRole, kms, vpc, securityGroup, subnet |
8888
| cognitoIdentityPool | iamRole, iamOpenIdConnectProvider, iamSamlProvider, elasticSearchDomain |

src/services/cloudfront/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type awsCloudfront implements awsBaseService @key(fields: "id") {
2121
s3: [awsS3] @hasInverse(field: cloudfrontDistributions)
2222
tags: [awsRawTag]
2323
webAcl: [awsWafV2WebAcl] @hasInverse(field: cloudfront)
24+
cloudwatch: [awsCloudwatch] @hasInverse(field: cloudfront)
2425
}
2526

2627
type awsCloudfrontOriginData {

src/services/cloudwatch/connections.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { ServiceConnection } from '@cloudgraph/sdk'
22
import { isEmpty } from 'lodash'
33
import { RawAwsCloudwatch } from './data'
4+
import { RawAwsCloudfront } from '../cloudfront/data'
45
import services from '../../enums/services'
6+
import { globalRegionName } from '../../enums/regions'
57

68
export default ({
79
service: cloudwatch,
@@ -15,7 +17,11 @@ export default ({
1517
}): {
1618
[property: string]: ServiceConnection[]
1719
} => {
18-
const { AlarmName: id, AlarmActions: alarmActions } = cloudwatch
20+
const {
21+
AlarmName: id,
22+
AlarmActions: alarmActions,
23+
Dimensions: dimensions,
24+
} = cloudwatch
1925
const connections: ServiceConnection[] = []
2026

2127
/**
@@ -40,6 +46,32 @@ export default ({
4046
}
4147
}
4248

49+
/**
50+
* Find Cloudfront
51+
* related to the cloudwatch
52+
*/
53+
const cloudfronts = data.find(({ name }) => name === services.cloudfront)
54+
if (cloudfronts?.data?.[globalRegionName]) {
55+
const cloudfrontsInRegion: RawAwsCloudfront[] = cloudfronts.data[globalRegionName].filter(
56+
({ summary: { Id: cloudfrontId } }: RawAwsCloudfront) =>
57+
dimensions?.some(d => d.Value === cloudfrontId)
58+
)
59+
60+
if (!isEmpty(cloudfrontsInRegion)) {
61+
for (const cf of cloudfrontsInRegion) {
62+
const {
63+
summary: { Id: cloudfrontId },
64+
}: RawAwsCloudfront = cf
65+
connections.push({
66+
id: cloudfrontId,
67+
resourceType: services.cloudfront,
68+
relation: 'child',
69+
field: 'cloudfront',
70+
})
71+
}
72+
}
73+
}
74+
4375
const result = {
4476
[id]: connections,
4577
}

src/services/cloudwatch/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type awsCloudwatch implements awsBaseService @key(fields: "arn") {
1414
cloudwatchLog: [awsCloudwatchLog] @hasInverse(field: cloudwatch)
1515
sns: [awsSns] @hasInverse(field: cloudwatch)
1616
cloudtrail: [awsCloudtrail] @hasInverse(field: cloudwatch)
17+
cloudfront: [awsCloudfront] @hasInverse(field: cloudwatch)
1718
}
1819

1920
type awsCloudwatchDimensions

src/types/generated.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ export type AwsCloudFormationStackSetParameter = {
743743

744744
export type AwsCloudfront = AwsBaseService & {
745745
callerReference?: Maybe<Scalars['String']>;
746+
cloudwatch?: Maybe<Array<Maybe<AwsCloudwatch>>>;
746747
customErrorResponses?: Maybe<Array<Maybe<AwsCloudfrontCustomErrorResponse>>>;
747748
defaultCacheBehavior?: Maybe<AwsCloudfrontCacheBehavior>;
748749
defaultRootObject?: Maybe<Scalars['String']>;
@@ -898,6 +899,7 @@ export type AwsCloudtrailStatus = {
898899
export type AwsCloudwatch = AwsBaseService & {
899900
actions?: Maybe<Array<Maybe<Scalars['String']>>>;
900901
actionsEnabled?: Maybe<Scalars['String']>;
902+
cloudfront?: Maybe<Array<Maybe<AwsCloudfront>>>;
901903
cloudtrail?: Maybe<Array<Maybe<AwsCloudtrail>>>;
902904
cloudwatchLog?: Maybe<Array<Maybe<AwsCloudwatchLog>>>;
903905
comparisonOperator?: Maybe<Scalars['String']>;
@@ -4226,8 +4228,12 @@ export type AwsTransitGateway = AwsBaseService & {
42264228
vpnEcmpSupport?: Maybe<Scalars['String']>;
42274229
};
42284230

4229-
export type AwsTransitGatewayAttachment = AwsBaseService & {
4231+
export type AwsTransitGatewayAttachment = {
4232+
accountId: Scalars['String'];
4233+
arn: Scalars['String'];
42304234
creationTime?: Maybe<Scalars['String']>;
4235+
id: Scalars['String'];
4236+
region?: Maybe<Scalars['String']>;
42314237
resourceId?: Maybe<Scalars['String']>;
42324238
resourceOwnerId?: Maybe<Scalars['String']>;
42334239
resourceType?: Maybe<Scalars['String']>;

0 commit comments

Comments
 (0)