Make it possible to specify filename in secrets.json

This commit is contained in:
2025-05-29 21:02:23 +02:00
parent b6b68a2e69
commit dd7e167bf7

View File

@@ -33,13 +33,21 @@ main() {
mapfile -t entries < <(jq -c '.[]' "${config_file}") mapfile -t entries < <(jq -c '.[]' "${config_file}")
local local_secret target_secret env obj local local_secret target_secret filename env obj
for obj in "${entries[@]}"; do for obj in "${entries[@]}"; do
local_secret="$(jq -r .secret_name <<<"${obj}")" local_secret="$(jq -r .secret_name <<<"${obj}")"
target_secret="$(jq -r .target_secret <<<"${obj}")" target_secret="$(jq -r .target_secret <<<"${obj}")"
env="$(jq -r .env <<<"${obj}")" env="$(jq -r .env <<<"${obj}")"
output_file="${secrets_dir}/${local_secret}" filename="$(jq -r .filename <<<"${obj}")"
# Default output file name
output_file="${secrets_dir}/${output_file}"
# If filename is specified in json, use it; otherwise, use the local_secret as the filename
if [[ -n "${filename}" && "${filename}" != "null" ]]; then
output_file="${filename}"
fi
if [[ -z "${env}" ]]; then if [[ -z "${env}" ]]; then
printf "Warning: Environment not specified for secret %s, assuming 'prod'\n" "${local_secret}" >&2 printf "Warning: Environment not specified for secret %s, assuming 'prod'\n" "${local_secret}" >&2