Add support for notification trigger management and poll notifications - #448
Merged
Conversation
Adds the trigger management Admin API (`triggers`, `create_trigger`, `update_trigger`, `delete_trigger`, `test_trigger`) and the poll notification transport (`notifications`, `ack_notifications`), addressed by named channel or `batch_id`. Adds `utils.verify_notification` to verify a polled message envelope, and `utils.base64url_decode` to decode its `signed_payload`. Fixes a `TypeError` in `verify_notification_signature` when the timestamp is a string, which is the form both the poll envelope and the `X-Cld-Timestamp` header deliver. Adds `batch_id` to upload, archive, multi, sprite and bulk delete parameters, and `request_id` to Admin API responses (`Response.request_id`) and Upload API results. Supports module-first URLs in the v2 API client, honors `cloudinary.config(timeout=...)` on Admin calls, and maps HTTP 503 to `GeneralError`. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds trigger management and the poll notification transport to the Python SDK. Poll notifications let a client receive notifications without exposing a public webhook endpoint: notifications are buffered server-side against a
poll://trigger and drained over long-poll.Admin API
Trigger management:
triggers,create_trigger,update_trigger,delete_trigger,test_trigger.Poll transport:
notificationsandack_notifications, addressed by either a named channel or abatch_id.notificationsraisesValueErrorunless exactly one of the two is given, mirroring the server.Signature verification
utils.verify_notification(message)verifies a polled message envelope directly:It decodes
signed_payloadand verifies against those bytes, then delegates to the existingverify_notification_signature. This matters because signatures cover the byte-exact signed payload: verifying against a re-serialization of the parsedpayload, or against the undecoded base64, returns a silentFalsethat reads as a forged notification.utils.base64url_decodeis exposed for callers who need the raw bytes.Also fixes a
TypeErrorinverify_notification_signaturewhentimestampis a string — the form both the poll envelope and theX-Cld-Timestampheader actually deliver, so the comparison raised on every real message.Other changes
batch_idon upload, archive, multi, sprite and bulk delete parameters (signed automatically)request_idon Admin API responses (Response.request_idattribute) and Upload API results (request_idkey). The Upload API return type stays a plaindict/v2/{module}/{cloud_name}/...), which the notifications endpoints requirecloudinary.config(timeout=...)now honored on Admin API calls; a per-calltimeoutstill winsGeneralErrorTesting
Mocked coverage for triggers, notifications, verification and
request_idpropagation, plus two live end-to-end tests: a trigger create/list/update/delete lifecycle, and an upload that is polled, signature-verified and acknowledged against the real API. Both clean up after themselves and skip without credentials.Verified against a live product environment: 178 passed.