@@ -4,6 +4,8 @@ import services from '../../enums/services'
44import { RawAwsManagedAirflow } from '../managedAirflow/data'
55import { RawAwsS3 } from '../s3/data'
66import { AwsSecurityGroup } from '../securityGroup/data'
7+ import { RawAwsLogGroup } from '../cloudwatchLogs/data'
8+ import { AwsKms } from '../kms/data'
79import { s3BucketArn } from '../../utils/generateArns'
810
911export default ( {
@@ -17,49 +19,110 @@ export default ({
1719} ) : {
1820 [ property : string ] : ServiceConnection [ ]
1921} => {
20- const { Arn, SourceBucketArn, NetworkConfiguration : { SecurityGroupIds = [ ] } = { } } = airflow
22+ const {
23+ Arn : id ,
24+ SourceBucketArn,
25+ NetworkConfiguration : { SecurityGroupIds = [ ] } = { } ,
26+ LoggingConfiguration,
27+ KmsKey,
28+ } = airflow
2129 const connections : ServiceConnection [ ] = [ ]
2230
2331 /**
2432 * Find any S3 related data
2533 */
26- const buckets = data . find ( ( { name } ) => name === services . s3 )
27- if ( buckets ?. data ?. [ region ] ) {
28- const dataAtRegion : RawAwsS3 [ ] = buckets . data [ region ] . filter (
29- ( { Name : name } : RawAwsS3 ) =>
30- s3BucketArn ( { name } ) === SourceBucketArn
31- )
32- for ( const bucket of dataAtRegion ) {
33- connections . push ( {
34- id : bucket . Id ,
35- resourceType : services . s3 ,
36- relation : 'child' ,
37- field : 's3' ,
38- } )
39- }
40- }
34+ const buckets = data . find ( ( { name } ) => name === services . s3 )
35+ if ( buckets ?. data ?. [ region ] ) {
36+ const dataAtRegion : RawAwsS3 [ ] = buckets . data [ region ] . filter (
37+ ( { Name : name } : RawAwsS3 ) => s3BucketArn ( { name } ) === SourceBucketArn
38+ )
39+ for ( const bucket of dataAtRegion ) {
40+ connections . push ( {
41+ id : bucket . Id ,
42+ resourceType : services . s3 ,
43+ relation : 'child' ,
44+ field : 's3' ,
45+ } )
46+ }
47+ }
4148
42- /**
49+ /**
4350 * Find any securityGroups related data
4451 */
45- const securityGroups = data . find ( ( { name } ) => name === services . sg )
46- if ( securityGroups ?. data ?. [ region ] ) {
47- const dataAtRegion : AwsSecurityGroup [ ] = securityGroups . data [ region ] . filter (
48- ( { GroupId } : AwsSecurityGroup ) =>
49- SecurityGroupIds . includes ( GroupId )
50- )
51- for ( const securityGroup of dataAtRegion ) {
52- connections . push ( {
53- id : securityGroup . GroupId ,
54- resourceType : services . sg ,
55- relation : 'child' ,
56- field : 'securityGroups' ,
57- } )
52+ const securityGroups = data . find ( ( { name } ) => name === services . sg )
53+ if ( securityGroups ?. data ?. [ region ] ) {
54+ const dataAtRegion : AwsSecurityGroup [ ] = securityGroups . data [ region ] . filter (
55+ ( { GroupId } : AwsSecurityGroup ) => SecurityGroupIds . includes ( GroupId )
56+ )
57+ for ( const securityGroup of dataAtRegion ) {
58+ connections . push ( {
59+ id : securityGroup . GroupId ,
60+ resourceType : services . sg ,
61+ relation : 'child' ,
62+ field : 'securityGroups' ,
63+ } )
64+ }
65+ }
66+
67+ /**
68+ * Find any cloudwatch log group related data
69+ */
70+ const cloudwatchLogs = data . find (
71+ ( { name } ) => name === services . cloudwatchLog
72+ )
73+ if ( cloudwatchLogs ?. data ?. [ region ] ) {
74+ const dataAtRegion : RawAwsLogGroup [ ] = cloudwatchLogs . data [ region ] . filter (
75+ ( { logGroupName } : RawAwsLogGroup ) => {
76+ return (
77+ LoggingConfiguration ?. TaskLogs ?. CloudWatchLogGroupArn ?. includes (
78+ logGroupName
79+ ) ||
80+ LoggingConfiguration ?. SchedulerLogs ?. CloudWatchLogGroupArn ?. includes (
81+ logGroupName
82+ ) ||
83+ LoggingConfiguration ?. WorkerLogs ?. CloudWatchLogGroupArn ?. includes (
84+ logGroupName
85+ ) ||
86+ LoggingConfiguration ?. WebserverLogs ?. CloudWatchLogGroupArn ?. includes (
87+ logGroupName
88+ ) ||
89+ LoggingConfiguration ?. DagProcessingLogs ?. CloudWatchLogGroupArn ?. includes (
90+ logGroupName
91+ )
92+ )
5893 }
94+ )
95+
96+ for ( const logGroup of dataAtRegion ) {
97+ connections . push ( {
98+ id : logGroup . logGroupName ,
99+ resourceType : services . cloudwatchLog ,
100+ relation : 'child' ,
101+ field : 'cloudwatchLogs' ,
102+ } )
103+ }
104+ }
105+
106+ /**
107+ * Find any kms related data
108+ */
109+ const kms = data . find ( ( { name } ) => name === services . kms )
110+ if ( kms ?. data ?. [ region ] ) {
111+ const dataAtRegion : AwsKms [ ] = kms . data [ region ] . filter (
112+ ( { Arn } : AwsKms ) => Arn === KmsKey
113+ )
114+
115+ for ( const kmsKey of dataAtRegion ) {
116+ connections . push ( {
117+ id : kmsKey . KeyId ,
118+ resourceType : services . kms ,
119+ relation : 'child' ,
120+ field : 'kms' ,
121+ } )
59122 }
123+ }
60124
61- const natResult = {
62- [ Arn ] : connections ,
125+ return {
126+ [ id ] : connections ,
63127 }
64- return natResult
65128}
0 commit comments