Skip to content

Commit

Permalink
refactor(secretsmanager): API cleanups (#2908)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `ISecret.secretJsonValue` renamed to `secretValueFromJson`.
  • Loading branch information
Elad Ben-Israel authored Jun 18, 2019
1 parent bd1bcf5 commit 60f46c8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-rds/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ export class DatabaseCluster extends DatabaseClusterBase {
port: props.port,
dbClusterParameterGroupName: props.parameterGroup && props.parameterGroup.parameterGroupName,
// Admin
masterUsername: secret ? secret.secretJsonValue('username').toString() : props.masterUser.username,
masterUsername: secret ? secret.secretValueFromJson('username').toString() : props.masterUser.username,
masterUserPassword: secret
? secret.secretJsonValue('password').toString()
? secret.secretValueFromJson('password').toString()
: (props.masterUser.password
? props.masterUser.password.toString()
: undefined),
Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-rds/lib/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,9 +724,9 @@ export class DatabaseInstance extends DatabaseInstanceSource implements IDatabas
...this.sourceCfnProps,
characterSetName: props.characterSetName,
kmsKeyId: props.kmsKey && props.kmsKey.keyArn,
masterUsername: secret ? secret.secretJsonValue('username').toString() : props.masterUsername,
masterUsername: secret ? secret.secretValueFromJson('username').toString() : props.masterUsername,
masterUserPassword: secret
? secret.secretJsonValue('password').toString()
? secret.secretValueFromJson('password').toString()
: (props.masterUserPassword
? props.masterUserPassword.toString()
: undefined),
Expand Down Expand Up @@ -819,9 +819,9 @@ export class DatabaseInstanceFromSnapshot extends DatabaseInstanceSource impleme
const instance = new CfnDBInstance(this, 'Resource', {
...this.sourceCfnProps,
dbSnapshotIdentifier: props.snapshotIdentifier,
masterUsername: secret ? secret.secretJsonValue('username').toString() : props.masterUsername,
masterUsername: secret ? secret.secretValueFromJson('username').toString() : props.masterUsername,
masterUserPassword: secret
? secret.secretJsonValue('password').toString()
? secret.secretValueFromJson('password').toString()
: (props.masterUserPassword
? props.masterUserPassword.toString()
: undefined),
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-secretsmanager/lib/secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface ISecret extends IResource {
/**
* Interpret the secret as a JSON object and return a field's value from it as a `SecretValue`.
*/
secretJsonValue(key: string): SecretValue;
secretValueFromJson(key: string): SecretValue;

/**
* Grants reading the secret value to some role.
Expand Down Expand Up @@ -129,10 +129,10 @@ abstract class SecretBase extends Resource implements ISecret {
}

public get secretValue() {
return this.secretJsonValue('');
return this.secretValueFromJson('');
}

public secretJsonValue(jsonField: string) {
public secretValueFromJson(jsonField: string) {
return SecretValue.secretsManager(this.secretArn, { jsonField });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ExampleStack extends cdk.Stack {
new iam.User(this, 'User', {
// Get the 'password' field from the secret that looks like
// { "username": "XXXX", "password": "YYYY" }
password: loginSecret.secretJsonValue('password')
password: loginSecret.secretValueFromJson('password')
});
/// !hide

Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-secretsmanager/test/integ.secret.lit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class SecretsManagerStack extends cdk.Stack {
});

new iam.User(this, 'OtherUser', {
userName: templatedSecret.secretJsonValue('username').toString(),
password: templatedSecret.secretJsonValue('password')
userName: templatedSecret.secretValueFromJson('username').toString(),
password: templatedSecret.secretValueFromJson('password')
});
/// !hide
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-secretsmanager/test/test.secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ export = {
test.equals(secret.secretArn, secretArn);
test.same(secret.encryptionKey, encryptionKey);
test.deepEqual(stack.resolve(secret.secretValue), '{{resolve:secretsmanager:arn::of::a::secret:SecretString:::}}');
test.deepEqual(stack.resolve(secret.secretJsonValue('password')), '{{resolve:secretsmanager:arn::of::a::secret:SecretString:password::}}');
test.deepEqual(stack.resolve(secret.secretValueFromJson('password')), '{{resolve:secretsmanager:arn::of::a::secret:SecretString:password::}}');
test.done();
},

Expand Down Expand Up @@ -399,7 +399,7 @@ export = {
const stack = new Stack();

// WHEN
const imported = secretsmanager.Secret.fromSecretAttributes(stack, 'Imported', { secretArn: 'my-secret-arn' }).secretJsonValue('password');
const imported = secretsmanager.Secret.fromSecretAttributes(stack, 'Imported', { secretArn: 'my-secret-arn' }).secretValueFromJson('password');
const value = SecretValue.secretsManager('my-secret-arn', { jsonField: 'password' });

// THEN
Expand Down

0 comments on commit 60f46c8

Please sign in to comment.