fix(cicd): show PaC apply API errors
This commit is contained in:
@@ -70,38 +70,29 @@ prepare_gitea_api_base() {
|
||||
export UNIDESK_PAC_GITEA_API_BASE_URL
|
||||
}
|
||||
|
||||
resolve_service_url_to_cluster_ip() {
|
||||
value="$1"
|
||||
hostport=$(printf '%s' "$value" | sed -n 's#^http://\([^/]*\).*$#\1#p')
|
||||
if ! printf '%s' "$hostport" | grep -q '\.svc\.cluster\.local'; then
|
||||
printf '%s' "$value"
|
||||
return
|
||||
fi
|
||||
host=${hostport%%:*}
|
||||
port=${hostport##*:}
|
||||
if [ "$port" = "$hostport" ]; then port=80; fi
|
||||
service=${host%%.*}
|
||||
rest=${host#*.}
|
||||
namespace=${rest%%.*}
|
||||
cluster_ip=$(kubectl -n "$namespace" get svc "$service" -o jsonpath='{.spec.clusterIP}')
|
||||
printf '%s' "$value" | sed "s#^http://$hostport#http://$cluster_ip:$port#"
|
||||
}
|
||||
|
||||
gitea_api() {
|
||||
method="$1"
|
||||
path="$2"
|
||||
body="${3:-}"
|
||||
tmp=$(mktemp)
|
||||
if [ -n "$body" ]; then
|
||||
curl -fsS -u "$UNIDESK_PAC_GITEA_ADMIN_USERNAME:$UNIDESK_PAC_GITEA_ADMIN_PASSWORD" \
|
||||
code=$(curl -sS -o "$tmp" -w '%{http_code}' -u "$UNIDESK_PAC_GITEA_ADMIN_USERNAME:$UNIDESK_PAC_GITEA_ADMIN_PASSWORD" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-X "$method" \
|
||||
--data "$body" \
|
||||
"$(api_url "$path")"
|
||||
"$(api_url "$path")" || true)
|
||||
else
|
||||
curl -fsS -u "$UNIDESK_PAC_GITEA_ADMIN_USERNAME:$UNIDESK_PAC_GITEA_ADMIN_PASSWORD" \
|
||||
code=$(curl -sS -o "$tmp" -w '%{http_code}' -u "$UNIDESK_PAC_GITEA_ADMIN_USERNAME:$UNIDESK_PAC_GITEA_ADMIN_PASSWORD" \
|
||||
-X "$method" \
|
||||
"$(api_url "$path")"
|
||||
"$(api_url "$path")" || true)
|
||||
fi
|
||||
case "$code" in
|
||||
2*) cat "$tmp"; rm -f "$tmp"; return 0 ;;
|
||||
esac
|
||||
response=$(head -c 500 "$tmp" | tr '\n' ' ' | sed 's/[[:space:]][[:space:]]*/ /g')
|
||||
rm -f "$tmp"
|
||||
printf 'gitea api %s %s failed: HTTP %s response=%s\n' "$method" "$path" "$code" "$response" >&2
|
||||
return 22
|
||||
}
|
||||
|
||||
ensure_token() {
|
||||
|
||||
Reference in New Issue
Block a user