Skip to content

Commit

Permalink
feat: adding groupEntityType inside CognitoUserPoolConfiguration (#105)
Browse files Browse the repository at this point in the history
Fixes #103
  • Loading branch information
reste85 authored May 10, 2024
1 parent ef81397 commit e69080c
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 21 deletions.
55 changes: 55 additions & 0 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,16 @@ const policyStore = new PolicyStore(scope, "PolicyStore", {
schema: cedarSchema,
validationSettings: validationSettingsStrict,
});
const cognitoGroupEntityType = 'test';
const userPool = new UserPool(scope, "UserPool"); // Creating a new Cognito UserPool
new IdentitySource(scope, "IdentitySource", {
configuration: {
cognitoUserPoolConfiguration: {
clientIds: ["&ExampleCogClientId;"],
userPool: userPool,
groupConfiguration: {
groupEntityType: cognitoGroupEntityType,
},
},
},
policyStore: policyStore,
Expand Down
23 changes: 23 additions & 0 deletions src/identity-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { ArnFormat, IResource, Lazy, Resource, Stack } from 'aws-cdk-lib/core';
import { Construct } from 'constructs';
import { IPolicyStore } from './policy-store';

export interface CognitoGroupConfiguration {

/**
* The name of the schema entity type that's mapped to the user pool group
*/
readonly groupEntityType: string;
}

export interface CognitoUserPoolConfiguration {
/**
* Client identifiers.
Expand All @@ -12,6 +20,13 @@ export interface CognitoUserPoolConfiguration {
*/
readonly clientIds?: string[];

/**
* Cognito Group Configuration
*
* @default - no Cognito Group configuration provided
*/
readonly groupConfiguration?: CognitoGroupConfiguration;

/**
* Cognito User Pool.
*
Expand Down Expand Up @@ -194,6 +209,7 @@ export class IdentitySource extends IdentitySourceBase {
readonly identitySourceId: string;
readonly openIdIssuer: string;
readonly userPoolArn: string;
readonly cognitoGroupEntityType?: string;
readonly policyStore: IPolicyStore;

constructor(scope: Construct, id: string, props: IdentitySourceProps) {
Expand All @@ -203,11 +219,17 @@ export class IdentitySource extends IdentitySourceBase {
props.configuration.cognitoUserPoolConfiguration.clientIds ?? [];
this.userPoolArn =
props.configuration.cognitoUserPoolConfiguration.userPool.userPoolArn;
const cognitoGroupConfiguration = props.configuration.cognitoUserPoolConfiguration.groupConfiguration?.groupEntityType
? {
groupEntityType: props.configuration.cognitoUserPoolConfiguration.groupConfiguration.groupEntityType,
}
: undefined;
this.identitySource = new CfnIdentitySource(this, id, {
configuration: {
cognitoUserPoolConfiguration: {
clientIds: Lazy.list({ produce: () => this.clientIds }),
userPoolArn: this.userPoolArn,
groupConfiguration: cognitoGroupConfiguration,
},
},
policyStoreId: props.policyStore.policyStoreId,
Expand All @@ -222,6 +244,7 @@ export class IdentitySource extends IdentitySourceBase {
});
this.openIdIssuer = this.identitySource.attrDetailsOpenIdIssuer;
this.policyStore = props.policyStore;
this.cognitoGroupEntityType = cognitoGroupConfiguration?.groupEntityType;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions test/identity-source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('Identity Source creation', () => {
mode: ValidationSettingsMode.OFF,
},
});
const cognitoGroupEntityType = 'test';
const policyStoreLogicalId = getResourceLogicalId(policyStore, CfnPolicyStore);
new IdentitySource(stack, 'IdentitySource', {
configuration: {
Expand All @@ -67,6 +68,9 @@ describe('Identity Source creation', () => {
'&ExampleCogClientId;',
],
userPool: userPool,
groupConfiguration: {
groupEntityType: cognitoGroupEntityType,
},
},
},
policyStore: policyStore,
Expand All @@ -80,6 +84,9 @@ describe('Identity Source creation', () => {
ClientIds: [
'&ExampleCogClientId;',
],
GroupConfiguration: {
GroupEntityType: cognitoGroupEntityType,
},
UserPoolArn: {
'Fn::GetAtt': [
getResourceLogicalId(userPool, CfnUserPool),
Expand Down
4 changes: 4 additions & 0 deletions test/integ.deployIdentitySource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ class IdentitySourceStack extends Stack {
const userPoolClient = new UserPoolClient(this, 'UserPoolClient', {
userPool: userPool,
});
const cognitoGroupEntityType = 'test';
new IdentitySource(this, 'IdentitySource', {
configuration: {
cognitoUserPoolConfiguration: {
clientIds: [userPoolClient.userPoolClientId],
userPool: userPool,
groupConfiguration: {
groupEntityType: cognitoGroupEntityType,
},
},
},
policyStore: policyStore,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "36.0.0",
"files": {
"0c0a55914d7f66e80e058a13a6ff9089236bee2010108ac3376ede5142b173bc": {
"d312f2e3ef42d644ea9be02e5c38ace3e6adec32bf3e6f58045bc2ebbe2a88d2": {
"source": {
"path": "IdentitySourceStack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "0c0a55914d7f66e80e058a13a6ff9089236bee2010108ac3376ede5142b173bc.json",
"objectKey": "d312f2e3ef42d644ea9be02e5c38ace3e6adec32bf3e6f58045bc2ebbe2a88d2.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
"Ref": "UserPoolClient2F5918F7"
}
],
"GroupConfiguration": {
"GroupEntityType": "test"
},
"UserPoolArn": {
"Fn::GetAtt": [
"UserPool6BA7E5F2",
Expand Down
2 changes: 1 addition & 1 deletion test/integ.deployIdentitySource.ts.snapshot/integ.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"IdentitySourceStack"
],
"regions": [
"${Token[AWS.Region.13]}"
"${Token[AWS.Region.11]}"
],
"cdkCommandOptions": {
"destroy": {
Expand Down
2 changes: 1 addition & 1 deletion test/integ.deployIdentitySource.ts.snapshot/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/0c0a55914d7f66e80e058a13a6ff9089236bee2010108ac3376ede5142b173bc.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/d312f2e3ef42d644ea9be02e5c38ace3e6adec32bf3e6f58045bc2ebbe2a88d2.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down
Loading

0 comments on commit e69080c

Please sign in to comment.