Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(secretsmanager): API cleanups #2908

Merged
merged 2 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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