From 0da438d46bd6623c7224315b6021b44b19d6d4ac Mon Sep 17 00:00:00 2001 From: Liz/Alice Cray Date: Fri, 4 Oct 2024 19:41:54 -0400 Subject: [PATCH] Fixed secret access + return state --- index.mjs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/index.mjs b/index.mjs index 0f43b06..f03b9ab 100644 --- a/index.mjs +++ b/index.mjs @@ -14,6 +14,8 @@ export const handler = async (event) => { keyResponse = await keyClient.send(new GetSecretValueCommand({ SecretId: process.env.TRIGGER_SECRET })); + keyResponse = JSON.parse(keyResponse.SecretString); + keyResponse = keyResponse["carbon-key"].replaceAll(" ", "\n"); } catch (err) { console.warn(err); result = err; @@ -32,6 +34,14 @@ export const handler = async (event) => { stream.on('close', (code, signal) => { // COMPLETE console.info("Trigger completed", code, signal) + result = code; + const response = { + statusCode: 200, + body: { + result + }, + }; + return response; }).stderr.on('data', (data) => { // STDERR console.warn(data); @@ -41,15 +51,16 @@ export const handler = async (event) => { host: process.env.TRIGGER_HOST, port: 22, username: process.env.TRIGGER_USERNAME, - privateKey: keyResponse.SecretString + privateKey: keyResponse.SecretStrin, }); + }else{ + const response = { + statusCode: 200, + body: { + result + }, + }; + return response; } - const response = { - statusCode: 200, - body: { - result - }, - }; - return response; };