Skip to content

Commit

Permalink
Optionally decrypt helm secrets in a temporary directory
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke committed Apr 26, 2020
1 parent 223d894 commit 78a3a63
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 6 additions & 1 deletion scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -eu
# The suffix to use for decrypted files. The default can be overridden using
# the HELM_SECRETS_DEC_SUFFIX environment variable.
DEC_SUFFIX="${HELM_SECRETS_DEC_SUFFIX:-.yaml.dec}"
DEC_DIR="${HELM_SECRETS_DEC_DIR:-}"

# Make sure HELM_BIN is set (normally by the helm command)
HELM_BIN="${HELM_BIN:-helm}"
Expand Down Expand Up @@ -148,7 +149,11 @@ is_file_encrypted() {
}

file_dec_name() {
echo "$(dirname "${1}")/$(basename "${1}" ".yaml")${DEC_SUFFIX}"
if [ "${DEC_DIR}" != "" ]; then
echo "${DEC_DIR}/$(basename "${1}" ".yaml")${DEC_SUFFIX}"
else
echo "$(dirname "${1}")/$(basename "${1}" ".yaml")${DEC_SUFFIX}"
fi
}

encrypt_helper() {
Expand Down
19 changes: 18 additions & 1 deletion tests/2-dec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ load 'bats/extensions/bats-assert/load'
}

@test "dec: Decrypt assets/helm_vars/secrets.yaml with HELM_SECRETS_DEC_SUFFIX" {
export HELM_SECRETS_DEC_SUFFIX=.yaml.test
HELM_SECRETS_DEC_SUFFIX=.yaml.test
export HELM_SECRETS_DEC_SUFFIX

FILE=tests/assets/helm_vars/secrets.yaml

Expand All @@ -50,6 +51,22 @@ load 'bats/extensions/bats-assert/load'
assert_output 'global_secret: global_bar'
}

@test "dec: Decrypt assets/helm_vars/secrets.yaml with HELM_SECRETS_DEC_DIR" {
HELM_SECRETS_DEC_DIR="$(mktemp -d)"
export HELM_SECRETS_DEC_DIR

FILE=tests/assets/helm_vars/secrets.yaml

run helm secrets dec "${FILE}"
assert_success
assert_output "Decrypting ${FILE}"
assert [ -e "${HELM_SECRETS_DEC_DIR}/secrets.yaml.dec" ]

run cat "${HELM_SECRETS_DEC_DIR}/secrets.yaml.dec"
assert_success
assert_output 'global_secret: global_bar'
}

@test "dec: Decrypt assets/helm_vars/projectX/sandbox/us-east-1/java-app/secrets.yaml" {
FILE=tests/assets/helm_vars/projectX/sandbox/us-east-1/java-app/secrets.yaml

Expand Down

0 comments on commit 78a3a63

Please sign in to comment.