Skip to content

Commit

Permalink
Fix .env generation with multiline, like private key
Browse files Browse the repository at this point in the history
  • Loading branch information
fagianijunior committed Apr 2, 2024
1 parent 4e16ecf commit ac822f8
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,13 @@ COMMIT_SHORT=$(head -c 8 <<<$CODEBUILD_RESOLVED_SOURCE_VERSION)
IMAGE_NAME=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REPO_SLUG-$BRANCH:$COMMIT_SHORT

main_application_secrets=$(aws secretsmanager get-secret-value --secret-id $BRANCH/$REPO_SLUG)
main_application_environment_variables=$(jq -r '.SecretString | fromjson | to_entries | .[] | .key + "=" + (.value|tostring)' <<<$main_application_secrets)
main_export_regex="^([A-Z0-9_])+[=]+(.*)"
for ENV_LINE in $main_application_environment_variables; do
if [[ $ENV_LINE =~ ${main_export_regex} ]]; then
export $ENV_LINE
echo $ENV_LINE >> .env
else
echo " SKIPPED: >> ${ENV_LINE}"
main_export_errors=true
fi
done
main_application_environment_variables=$(jq -r '.SecretString | fromjson | to_entries[] | "\(.key)=\(.value|tostring)"' <<<$main_application_secrets)

while IFS= read -r ENV_LINE; do
export "$ENV_LINE"
echo "$ENV_LINE" >> .env
done <<< "$main_application_environment_variables"


if [ ! -z "$main_export_errors" ]; then
echo " WARNING: The above noted environment variables were skipped from the export, as they were not identified as a valid value or by a flag."
Expand Down

0 comments on commit ac822f8

Please sign in to comment.