Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit 0ab68db

Browse files
Fail the plugin if no secrets were specified
Signed-off-by: Christopher Maier <[email protected]>
1 parent 1c8d6b5 commit 0ab68db

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

hooks/environment

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ if [[ -n "${secret_prefix}" && ! "${secret_prefix}" =~ /$ ]]; then
4545
fi
4646
readonly secret_prefix
4747

48+
# Resolve secrets
4849
########################################################################
4950

50-
readonly container_name="vault-env-plugin-${BUILDKITE_JOB_ID}"
51-
5251
# STOLEN FROM https://github.com/buildkite-plugins/docker-buildkite-plugin/blob/9f90d8ef742d9fa1eb3556720e16f2b842ff1cb2/hooks/command#L25-L47
5352
#
5453
# Reads a list from plugin config into a global result array
@@ -74,14 +73,22 @@ plugin_read_list_into_result() {
7473
[[ ${#result[@]} -gt 0 ]] || return 1
7574
}
7675

77-
envconsul_env() {
78-
# This populates a `result` array for later use
79-
plugin_read_list_into_result BUILDKITE_PLUGIN_VAULT_ENV_SECRETS
76+
secrets=()
77+
if plugin_read_list_into_result BUILDKITE_PLUGIN_VAULT_ENV_SECRETS; then
78+
secrets=("${result[@]}")
79+
else
80+
raise_error "At least one secret must be specified!"
81+
fi
8082

81-
secrets=()
82-
for secret in "${result[@]}"; do
83+
########################################################################
84+
85+
readonly container_name="vault-env-plugin-${BUILDKITE_JOB_ID}"
86+
87+
envconsul_env() {
88+
args=()
89+
for secret in "${secrets[@]}"; do
8390
# secret_prefix is guaranteed to end with a / if it is non-empty
84-
secrets+=("-secret=${secret_prefix}${secret}")
91+
args+=("-secret=${secret_prefix}${secret}")
8592
done
8693

8794
# Explicitly *not* using `--rm` so we can output the container
@@ -91,7 +98,7 @@ envconsul_env() {
9198
--name="${container_name}" \
9299
-- \
93100
"${image}" \
94-
"${secrets[@]}" \
101+
"${args[@]}" \
95102
-once \
96103
-upcase \
97104
-pristine \

0 commit comments

Comments
 (0)