Skip to content

Commit

Permalink
feat(redshift): expose user.secret as property (aws#17520)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed-Hussein93 committed Apr 25, 2022
1 parent 40a6ceb commit 65adf18
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-redshift/lib/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as kms from '@aws-cdk/aws-kms';
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
import * as cdk from '@aws-cdk/core';
import { Construct } from 'constructs';
import { ICluster } from './cluster';
Expand Down Expand Up @@ -137,6 +138,12 @@ export class User extends UserBase {
readonly databaseName: string;
protected databaseProps: DatabaseOptions;

/**
* the Secrets Manager secret of the user.
* @attribute
*/
public readonly secret: secretsmanager.ISecret;

private resource: DatabaseQuery<UserHandlerProps>;

constructor(scope: Construct, id: string, props: UserProps) {
Expand Down Expand Up @@ -165,6 +172,7 @@ export class User extends UserBase {
attachedSecret.grantRead(this.resource);

this.username = this.resource.getAttString('username');
this.secret = secret;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-redshift/test/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ describe('cluster user', () => {
});
});

it('secret property is exposed', () => {
const user = new redshift.User(stack, 'User', databaseOptions);

expect(stack.resolve(user.secret.secretArn)).toStrictEqual({
Ref: 'UserSecretE2C04A69',
});
});

it('uses username when provided', () => {
const username = 'username';

Expand Down

0 comments on commit 65adf18

Please sign in to comment.