mirror of
https://github.com/acmesh-official/acme.sh.git
synced 2026-08-18 15:13:29 +08:00
fix proxmoxve/proxmoxbs deploy: fail on non-2xx API response
The success check only grepped "message" from the response body, but PVE/PBS auth failures return HTTP 401 with an empty body, so wrong or unauthorized API tokens were reported as "Certificate successfully deployed". Also _retval captured the exit code of the message pipeline instead of _post. Check the HTTP status line from $HTTP_HEADER and capture _post's exit code directly. fix https://github.com/acmesh-official/acme.sh/issues/7141
This commit is contained in:
@@ -116,17 +116,24 @@ HEREDOC
|
|||||||
export HTTPS_INSECURE=1
|
export HTTPS_INSECURE=1
|
||||||
export _H1="Authorization: PBSAPIToken=${_proxmoxbs_header_api_token}"
|
export _H1="Authorization: PBSAPIToken=${_proxmoxbs_header_api_token}"
|
||||||
response=$(_post "$_json_payload" "$_target_url" "" POST "application/json")
|
response=$(_post "$_json_payload" "$_target_url" "" POST "application/json")
|
||||||
|
_retval=$?
|
||||||
|
# The API errors out with a non-2xx HTTP status and an empty body,
|
||||||
|
# so the status line is checked too, not only the response body.
|
||||||
|
_status_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\r\n")"
|
||||||
|
_debug2 "HTTP status" "$_status_code"
|
||||||
response="$(echo "$response" | _json_decode | _normalizeJson)"
|
response="$(echo "$response" | _json_decode | _normalizeJson)"
|
||||||
message=$(echo "$response" | _egrep_o '"message":"[^"]*' | cut -d : -f 2 | tr -d '"')
|
message=$(echo "$response" | _egrep_o '"message":"[^"]*' | cut -d : -f 2 | tr -d '"')
|
||||||
_retval=$?
|
case "$_status_code" in
|
||||||
if [ "${_retval}" -eq 0 ] && [ -z "$message" ]; then
|
2[0-9][0-9])
|
||||||
_debug3 response "$response"
|
if [ "${_retval}" -eq 0 ] && [ -z "$message" ]; then
|
||||||
_info "Certificate successfully deployed"
|
_debug3 response "$response"
|
||||||
return 0
|
_info "Certificate successfully deployed"
|
||||||
else
|
return 0
|
||||||
_err "Certificate deployment failed: $message"
|
fi
|
||||||
_debug "Response" "$response"
|
;;
|
||||||
return 1
|
esac
|
||||||
fi
|
_err "Certificate deployment failed (HTTP status $_status_code). $message"
|
||||||
|
_debug "Response" "$response"
|
||||||
|
return 1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,17 +128,24 @@ HEREDOC
|
|||||||
export HTTPS_INSECURE=1
|
export HTTPS_INSECURE=1
|
||||||
export _H1="Authorization: PVEAPIToken=${_proxmoxve_header_api_token}"
|
export _H1="Authorization: PVEAPIToken=${_proxmoxve_header_api_token}"
|
||||||
response=$(_post "$_json_payload" "$_target_url" "" POST "application/json")
|
response=$(_post "$_json_payload" "$_target_url" "" POST "application/json")
|
||||||
|
_retval=$?
|
||||||
|
# The API errors out with a non-2xx HTTP status and an empty body,
|
||||||
|
# so the status line is checked too, not only the response body.
|
||||||
|
_status_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\r\n")"
|
||||||
|
_debug2 "HTTP status" "$_status_code"
|
||||||
response="$(echo "$response" | _json_decode | _normalizeJson)"
|
response="$(echo "$response" | _json_decode | _normalizeJson)"
|
||||||
message=$(echo "$response" | _egrep_o '"message":"[^"]*' | cut -d : -f 2 | tr -d '"')
|
message=$(echo "$response" | _egrep_o '"message":"[^"]*' | cut -d : -f 2 | tr -d '"')
|
||||||
_retval=$?
|
case "$_status_code" in
|
||||||
if [ "${_retval}" -eq 0 ] && [ -z "$message" ]; then
|
2[0-9][0-9])
|
||||||
_debug3 response "$response"
|
if [ "${_retval}" -eq 0 ] && [ -z "$message" ]; then
|
||||||
_info "Certificate successfully deployed"
|
_debug3 response "$response"
|
||||||
return 0
|
_info "Certificate successfully deployed"
|
||||||
else
|
return 0
|
||||||
_err "Certificate deployment failed: $message"
|
fi
|
||||||
_debug "Response" "$response"
|
;;
|
||||||
return 1
|
esac
|
||||||
fi
|
_err "Certificate deployment failed (HTTP status $_status_code). $message"
|
||||||
|
_debug "Response" "$response"
|
||||||
|
return 1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user