feat: add idempotent token deletion before generating new Gitea backup admin token

This commit is contained in:
S
2026-03-01 08:58:39 -05:00
parent 83f706c6b8
commit 24d7df0a0b

View File

@@ -132,6 +132,12 @@ if [[ -n "${GITEA_BACKUP_ADMIN_TOKEN:-}" ]]; then
fi fi
if [[ -z "${GITEA_BACKUP_ADMIN_TOKEN:-}" ]]; then if [[ -z "${GITEA_BACKUP_ADMIN_TOKEN:-}" ]]; then
# Delete any stale token with the same name (idempotent re-run safety).
curl -sf -u "${GITEA_ADMIN_USER}:${GITEA_ADMIN_PASSWORD}" \
-X DELETE \
"${GITEA_BACKUP_INTERNAL_URL}/api/v1/users/${GITEA_ADMIN_USER}/tokens/migration-token" \
-o /dev/null 2>/dev/null || true
# Generate via basic auth — token is only returned once in the .sha1 field # Generate via basic auth — token is only returned once in the .sha1 field
TOKEN_RESPONSE=$(curl -sf -u "${GITEA_ADMIN_USER}:${GITEA_ADMIN_PASSWORD}" \ TOKEN_RESPONSE=$(curl -sf -u "${GITEA_ADMIN_USER}:${GITEA_ADMIN_PASSWORD}" \
-X POST \ -X POST \