Compare commits

...

5 Commits

View File

@@ -1,5 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail
fetch_secret() {
local target_secret="${1:?Target secret local_secret is required}"
local env="${2:?Environment is required}"
@@ -46,16 +48,22 @@ main() {
env="$(jq -r .env <<<"${obj}")"
filename="$(jq -r .filename <<<"${obj}")"
if [[ ${local_secret} == "null" || ${target_secret} == "null" ]]; then
printf "Error: Missing required fields in entry: %s\n" "${obj}" >&2
continue
fi
# Default output file name
output_file="${secrets_dir}/${output_file}"
output_file="${secrets_dir}/${local_secret}"
# If filename is specified in json, use it; otherwise, use the local_secret as the filename
if [[ -n ${filename} && ${filename} != "null" ]]; then
output_file="${secrets_dir}/${filename}"
fi
if [[ -z ${env} ]]; then
printf "Warning: Environment not specified for secret %s, assuming 'prod'\n" "${local_secret}" >&2
if [[ ${env} == "null" ]]; then
printf "Warning: Environment not specified for secret %s, assuming 'dev'\n" "${local_secret}" >&2
env="dev"
fi
printf "Processing %s -> %s (%s)\n" "${local_secret}" "${target_secret}" "${env}"