From 9eebd05bbc5b29742eb466d1e1517eef8d6ec4bb Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Wed, 10 Oct 2018 14:18:18 +0200 Subject: [PATCH] feat(cdk): configurable default SSM context provider (#889) This feature is going to be used by the ECS constructs. --- packages/@aws-cdk/cdk/lib/context.ts | 4 ++-- packages/@aws-cdk/cdk/test/test.context.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/cdk/lib/context.ts b/packages/@aws-cdk/cdk/lib/context.ts index 3c17890b6e129..e63e6aa58d201 100644 --- a/packages/@aws-cdk/cdk/lib/context.ts +++ b/packages/@aws-cdk/cdk/lib/context.ts @@ -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); } } diff --git a/packages/@aws-cdk/cdk/test/test.context.ts b/packages/@aws-cdk/cdk/test/test.context.ts index a3c6ab46d148c..d1acdf1ab3688 100644 --- a/packages/@aws-cdk/cdk/test/test.context.ts +++ b/packages/@aws-cdk/cdk/test/test.context.ts @@ -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');