From 552ba26dc7ad6638db5b24305091cfec7241089f Mon Sep 17 00:00:00 2001 From: Samuel Liu <143571692+sliu526@users.noreply.github.com> Date: Mon, 8 Jan 2024 20:00:42 -0500 Subject: [PATCH] fixed region for retrieving frontend env secret (#14) * fixed region for retrieving frontend env secret * edited build-frontend-env code to parse through key:value representation of AWS secret * fixed minor code cleanliness issues --------- Co-authored-by: Samuel Liu --- .../build_frontend_env/build-frontend-env-file.go | 14 ++++++++++++-- cmd/frontend/frontend.go | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/frontend/build_frontend_env/build-frontend-env-file.go b/cmd/frontend/build_frontend_env/build-frontend-env-file.go index 64b537a..72e0cd3 100644 --- a/cmd/frontend/build_frontend_env/build-frontend-env-file.go +++ b/cmd/frontend/build_frontend_env/build-frontend-env-file.go @@ -13,6 +13,7 @@ import ( "github.com/spf13/cobra" "github.com/DSGT-DLP/Deep-Learning-Playground/cli/cmd/frontend" // For frontend/ "github.com/DSGT-DLP/Deep-Learning-Playground/cli/utils" // For utils/ + "encoding/json" ) var secretName string // Name of the secret in AWS Secrets Manager @@ -33,9 +34,18 @@ var buildFrontendEnvCmd = &cobra.Command{ } path := "./frontend" + + // AWS secrets are parsed from key:value pairs in secrets manager for populating the .env file - // Adding secrets to the .env file - utils.WriteToEnvFile(secretName, *secretValue.SecretString, path) + var secretsMap map[string]string + + if err := json.Unmarshal([]byte(*secretValue.SecretString), &secretsMap); err != nil { + log.Fatal("error unmarshalling json: ", err) + } + + for key,value := range secretsMap { + utils.WriteToEnvFile(key, value, path) + } // Hardcoding bucket name as a constant utils.WriteToEnvFile("BUCKET_NAME", utils.DlpUploadBucket, path) diff --git a/cmd/frontend/frontend.go b/cmd/frontend/frontend.go index 2dc6f9d..eb811db 100644 --- a/cmd/frontend/frontend.go +++ b/cmd/frontend/frontend.go @@ -9,7 +9,7 @@ import ( ) const FrontendDir string = "./frontend" -const AwsRegion = "us-west-2" +const AwsRegion = "us-east-1" // FrontendCmd represents the frontend command var FrontendCmd = &cobra.Command{