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

feat: Add __GIT_WORKING_DIR__ to terraform_checkov #399

Merged
merged 2 commits into from
Jun 27, 2022
Merged

feat: Add __GIT_WORKING_DIR__ to terraform_checkov #399

merged 2 commits into from
Jun 27, 2022

Conversation

ouranos
Copy link
Contributor

@ouranos ouranos commented Jun 15, 2022

Put an x into the box if that apply:

  • This PR introduces breaking change.
  • This PR fixes a bug.
  • This PR adds new functionality.
  • This PR enhances existing functionality.

Description of your changes

This PR adds support for __GIT_WORKING_DIR__ to the new terraform_checkov hook.

Since the new hook cd into each directory, it now ignores the checkov.yml file in the root folder. The functionality can now be restored with:

- id: terraform_checkov
  args:
    - --args=--config-file __GIT_WORKING_DIR__/.checkov.yml

How can we test changes

  1. Create a checkov.yml in the top directory
  2. Commit something that will trigger terraform_checkov in a subdirectory:
    • the config file is ignored
  3. Add --args=--config-file __GIT_WORKING_DIR__/.checkov.yml to the .pre-commit-config.yaml file
  4. Commit something that will trigger terraform_checkov in a subdirectory
    • the config file is now taken into account

@ouranos ouranos changed the title Add __GIT_WORKING_DIR__ to terraform_checkov feat: Add __GIT_WORKING_DIR__ to terraform_checkov Jun 15, 2022
Copy link
Collaborator

@MaxymVlasov MaxymVlasov left a comment

Choose a reason for hiding this comment

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

Please, add related documentation to the readme (You can copy-paste related to __GIT_WORKING_DIR__ doc from tfsec and little-bit change it)

Comment on lines 20 to 22
# shellcheck disable=SC2128 # It's the simplest syntax for that case
# shellcheck disable=SC2153 # False positive
common::per_dir_hook "${ARGS[*]}" "$HOOK_ID" "${FILES[@]}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's maintain one style across the codebase. Also, no need to expand ARGS to an array

Suggested change
# shellcheck disable=SC2128 # It's the simplest syntax for that case
# shellcheck disable=SC2153 # False positive
common::per_dir_hook "${ARGS[*]}" "$HOOK_ID" "${FILES[@]}"
# shellcheck disable=SC2128 # It's the simplest syntax for that case
common::per_dir_hook "$ARGS" "$HOOK_ID" "${FILES[@]}"

# Support for setting PATH to repo root.
# shellcheck disable=SC2178 # It's the simplest syntax for that case
ARGS=${ARGS[*]/__GIT_WORKING_DIR__/$(pwd)\/}
# shellcheck disable=SC2128 # It's the simplest syntax for that case
common::per_dir_hook "$ARGS" "$HOOK_ID" "${FILES[@]}"

@ouranos
Copy link
Contributor Author

ouranos commented Jun 27, 2022

@MaxymVlasov are you happy with these changes or would you like me to do anything else?

@MaxymVlasov MaxymVlasov requested a review from antonbabenko June 27, 2022 14:48
@antonbabenko antonbabenko merged commit ae88ed7 into antonbabenko:master Jun 27, 2022
antonbabenko pushed a commit that referenced this pull request Jun 27, 2022
# [1.73.0](v1.72.2...v1.73.0) (2022-06-27)

### Features

* Add __GIT_WORKING_DIR__ to terraform_checkov ([#399](#399)) ([ae88ed7](ae88ed7))
@antonbabenko
Copy link
Owner

This PR is included in version 1.73.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants