From 19fd9f4d833787215fec6eeebc8b3af06a06cd76 Mon Sep 17 00:00:00 2001 From: xZero707 Date: Sun, 1 Jun 2025 23:35:31 +0200 Subject: [PATCH] Use infisical cli directly, if available --- dist/scripts/src/fetch-secrets.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/dist/scripts/src/fetch-secrets.sh b/dist/scripts/src/fetch-secrets.sh index 017314d..eaf0ffd 100755 --- a/dist/scripts/src/fetch-secrets.sh +++ b/dist/scripts/src/fetch-secrets.sh @@ -5,9 +5,14 @@ fetch_secret() { local env="${2:?Environment is required}" local output_file="${3:?}" - script -q /dev/null \ - -c "docker compose run --rm -t cli infisical secrets --plain get ""${target_secret}"" --env ""${env}""" \ - >"${output_file}" + if command -v infisical &>/dev/null; then + # If infisical CLI command is available, use it directly + infisical secrets --plain get "${target_secret}" --env "${env}" >"${output_file}" + else + script -q /dev/null \ + -c "docker compose run --rm -t cli infisical secrets --plain get ""${target_secret}"" --env ""${env}""" \ + >"${output_file}" + fi # Check if file is empty if [[ ! -s ${output_file} ]]; then @@ -19,12 +24,12 @@ main() { local config_file="${1:-./secrets.json}" local secrets_dir="${2:-./secrets}" - if ! command -v jq &> /dev/null; then + if ! command -v jq &>/dev/null; then printf "Error: jq is required but not installed\n" >&2 return 1 fi - if [[ ! -f "${config_file}" ]]; then + if [[ ! -f ${config_file} ]]; then printf "Error: Config file %s not found\n" "${config_file}" >&2 return 1 fi @@ -45,11 +50,11 @@ main() { 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 + if [[ -n ${filename} && ${filename} != "null" ]]; then output_file="${secrets_dir}/${filename}" fi - if [[ -z "${env}" ]]; then + if [[ -z ${env} ]]; then printf "Warning: Environment not specified for secret %s, assuming 'prod'\n" "${local_secret}" >&2 fi