Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/services/nacl/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ServiceConnection } from '@cloudgraph/sdk'
import isEmpty from 'lodash/isEmpty'

import services from '../../enums/services'
import { RawAwsSubnet } from '../subnet/data'
import { RawAwsVpc } from '../vpc/data'
import { RawAwsNetworkAcl } from './data'

Expand All @@ -19,9 +20,40 @@ export default ({
service: RawAwsNetworkAcl
}): { [key: string]: ServiceConnection[] } => {
const connections: ServiceConnection[] = []
const { NetworkAclId: id, VpcId: NaclVpcId } = nacl
const {
NetworkAclId: id,
VpcId: NaclVpcId,
Associations: naclSubnetAssociations = [],
} = nacl

// TODO: Add subnet connection
const subnetIds = naclSubnetAssociations.map(({ SubnetId }) => SubnetId)

/**
* Find related Subnets
*/
const subnets: {
name: string
data: { [property: string]: RawAwsSubnet[] }
} = data.find(({ name }) => name === services.subnet)
if (subnets?.data?.[region]) {
const dataAtRegion: RawAwsSubnet[] = subnets.data[region].filter(
({ SubnetId }: RawAwsSubnet) =>
!isEmpty(subnetIds) &&
subnetIds.filter(str =>
str.toLowerCase().includes(SubnetId.toLowerCase())
).length > 0
)
if (!isEmpty(dataAtRegion)) {
for (const subnet of dataAtRegion) {
connections.push({
id: subnet.SubnetId,
resourceType: services.subnet,
relation: 'child',
field: 'subnets',
})
}
}
}

/**
* Find related Vpc
Expand Down
2 changes: 1 addition & 1 deletion src/services/nacl/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type awsNetworkAcl implements awsBaseService @key(fields: "id") {
associatedSubnets: [awsNetworkAclAssociatedSubnet]
tags: [awsRawTag]
vpc: [awsVpc] @hasInverse(field: nacl)
# subnet: [awsSubnet] @hasInverse(field: nacl) #change to plural
subnets: [awsSubnet] @hasInverse(field: nacls)
vpcId: String @search(by: [hash, regexp])
}

Expand Down
1 change: 1 addition & 0 deletions src/services/subnet/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type awsSubnet implements awsBaseService @key(fields: "id") {
ec2Instances: [awsEc2] @hasInverse(field: subnets) #change to plural
elb: [awsElb] @hasInverse(field: subnet) #change to plural
lambda: [awsLambda] @hasInverse(field: subnet) #change to plural
nacls: [awsNetworkAcl] @hasInverse(field: subnets)
natGateway: [awsNatGateway] @hasInverse(field: subnet) #change to plural
networkInterface: [awsNetworkInterface] @hasInverse(field: subnet) #change to plural
routeTable: [awsRouteTable] @hasInverse(field: subnet)
Expand Down
2 changes: 2 additions & 0 deletions src/types/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3392,6 +3392,7 @@ export type AwsNetworkAcl = AwsBaseService & {
default?: Maybe<Scalars['Boolean']>;
inboundRules?: Maybe<Array<Maybe<AwsNetworkAclRule>>>;
outboundRules?: Maybe<Array<Maybe<AwsNetworkAclRule>>>;
subnets?: Maybe<Array<Maybe<AwsSubnet>>>;
tags?: Maybe<Array<Maybe<AwsRawTag>>>;
vpc?: Maybe<Array<Maybe<AwsVpc>>>;
vpcId?: Maybe<Scalars['String']>;
Expand Down Expand Up @@ -3919,6 +3920,7 @@ export type AwsSubnet = AwsBaseService & {
ipV6Cidr?: Maybe<Scalars['String']>;
lambda?: Maybe<Array<Maybe<AwsLambda>>>;
managedAirflows?: Maybe<Array<Maybe<AwsManagedAirflow>>>;
nacls?: Maybe<Array<Maybe<AwsNetworkAcl>>>;
natGateway?: Maybe<Array<Maybe<AwsNatGateway>>>;
networkInterface?: Maybe<Array<Maybe<AwsNetworkInterface>>>;
rdsDbInstance?: Maybe<Array<Maybe<AwsRdsDbInstance>>>;
Expand Down