Skip to content

Commit eb44044

Browse files
author
Marco Franceschi
committed
feat: Created account global service
1 parent 5a1d5c1 commit eb44044

6 files changed

Lines changed: 134 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { ServiceConnection } from '@cloudgraph/sdk'
2+
import { flatMap } from 'lodash'
3+
import services from '../../enums/services'
4+
5+
export default ({
6+
service,
7+
data,
8+
}: {
9+
service: any
10+
data: Array<{
11+
name: string
12+
accountId: string
13+
data: { [property: string]: any[] }
14+
}>
15+
}): {
16+
[property: string]: ServiceConnection[]
17+
} => {
18+
const { id } = service
19+
const connections: ServiceConnection[] = []
20+
const connectTo = Object.values(services).filter(s => s !== 'account')
21+
22+
for (const serviceName of connectTo) {
23+
const instances: {
24+
name: string
25+
data: { [property: string]: any[] }
26+
} = data.find(({ name }) => {
27+
return name === serviceName
28+
})
29+
30+
if (instances?.data) {
31+
const filtered = flatMap(instances.data).filter(i => i.accountId === id)
32+
33+
for (const instance of filtered) {
34+
if (instance) {
35+
connections.push({
36+
id: instance.id,
37+
resourceType: serviceName,
38+
relation: 'child',
39+
field: serviceName,
40+
})
41+
}
42+
}
43+
}
44+
}
45+
46+
return {
47+
[id]: connections,
48+
}
49+
}

src/services/account/data.ts

Whitespace-only changes.

src/services/account/format.ts

Whitespace-only changes.

src/services/account/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Service } from '@cloudgraph/sdk'
2+
import BaseService from '../base'
3+
import getConnections from './connections'
4+
import mutation from './mutation'
5+
6+
export default class AwsAccount extends BaseService implements Service {
7+
format = ({ service }: { service: any }): any => service
8+
9+
getConnections = getConnections.bind(this)
10+
11+
getData
12+
13+
mutation = mutation
14+
}

src/services/account/mutation.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default `mutation($input: [AddawsAccountInput!]!) {
2+
addawsAccount(input: $input, upsert: true) {
3+
numUids
4+
}
5+
}`
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#change to plural for ALL SERVICE FIELDS
2+
type awsAccount @key(fields: "id") {
3+
id: String! @id @search(by: [hash])
4+
alb: [awsAlb] #change to plural
5+
asg: [awsAsg] #change to plural
6+
cloudwatch: [awsCloudwatch] #change to plural
7+
cloudfront: [awsCloudfront] #change to plural
8+
codebuilds: [awsCodebuild]
9+
ebs: [awsEbs]
10+
eip: [awsEip]
11+
elb: [awsElb]
12+
igw: [awsIgw]
13+
kms: [awsKms]
14+
lambda: [awsLambda]
15+
natGateway: [awsNatGateway]
16+
networkInterface: [awsNetworkInterface]
17+
securityGroups: [awsSecurityGroup]
18+
vpc: [awsVpc]
19+
ec2Instance: [awsEc2]
20+
sqs: [awsSqs]
21+
routeTable: [awsRouteTable]
22+
s3: [awsS3]
23+
cognitoIdentityPool: [awsCognitoIdentityPool]
24+
cognitoUserPool: [awsCognitoUserPool]
25+
kinesisFirehose: [awsKinesisFirehose]
26+
appSync: [awsAppSync]
27+
cloudtrail: [awsCloudtrail]
28+
cloudFormationStack: [awsCloudFormationStack]
29+
cloudFormationStackSet: [awsCloudFormationStackSet]
30+
dynamodb: [awsDynamoDbTable]
31+
nacl: [awsNetworkAcl]
32+
ecr: [awsEcr]
33+
subnet: [awsSubnet]
34+
secretsManager: [awsSecretsManager]
35+
iamUsers: [awsIamUser]
36+
iamRoles: [awsIamRole]
37+
iamPolicies: [awsIamPolicy]
38+
rdsCluster: [awsRdsCluster]
39+
rdsDbInstance: [awsRdsDbInstance]
40+
elasticBeanstalkApp: [awsElasticBeanstalkApp]
41+
elasticBeanstalkEnv: [awsElasticBeanstalkEnv]
42+
sns: [awsSns]
43+
redshiftClusters: [awsRedshiftCluster]
44+
eksCluster: [awsEksCluster]
45+
ecsCluster: [awsEcsCluster]
46+
ecsContainer: [awsEcsContainer]
47+
ecsService: [awsEcsService]
48+
ecsTask: [awsEcsTask]
49+
apiGatewayRestApi: [awsApiGatewayRestApi]
50+
apiGatewayStage: [awsApiGatewayStage]
51+
elastiCacheCluster: [awsElastiCacheCluster]
52+
elastiCacheReplicationGroup: [awsElastiCacheReplicationGroup]
53+
cloud9Environment: [awsCloud9Environment]
54+
efs: [awsEfs]
55+
flowLogs: [awsFlowLog]
56+
emrCluster: [awsEmrCluster]
57+
customerGateway: [awsCustomerGateway]
58+
transitGateway: [awsTransitGateway]
59+
transitGatewayAttachment: [awsTransitGatewayAttachment]
60+
vpnGateway: [awsVpnGateway]
61+
clientVpnEndpoint: [awsClientVpnEndpoint]
62+
vpnConnection: [awsVpnConnection]
63+
managedAirflows: [awsManagedAirflow]
64+
guardDutyDetectors: [awsGuardDutyDetector]
65+
elasticSearchDomains: [awsElasticSearchDomain]
66+
}

0 commit comments

Comments
 (0)