fix(gitea): redirect log() calls to stderr in value-returning functions

log() writes to stdout, so log calls inside functions that return
values via printf/stdout contaminate the captured output.

gitea_helm_admin_token and gitea_ensure_password now redirect all
log() calls to stderr with >&2, keeping stdout clean for the
returned token/password string.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
chrisfu 2026-05-09 19:34:58 -07:00
parent 23e87f074c
commit cddd9c8889

View File

@ -825,7 +825,7 @@ gitea_ensure_password() {
local pw local pw
pw=$(op item get "$title" --vault="${GITEA_OP_VAULT}" --fields=password 2>/dev/null) || true pw=$(op item get "$title" --vault="${GITEA_OP_VAULT}" --fields=password 2>/dev/null) || true
if [[ -n "$pw" ]]; then if [[ -n "$pw" ]]; then
log " Gitea: retrieved existing credential for '${username}' from 1Password (vault: ${GITEA_OP_VAULT})" log " Gitea: retrieved existing credential for '${username}' from 1Password (vault: ${GITEA_OP_VAULT})" >&2
printf '%s' "$pw" printf '%s' "$pw"
return 0 return 0
fi fi
@ -833,7 +833,7 @@ gitea_ensure_password() {
# Generate and store a new credential in 1Password. # Generate and store a new credential in 1Password.
# --generate-password uses 1Password's generator — no plaintext secret # --generate-password uses 1Password's generator — no plaintext secret
# ever appears in the process environment or shell history. # ever appears in the process environment or shell history.
log " Gitea: generating credential for '${username}' → 1Password vault '${GITEA_OP_VAULT}'" log " Gitea: generating credential for '${username}' → 1Password vault '${GITEA_OP_VAULT}'" >&2
op item create \ op item create \
--category=Login \ --category=Login \
--title="$title" \ --title="$title" \
@ -849,7 +849,7 @@ gitea_ensure_password() {
err " Gitea: 1Password item created but password could not be retrieved" err " Gitea: 1Password item created but password could not be retrieved"
return 1 return 1
fi fi
log " Gitea: credential stored as '${title}' in vault '${GITEA_OP_VAULT}'" log " Gitea: credential stored as '${title}' in vault '${GITEA_OP_VAULT}'" >&2
printf '%s' "$pw" printf '%s' "$pw"
} }
@ -972,7 +972,7 @@ gitea_helm_admin_token() {
warn " Gitea: could not obtain API token for Helm admin '${admin_user}'" warn " Gitea: could not obtain API token for Helm admin '${admin_user}'"
return 1 return 1
fi fi
log " Gitea: obtained bootstrap token from Helm admin '${admin_user}'" log " Gitea: obtained bootstrap token from Helm admin '${admin_user}'" >&2
printf '%s' "$tok" printf '%s' "$tok"
} }