From 8109c924f5df1ac705df146d1efdb014d94f577f Mon Sep 17 00:00:00 2001 From: "George L. Yermulnik" Date: Sat, 23 Mar 2024 01:35:11 +0200 Subject: [PATCH 1/3] fix: Improve README and drop quotes from hook env vars --- README.md | 3 +-- hooks/_common.sh | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 87143321f..a4ddc245e 100644 --- a/README.md +++ b/README.md @@ -328,8 +328,7 @@ Config example: - 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 From eacd8a535f3f77e821e043dc12a88e79e996193c Mon Sep 17 00:00:00 2001 From: "George L. Yermulnik" Date: Mon, 25 Mar 2024 17:12:42 +0200 Subject: [PATCH 2/3] Add more details on how the env vars are exported --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index a4ddc245e..89c67188e 100644 --- a/README.md +++ b/README.md @@ -322,6 +322,12 @@ 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 behavior is the same as if values would've been wrapped into single quotes +> - The enclosing double quotes are removed if they are provided + Config example: ```yaml From d9f285b2b8af2a0867cc98a8a1552361acead6d2 Mon Sep 17 00:00:00 2001 From: "George L. Yermulnik" Date: Mon, 25 Mar 2024 22:22:55 +0200 Subject: [PATCH 3/3] Address PR review by dropping what may confuse users --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 89c67188e..346203435 100644 --- a/README.md +++ b/README.md @@ -325,7 +325,6 @@ 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 behavior is the same as if values would've been wrapped into single quotes > - The enclosing double quotes are removed if they are provided Config example: