Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve README and drop quotes from hook env vars #651

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,19 @@ 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
yermulnik marked this conversation as resolved.
Show resolved Hide resolved
> - 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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, I found out why that functional was implemented - #116

No idea if is it worth highlighting such hack option in docs examples :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The options is nice I reckon. And the PR was not about it but to remove insecure example =)

```

### All hooks: Disable color output
Expand Down
5 changes: 5 additions & 0 deletions hooks/_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
yermulnik marked this conversation as resolved.
Show resolved Hide resolved
var_value="${var_value#\"}"
var_value="${var_value%\"}"
fi
# shellcheck disable=SC2086
export $var_name="$var_value"
done
Expand Down