Pass --projectId if INFISICAL_PROJECT_ID env is present

This commit is contained in:
2025-06-02 00:53:20 +02:00
parent 2de61ffd1b
commit 9de315bd7b

View File

@@ -16,12 +16,19 @@ fetch_secret() {
local target_secret="${1:?Target secret local_secret is required}"
local env="${2:?Environment is required}"
local output_file="${3:?}"
declare -a args
if [[ -n "${INFISICAL_PROJECT_ID:-}" ]]; then
args+=("--projectId" "${INFISICAL_PROJECT_ID}")
fi
args+=("secrets" "--plain" "get" "${target_secret}" "--env" "${env}")
if command -v infisical-dcli &>/dev/null; then
# If infisical CLI command is available, use it directly
infisical-dcli secrets --plain get "${target_secret}" --env "${env}" >"${output_file}"
infisical-dcli "${args[@]}" >"${output_file}"
else
if ! dc_infisical secrets --plain get "${target_secret}" --env "${env}" >"${output_file}"; then
if ! dc_infisical "${args[@]}" >"${output_file}"; then
rm -f "${output_file}" # Clean up if fetch failed
return 1
fi