From f7dcac14bc972045f4d9202143b8981f9c46dffe Mon Sep 17 00:00:00 2001 From: Kikuo Emoto Date: Wed, 11 Oct 2023 22:18:58 +0900 Subject: [PATCH] feat(cdk): add OpenAI API key param - `SystemParameters` introduces a new parameter `openAiApiKeyParameter` that stores the OpenAI API key. - `ViewerHandler` is granted access to the OpenAI API key parameter. - `CdkStack` outputs the parameter path of the OpenAI API key as `OpenAiApiKeyParameterPath`. issue codemonger-io/mumble#26 --- cdk/lib/cdk-stack.ts | 4 ++++ cdk/lib/system-parameters.ts | 5 +++++ cdk/lib/viewer.ts | 1 + 3 files changed, 10 insertions(+) diff --git a/cdk/lib/cdk-stack.ts b/cdk/lib/cdk-stack.ts index ba03e3d..af58db8 100644 --- a/cdk/lib/cdk-stack.ts +++ b/cdk/lib/cdk-stack.ts @@ -130,5 +130,9 @@ export class CdkStack extends Stack { description: 'Path to the domain name stored in Parameter Store on AWS Systems Manager', value: systemParameters.domainNameParameter.parameterName, }); + new CfnOutput(this, 'OpenAiApiKeyParameterPath', { + description: 'Path to the OpenAI API key stored in Parameter Store on AWS Systems Manager', + value: systemParameters.openAiApiKeyParameter.parameterName, + }); } } diff --git a/cdk/lib/system-parameters.ts b/cdk/lib/system-parameters.ts index 846cdad..e929001 100644 --- a/cdk/lib/system-parameters.ts +++ b/cdk/lib/system-parameters.ts @@ -9,6 +9,8 @@ export class SystemParameters extends Construct { readonly parameterPathPrefix: string; /** Parameter for the domain name. */ readonly domainNameParameter: GhostStringParameter; + /** Parameter for the OpenAI API key. */ + readonly openAiApiKeyParameter: GhostStringParameter; constructor(scope: Construct, id: string) { super(scope, id); @@ -18,5 +20,8 @@ export class SystemParameters extends Construct { this.domainNameParameter = new GhostStringParameter(this, { parameterName: `${this.parameterPathPrefix}DOMAIN_NAME`, }); + this.openAiApiKeyParameter = new GhostStringParameter(this, { + parameterName: `${this.parameterPathPrefix}OPENAI_API_KEY`, + }); } } diff --git a/cdk/lib/viewer.ts b/cdk/lib/viewer.ts index dd90654..94de5c0 100644 --- a/cdk/lib/viewer.ts +++ b/cdk/lib/viewer.ts @@ -54,6 +54,7 @@ export class Viewer extends Construct { objectStore.objectsBucket.grantRead(this.handler); objectStore.objectTable.grantReadData(this.handler); systemParameters.domainNameParameter.grantRead(this.handler); + systemParameters.openAiApiKeyParameter.grantRead(this.handler); userTable.userTable.grantReadData(this.handler); this.functionUrl = this.handler.addFunctionUrl({