From daec6823f980ef0e9ac8675ed93b6861fcbe58cc Mon Sep 17 00:00:00 2001 From: "George L. Yermulnik" Date: Mon, 25 Mar 2024 22:26:19 +0200 Subject: [PATCH] fix: Improve README and drop quotes from hook env vars (#651) --- README.md | 8 ++++++-- hooks/_common.sh | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 87143321f..346203435 100644 --- a/README.md +++ b/README.md @@ -322,14 +322,18 @@ If for config above set up `export CONFIG_NAME=.tflint; export CONFIG_EXT=hcl` b You can specify environment variables that will be passed to the hook at runtime. +> [!IMPORTANT] +> Variable values are exported _verbatim_: +> - No interpolation or expansion are applied +> - The enclosing double quotes are removed if they are provided + Config example: ```yaml - id: terraform_validate args: - --env-vars=AWS_DEFAULT_REGION="us-west-2" - - --env-vars=AWS_ACCESS_KEY_ID="anaccesskey" - - --env-vars=AWS_SECRET_ACCESS_KEY="asecretkey" + - --env-vars=AWS_PROFILE="my-aws-cli-profile" ``` ### All hooks: Disable color output diff --git a/hooks/_common.sh b/hooks/_common.sh index e6d610af3..16c070c6c 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -527,6 +527,11 @@ function common::export_provided_env_vars { for var in "${env_vars[@]}"; do var_name="${var%%=*}" var_value="${var#*=}" + # Drop enclosing double quotes + if [[ $var_value =~ ^\" && $var_value =~ \"$ ]]; then + var_value="${var_value#\"}" + var_value="${var_value%\"}" + fi # shellcheck disable=SC2086 export $var_name="$var_value" done