Skip to content

Commit

Permalink
feat(cdk): configurable default SSM context provider (#889)
Browse files Browse the repository at this point in the history
This feature is going to be used by the ECS constructs.
  • Loading branch information
rix0rrr authored Oct 10, 2018
1 parent 4a76287 commit 9eebd05
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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

0 comments on commit 9eebd05

Please sign in to comment.