Skip to content

Commit b735e77

Browse files
committed
Merge branch 'alpha' into feature/CG-1061
2 parents 4ff22ec + 7c347c3 commit b735e77

File tree

11 files changed

+155
-36
lines changed

11 files changed

+155
-36
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# [0.79.0-alpha.1](https://github.com/cloudgraphdev/cloudgraph-provider-aws/compare/0.78.2-alpha.1...0.79.0-alpha.1) (2022-04-07)
2+
3+
4+
### Features
5+
6+
* Handle TODOs for dynamoDB ([625701e](https://github.com/cloudgraphdev/cloudgraph-provider-aws/commit/625701ea2a47b6be8bdf1fe910a541fd6f1ed132))
7+
* Handle TODOs for dynamoDB ([2911751](https://github.com/cloudgraphdev/cloudgraph-provider-aws/commit/2911751e96908793dc1b042b07c28bba340f1134))
8+
19
## [0.78.2-alpha.1](https://github.com/cloudgraphdev/cloudgraph-provider-aws/compare/0.78.1...0.78.2-alpha.1) (2022-04-06)
210

311

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cloudgraph/cg-provider-aws",
3-
"version": "0.78.2-alpha.1",
3+
"version": "0.79.0-alpha.1",
44
"description": "cloud-graph provider plugin for AWS used to fetch AWS cloud data.",
55
"publishConfig": {
66
"registry": "https://registry.npmjs.org/",

src/services/cloudFormationStack/connections.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { ServiceConnection } from '@cloudgraph/sdk'
22
import { Stack } from 'aws-sdk/clients/cloudformation'
33
import isEmpty from 'lodash/isEmpty'
4-
import resources from '../../enums/resources'
54
import services from '../../enums/services'
65
import { RawAwsCloudFormationStack } from './data'
76
import { RawAwsIamRole } from '../iamRole/data'
87
import { TagMap } from '../../types'
9-
import { getIamId } from '../../utils/ids'
108
import { globalRegionName } from '../../enums/regions'
119

1210
/**
@@ -84,14 +82,10 @@ export default ({
8482
)
8583
if (!isEmpty(dataAtRegion)) {
8684
for (const instance of dataAtRegion) {
87-
const { RoleId: roleId, RoleName: roleName } = instance
85+
const { Arn: arn }: RawAwsIamRole = instance
8886

8987
connections.push({
90-
id: getIamId({
91-
resourceId: roleId,
92-
resourceName: roleName,
93-
resourceType: resources.iamRole,
94-
}),
88+
id: arn,
9589
resourceType: services.iamRole,
9690
relation: 'child',
9791
field: 'iamRole',

src/services/cloudFormationStack/format.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export default ({
124124
timeoutInMinutes,
125125
capabilities,
126126
outputs: outputsList,
127-
roleArn: roleArn || '', // TODO: create connection to IAM role if possible
127+
roleArn: roleArn || '',
128128
tags: formatTagsFromMap(tags),
129129
enableTerminationProtection: enableTerminationProtection ? t.yes : t.no,
130130
parentId: parentId || '',
Lines changed: 126 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,47 @@
1-
import { UserPoolType } from 'aws-sdk/clients/cognitoidentityserviceprovider';
1+
import { UserPoolType, LambdaConfigType } from 'aws-sdk/clients/cognitoidentityserviceprovider'
22

3-
import { ServiceConnection } from '@cloudgraph/sdk';
4-
import services from '../../enums/services';
3+
import { ServiceConnection } from '@cloudgraph/sdk'
4+
import { isEmpty } from 'lodash'
5+
import services from '../../enums/services'
6+
import { sesArn } from '../../utils/generateArns'
7+
import { RawAwsLambdaFunction } from '../lambda/data'
8+
import { RawAwsSes } from '../ses/data'
9+
import { RawAwsIamRole } from '../iamRole/data'
10+
import { AwsKms } from '../kms/data'
11+
12+
const getLambdasArn = (
13+
lambdaConfig?: LambdaConfigType
14+
): string[] => {
15+
if (isEmpty(lambdaConfig)) {
16+
return []
17+
}
18+
19+
const {
20+
PreSignUp,
21+
CustomMessage,
22+
PostConfirmation,
23+
PreAuthentication,
24+
PostAuthentication,
25+
DefineAuthChallenge,
26+
CreateAuthChallenge,
27+
VerifyAuthChallengeResponse,
28+
PreTokenGeneration,
29+
UserMigration,
30+
} = lambdaConfig
31+
32+
return [
33+
PreSignUp,
34+
CustomMessage,
35+
PostConfirmation,
36+
PreAuthentication,
37+
PostAuthentication,
38+
DefineAuthChallenge,
39+
CreateAuthChallenge,
40+
VerifyAuthChallengeResponse,
41+
PreTokenGeneration,
42+
UserMigration,
43+
]?.filter(l => l)
44+
}
545

646
/**
747
* Cognito User Pool
@@ -11,7 +51,9 @@ export default ({
1151
service: userPool,
1252
data,
1353
region,
54+
account,
1455
}: {
56+
account: string
1557
data: { name: string; data: { [property: string]: any[] } }[]
1658
service: UserPoolType & {
1759
region: string
@@ -23,38 +65,104 @@ export default ({
2365
const {
2466
Id: id,
2567
LambdaConfig: lambdaConfig,
68+
EmailConfiguration: emailConfiguration,
69+
SmsConfiguration: smsConfiguration,
2670
} = userPool
2771

28-
const defineAuthChallengeArn = lambdaConfig?.DefineAuthChallenge
29-
3072
/**
3173
* Find Lambda Functions
32-
* related to this Auto Scaling Group
74+
* related to this cognito user pool
3375
*/
76+
const lambdasArn: string[] = getLambdasArn(lambdaConfig)
3477
const lambdas = data.find(({ name }) => name === services.lambda)
3578

36-
if (defineAuthChallengeArn && lambdas?.data?.[region]) {
37-
const lambdaInRegion = lambdas.data[region].find(lambda =>
38-
defineAuthChallengeArn === lambda.FunctionArn)
39-
40-
if (lambdaInRegion) {
41-
const lambdaFunctionArn = lambdaInRegion.FunctionArn
79+
if (lambdasArn?.length > 0 && lambdas?.data?.[region]) {
80+
const lambdasInRegion: RawAwsLambdaFunction[] = lambdas.data[region].filter(
81+
({ FunctionArn }: RawAwsLambdaFunction) =>
82+
lambdasArn.includes(FunctionArn)
83+
)
4284

85+
if (!isEmpty(lambdasInRegion)) {
86+
for (const lambda of lambdasInRegion) {
87+
connections.push({
88+
id: lambda.FunctionArn,
89+
resourceType: services.lambda,
90+
relation: 'child',
91+
field: 'lambdas',
92+
})
93+
}
94+
}
95+
}
96+
97+
/**
98+
* Find MKS
99+
* related to this cognito user pool
100+
*/
101+
const kmsKeyID = lambdaConfig?.KMSKeyID
102+
const kms = data.find(({ name }) => name === services.kms)
103+
104+
if (kmsKeyID && kms?.data?.[region]) {
105+
const kmsInRegion: AwsKms = kms.data[region].find(
106+
({ KeyId }: AwsKms) => kmsKeyID === KeyId
107+
)
108+
109+
if (kmsInRegion) {
43110
connections.push({
44-
id: lambdaFunctionArn,
45-
resourceType: services.lambda,
111+
id: kmsInRegion.KeyId,
112+
resourceType: services.kms,
46113
relation: 'child',
47-
field: 'lambda',
114+
field: 'kms',
48115
})
49116
}
50117
}
51118

52-
// TODO Email Sender
119+
/**
120+
* Find SES sender
121+
* related to this cognito user pool
122+
*/
123+
const emailConfigSourceArn = emailConfiguration?.SourceArn
124+
const emails = data.find(({ name }) => name === services.ses)
53125

54-
// TODO SMS Sender
126+
if (emailConfigSourceArn && emails?.data?.[region]) {
127+
const emailInRegion: RawAwsSes = emails.data[region].find(
128+
({ Identity }: RawAwsSes) =>
129+
emailConfigSourceArn === sesArn({ region, account, email: Identity })
130+
)
131+
132+
if (emailInRegion) {
133+
connections.push({
134+
id: sesArn({ region, account, email: emailInRegion.Identity }),
135+
resourceType: services.ses,
136+
relation: 'child',
137+
field: 'ses',
138+
})
139+
}
140+
}
141+
142+
/**
143+
* Find SNS caller
144+
* related to this cognito user pool
145+
*/
146+
const smsConfigSnsCallerArn = smsConfiguration?.SnsCallerArn
147+
const iamRoles = data.find(({ name }) => name === services.iamRole)
148+
149+
if (smsConfigSnsCallerArn && iamRoles?.data?.[region]) {
150+
const iamRoleInRegion: RawAwsIamRole = iamRoles.data[region].find(
151+
({ Arn }: RawAwsIamRole) => smsConfigSnsCallerArn === Arn
152+
)
153+
154+
if (iamRoleInRegion) {
155+
connections.push({
156+
id: iamRoleInRegion.Arn,
157+
resourceType: services.iamRole,
158+
relation: 'child',
159+
field: 'iamRole',
160+
})
161+
}
162+
}
55163

56164
const userPoolResult = {
57165
[id]: connections,
58166
}
59167
return userPoolResult
60-
}
168+
}

src/services/cognitoUserPool/schema.graphql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ type awsCognitoUserPool implements awsBaseService @key(fields: "id") {
119119
usernameConfigurationCaseSensitive: String @search(by: [hash, regexp])
120120
accountRecoverySettings: [awsAccountRecoverySetting]
121121
tags: [awsRawTag]
122-
lambda: [awsLambda] @hasInverse(field: cognitoUserPool) #change to plural
122+
lambdas: [awsLambda] @hasInverse(field: cognitoUserPools)
123123
appSync: [awsAppSync] @hasInverse(field: cognitoUserPool)
124-
}
125-
126-
# TODO: add connetion to kms
127-
# TODO: add connection to iamRole using SmsConfiguration.SnsCallerArn
124+
kms: [awsKms] @hasInverse(field: cognitoUserPools)
125+
ses: [awsSes] @hasInverse(field: cognitoUserPools)
126+
iamRole: [awsIamRole] @hasInverse(field: cognitoUserPools)
127+
}

src/services/iamRole/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ type awsIamRole implements awsBaseService @key(fields: "id") {
2323
@hasInverse(field: iamRole)
2424
iamInstanceProfiles: [awsIamInstanceProfile] @hasInverse(field: iamRole)
2525
ec2Instances: [awsEc2] @hasInverse(field: iamRole)
26+
cognitoUserPools: [awsCognitoUserPool] @hasInverse(field: iamRole)
2627
}

src/services/kms/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ type awsKms implements awsBaseService @key(fields: "id") {
2828
sageMakerNotebookInstances: [awsSageMakerNotebookInstance]
2929
@hasInverse(field: kms)
3030
rdsClusterSnapshots: [awsRdsClusterSnapshot] @hasInverse(field: kms)
31+
cognitoUserPools: [awsCognitoUserPool] @hasInverse(field: kms)
3132
}

src/services/lambda/schema.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type awsLambda implements awsBaseService @key(fields: "arn") {
2020
securityGroups: [awsSecurityGroup] @hasInverse(field: lambda)
2121
subnet: [awsSubnet] @hasInverse(field: lambda) #change to plural
2222
vpc: [awsVpc] @hasInverse(field: lambda)
23-
cognitoUserPool: [awsCognitoUserPool] @hasInverse(field: lambda) #change to plural
23+
cognitoUserPools: [awsCognitoUserPool] @hasInverse(field: lambdas)
2424
appSync: [awsAppSync] @hasInverse(field: lambda)
2525
}
2626

src/services/ses/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
type awsSes implements awsBaseService @key(fields: "arn") {
22
email: String @search(by: [hash, regexp])
33
verificationStatus: String @search(by: [hash, regexp])
4+
cognitoUserPools: [awsCognitoUserPool] @hasInverse(field: ses)
45
}

0 commit comments

Comments
 (0)