From 46abfae9ce42136bb2005d02357a9c78621b9068 Mon Sep 17 00:00:00 2001 From: cemanzano Date: Fri, 20 Sep 2024 13:51:15 -0700 Subject: [PATCH] fix: add dynamic key values to secrets.properties in idx template (#1814) * Add dynamic key values to secrets.properties in idx template Update idx template to read local.defaults.properties and generate key entries in secrets.properties file using the user's provided API key. * Fix incorrect variable for key Update key to be keyVar when writing to secrets.properties --- open-in-idx-template/idx-template.nix | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/open-in-idx-template/idx-template.nix b/open-in-idx-template/idx-template.nix index ed230f863..c9e17d1f4 100644 --- a/open-in-idx-template/idx-template.nix +++ b/open-in-idx-template/idx-template.nix @@ -14,9 +14,21 @@ chmod -R +w "$WS_NAME" mkdir -p "$WS_NAME/.idx/" - # Create a secrets.properties file in the repo and replace the MAPS_API_KEY property with said value + # Create a secrets.properties file in the repo touch $WS_NAME/secrets.properties - echo "MAPS_API_KEY=\"${apikey}\"" > $WS_NAME/secrets.properties + + # Create a secrets.properties variable for each key type in the + local.defaults.properties file + + while IFS= read -r line || [[ -n "$line" ]]; do + # Check that an "=" exists in the line + if [[ $line == *"="* ]]; then + # Extract the variable name + keyVar=$(echo "$line" | cut -d '=' -f 1) + # Define new variable in secrets file + echo "$keyVar=\"${apikey}\"" >> $WS_NAME/secrets.properties + fi + done < $WS_NAME/local.defaults.properties # We create a dev.nix that builds the subproject specified at template instantiation launch_activity=${launchactivity} j2 --format=env ${./devNix.j2} -o $WS_NAME/.idx/dev.nix