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

feat(cdk): configurable default SSM context provider #889

Merged
merged 1 commit into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions packages/@aws-cdk/cdk/lib/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ export class SSMParameterProvider {
/**
* Return the SSM parameter string with the indicated key
*/
public getString(parameterName: string): any {
public getString(parameterName: string, defaultValue: string = "dummy"): any {
const scope = this.provider.accountRegionScope('SSMParameterProvider');
return this.provider.getStringValue(SSM_PARAMETER_PROVIDER, scope, [parameterName], 'dummy');
return this.provider.getStringValue(SSM_PARAMETER_PROVIDER, scope, [parameterName], defaultValue);
}
}

Expand Down
13 changes: 13 additions & 0 deletions packages/@aws-cdk/cdk/test/test.context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ export = {
test.done();
},

'SSM parameter provider has configurable default'(test: Test) {
// GIVEN
const stack = new Stack(undefined, 'TestStack', { env: { account: '12345', region: 'us-east-1' } });

// WHEN
const customizedDefault = new SSMParameterProvider(stack).getString('test', 'some-value');

// THEN
test.equals(customizedDefault, 'some-value');

test.done();
},

'Return default values if "env" is undefined to facilitate unit tests, but also expect metadata to include "error" messages'(test: Test) {
const app = new App();
const stack = new Stack(app, 'test-stack');
Expand Down