Files
carmanagement/scripts/describe-env-values.sh
T
root d6fcb52941
Build & Push / Pipeline Tests (push) Successful in 1m49s
Test / Type Check (all packages) (push) Successful in 53s
Build & Push / Build & Push Docker Image (push) Failing after 33s
Test / API Unit Tests (push) Successful in 1m9s
Test / Homepage Unit Tests (push) Successful in 50s
Test / Carplace Unit Tests (push) Successful in 44s
Test / Admin Unit Tests (push) Successful in 43s
Test / Dashboard Unit Tests (push) Successful in 47s
Test / API Integration Tests (push) Successful in 1m8s
stripe build fix
2026-07-29 18:46:14 -04:00

87 lines
2.2 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'EOF'
Usage:
describe-env-values.sh <env-file> <KEY> [KEY...]
Prints a non-secret status for each requested key in <env-file>.
EOF
}
if [[ $# -lt 2 ]]; then
usage >&2
exit 1
fi
env_file="$1"
shift
if [[ ! -f "${env_file}" ]]; then
echo "Missing env file: ${env_file}" >&2
exit 1
fi
read_env_value() {
local key="$1"
local value
value="$(
awk -F= -v key="${key}" '
/^[[:space:]]*#/ || index($0, "=") == 0 {
next
}
{
name = $1
sub(/^[[:space:]]*export[[:space:]]+/, "", name)
gsub(/^[[:space:]]+|[[:space:]]+$/, "", name)
if (name == key) {
value = substr($0, index($0, "=") + 1)
}
}
END {
print value
}
' "${env_file}"
)"
value="${value%$'\r'}"
value="${value#"${value%%[![:space:]]*}"}"
value="${value%"${value##*[![:space:]]}"}"
if [[ "${value}" == \"*\" && "${value}" == *\" ]]; then
value="${value#\"}"
value="${value%\"}"
elif [[ "${value}" == \'*\' && "${value}" == *\' ]]; then
value="${value#\'}"
value="${value%\'}"
fi
printf '%s' "${value}"
}
describe_value() {
local key="$1"
local value="$2"
if [[ -z "${value}" ]]; then
printf '%s: missing\n' "${key}"
elif [[ "${value}" == placeholder || "${value}" == replace-with-* || "${value}" == *changeme* || "${value}" == *change-me* ]]; then
printf '%s: placeholder\n' "${key}"
elif [[ "${key}" == STRIPE_BILLING_REQUIRED && ( "${value}" == "true" || "${value}" == "1" || "${value}" == "yes" ) ]]; then
printf '%s: enabled\n' "${key}"
elif [[ "${key}" == STRIPE_BILLING_REQUIRED && ( "${value}" == "false" || "${value}" == "0" || "${value}" == "no" ) ]]; then
printf '%s: disabled\n' "${key}"
elif [[ "${key}" == STRIPE_API_KEY && ( "${value}" == sk_live_* || "${value}" == rk_live_* ) ]]; then
printf '%s: valid live prefix\n' "${key}"
elif [[ "${key}" == STRIPE_WEBHOOK_SECRET && "${value}" == whsec_* ]]; then
printf '%s: valid webhook prefix\n' "${key}"
else
printf '%s: invalid prefix\n' "${key}"
fi
}
for key in "$@"; do
describe_value "${key}" "$(read_env_value "${key}")"
done