chore: Improved code structure (moved hooks into a separate dir) (#316)

This commit is contained in:
Maksym Vlasov 2022-01-06 17:09:51 +02:00 committed by GitHub
commit c5f2a618a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 1066 additions and 1591 deletions

34
hooks/terraform_tfsec.sh Executable file
View file

@ -0,0 +1,34 @@
#!/usr/bin/env bash
set -eo pipefail
# shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines
readonly SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
# shellcheck source=_common.sh
. "$SCRIPT_DIR/_common.sh"
function main {
common::initialize "$SCRIPT_DIR"
common::parse_cmdline "$@"
# 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" "${FILES[@]}"
}
function per_dir_hook_unique_part {
# common logic located in common::per_dir_hook
local -r args="$1"
# shellcheck disable=SC2034 # Unused var.
local -r dir_path="$2"
# pass the arguments to hook
# shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]")
tfsec ${args[@]}
# return exit code to common::per_dir_hook
local exit_code=$?
return $exit_code
}
[ "${BASH_SOURCE[0]}" != "$0" ] || main "$@"