Skip to content

Commit 4b7778b

Browse files
authored
Merge pull request #25 from cloudgraphdev/fix/connection-subnet-nacl
fix: added connection between nacl and subnet services
2 parents a38bafb + 478c356 commit 4b7778b

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

src/services/nacl/connections.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ServiceConnection } from '@cloudgraph/sdk'
22
import isEmpty from 'lodash/isEmpty'
33

44
import services from '../../enums/services'
5+
import { RawAwsSubnet } from '../subnet/data'
56
import { RawAwsVpc } from '../vpc/data'
67
import { RawAwsNetworkAcl } from './data'
78

@@ -19,9 +20,40 @@ export default ({
1920
service: RawAwsNetworkAcl
2021
}): { [key: string]: ServiceConnection[] } => {
2122
const connections: ServiceConnection[] = []
22-
const { NetworkAclId: id, VpcId: NaclVpcId } = nacl
23+
const {
24+
NetworkAclId: id,
25+
VpcId: NaclVpcId,
26+
Associations: naclSubnetAssociations = [],
27+
} = nacl
2328

24-
// TODO: Add subnet connection
29+
const subnetIds = naclSubnetAssociations.map(({ SubnetId }) => SubnetId)
30+
31+
/**
32+
* Find related Subnets
33+
*/
34+
const subnets: {
35+
name: string
36+
data: { [property: string]: RawAwsSubnet[] }
37+
} = data.find(({ name }) => name === services.subnet)
38+
if (subnets?.data?.[region]) {
39+
const dataAtRegion: RawAwsSubnet[] = subnets.data[region].filter(
40+
({ SubnetId }: RawAwsSubnet) =>
41+
!isEmpty(subnetIds) &&
42+
subnetIds.filter(str =>
43+
str.toLowerCase().includes(SubnetId.toLowerCase())
44+
).length > 0
45+
)
46+
if (!isEmpty(dataAtRegion)) {
47+
for (const subnet of dataAtRegion) {
48+
connections.push({
49+
id: subnet.SubnetId,
50+
resourceType: services.subnet,
51+
relation: 'child',
52+
field: 'subnets',
53+
})
54+
}
55+
}
56+
}
2557

2658
/**
2759
* Find related Vpc

src/services/nacl/schema.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type awsNetworkAcl implements awsBaseService @key(fields: "id") {
55
associatedSubnets: [awsNetworkAclAssociatedSubnet]
66
tags: [awsRawTag]
77
vpc: [awsVpc] @hasInverse(field: nacl)
8-
# subnet: [awsSubnet] @hasInverse(field: nacl) #change to plural
8+
subnets: [awsSubnet] @hasInverse(field: nacls)
99
vpcId: String @search(by: [hash, regexp])
1010
}
1111

src/services/subnet/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type awsSubnet implements awsBaseService @key(fields: "id") {
1313
ec2Instances: [awsEc2] @hasInverse(field: subnets) #change to plural
1414
elb: [awsElb] @hasInverse(field: subnet) #change to plural
1515
lambda: [awsLambda] @hasInverse(field: subnet) #change to plural
16+
nacls: [awsNetworkAcl] @hasInverse(field: subnets)
1617
natGateway: [awsNatGateway] @hasInverse(field: subnet) #change to plural
1718
networkInterface: [awsNetworkInterface] @hasInverse(field: subnet) #change to plural
1819
routeTable: [awsRouteTable] @hasInverse(field: subnet)

src/types/generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3413,6 +3413,7 @@ export type AwsNetworkAcl = AwsBaseService & {
34133413
default?: Maybe<Scalars['Boolean']>;
34143414
inboundRules?: Maybe<Array<Maybe<AwsNetworkAclRule>>>;
34153415
outboundRules?: Maybe<Array<Maybe<AwsNetworkAclRule>>>;
3416+
subnets?: Maybe<Array<Maybe<AwsSubnet>>>;
34163417
tags?: Maybe<Array<Maybe<AwsRawTag>>>;
34173418
vpc?: Maybe<Array<Maybe<AwsVpc>>>;
34183419
vpcId?: Maybe<Scalars['String']>;
@@ -3994,6 +3995,7 @@ export type AwsSubnet = AwsBaseService & {
39943995
ipV6Cidr?: Maybe<Scalars['String']>;
39953996
lambda?: Maybe<Array<Maybe<AwsLambda>>>;
39963997
managedAirflows?: Maybe<Array<Maybe<AwsManagedAirflow>>>;
3998+
nacls?: Maybe<Array<Maybe<AwsNetworkAcl>>>;
39973999
natGateway?: Maybe<Array<Maybe<AwsNatGateway>>>;
39984000
networkInterface?: Maybe<Array<Maybe<AwsNetworkInterface>>>;
39994001
rdsDbInstance?: Maybe<Array<Maybe<AwsRdsDbInstance>>>;

0 commit comments

Comments
 (0)