Clarify sink behaviour in implicit subscription model - #680
Conversation
|
Additional test case in sample-implicit-events-template.feature can be considered to check the error response when event delivery is not supported. |
Thanks @rartych! Good point |
Co-authored-by: Rafal Artych <121048129+rartych@users.noreply.github.com>
…uide.md Co-authored-by: Rafal Artych <121048129+rartych@users.noreply.github.com>
bigludo7
left a comment
There was a problem hiding this comment.
LGTM
Thanks @PedroDiez for the reminder
There was a problem hiding this comment.
See a few suggestions below.
Two small things in the PR description, since it feeds the release notes:
- The Changes list doesn't mention the added test scenario in
artifacts/testing/sample-implicit-events-template.feature. - "providing an unsupported sink returns an error" (in the
CreateResource.sinkbullet) sounds like the existing400 INVALID_SINK/INVALID_PROTOCOL/INVALID_CREDENTIALcases, which this PR doesn't change. The new code is for a different case: the provider doesn't support notification delivery at all.
On the breaking change I agree, and I think the PR should say who has to act on it. Today an implementation may accept sink, create the resource, and simply not send events; nothing forbids it. After this PR that is no longer allowed. Whether to document the new 422 is then each API's own decision: an API that wants to allow implementations without notification delivery adds it — a breaking change per §7.4 of the Design Guide, so a major version — while an API that expects every implementation to deliver events adds nothing and stays as it is (camaraproject/QualityOnDemand#556 tracks that decision for QoD). Worth saying so in §2.1, so the new text isn't read as requiring the error in every API offering the pattern.
| status: 422 | ||
| code: PRIVATE_KEY_JWT_NOT_CONFIGURED | ||
| message: Private key JWT credential type cannot be used because no configuration was pre-shared. | ||
| GENERIC_422_NOTIFICATIONS_NOT_SUPPORTED: |
There was a problem hiding this comment.
Example key aligned with the code:
| GENERIC_422_NOTIFICATIONS_NOT_SUPPORTED: | |
| GENERIC_422_EVENT_NOTIFICATIONS_NOT_SUPPORTED: |
|
|
||
| | attribute name | type | attribute description | cardinality | | ||
| |----------------|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------| | ||
| | sink | string | https callback address where the notification must be POST-ed, `format: uri` SHOULD be used to require a string that is compliant with [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986). The [security considerations](#43-notifications-security-considerations) SHOULD be followed. | mandatory | |
There was a problem hiding this comment.
The attribute sink must be optional to not contradict the described behavior and the definition within artifacts (this inconsistency wasn't introduced by the PR, it pre-existed):
| | sink | string | https callback address where the notification must be POST-ed, `format: uri` SHOULD be used to require a string that is compliant with [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986). The [security considerations](#43-notifications-security-considerations) SHOULD be followed. | optional | |
| Present in the response when `sink` was provided in the creation | ||
| request and event delivery is supported and active. |
There was a problem hiding this comment.
Under the new contract, if delivery isn't supported the resource is not created — so every existing resource whose creation carried sink had delivery accepted, and the guide says sink MUST be echoed.
| Present in the response when `sink` was provided in the creation | |
| request and event delivery is supported and active. | |
| Present in the response whenever `sink` was provided in the creation request. |
| **Sink delivery behaviour** | ||
|
|
||
| When `sink` is provided in the POST request, the following rules apply: | ||
| - API providers SHOULD implement event delivery support. If a request includes `sink` and the API provider does not support notification delivery (i.e. the implicit subscription feature is not implemented by this provider instance), the request MUST be rejected with 422 EVENT_NOTIFICATIONS_NOT_SUPPORTED and the resource MUST NOT be created. |
There was a problem hiding this comment.
Vocabulary ... we haven't used "provider instance" yet in the document:
| - API providers SHOULD implement event delivery support. If a request includes `sink` and the API provider does not support notification delivery (i.e. the implicit subscription feature is not implemented by this provider instance), the request MUST be rejected with 422 EVENT_NOTIFICATIONS_NOT_SUPPORTED and the resource MUST NOT be created. | |
| - API providers SHOULD implement event delivery support. If a request includes `sink` and the API provider does not support notification delivery (i.e. the implicit subscription feature is not implemented by this API provider), the request MUST be rejected with 422 EVENT_NOTIFICATIONS_NOT_SUPPORTED and the resource MUST NOT be created. |
| And the response property "$.code" is "INVALID_TOKEN" OR "INVALID_ARGUMENT" | ||
| And the response property "$.message" contains a user friendly text | ||
|
|
||
| # Event notifications capability not supported scenario |
There was a problem hiding this comment.
The file inherits # Syntax Error scenarios from line 44, so this 422 currently sits in the syntax group. sample-service-template.feature splits the two — adding the second header keeps that structure:
| # Event notifications capability not supported scenario | |
| # Service Error scenarios | |
| # Event notifications capability not supported scenario |
| And the event header "Content-Type" is set to "application/cloudevents+json" | ||
| And the event body complies with the OAS schema at "#/components/schemas/ApiNotificationEvent" | ||
| # Additionally any event body has to comply with some constraints beyond the schema compliance | ||
| And the event body property "$.<property>" is ... |
There was a problem hiding this comment.
§2.1 now also states that sink MUST be echoed in the response when event delivery is accepted, and no scenario covers that yet — this one verifies the notification arrives, and its When acts on an already-created resource. A compact scenario for the creation response could look like:
@{feature_identifier}_{operationId}_xx_sink_echoed
Scenario: Sink is returned in the creation response when event delivery is accepted
Given the request body includes property "$.sink" with a valid value
When the request "{operationId}" is sent
Then the response status code is 2<xx>
And the response property "$.sink" has same value as the request body property "$.sink"
What type of PR is this?
What this PR does / why we need it:
Formalises the behaviour for
sinkhandling in the implicit-subscription model: when a consumer provides a sink in the request, the API provider must either deliver events or reject the request with an error — silently creating the resource without notifications is no longer permitted.Changes
documentation/CAMARA-API-Event-Subscription-and-Notification-Guide.mdsinkis provided.422 EVENT_NOTIFICATIONS_NOT_SUPPORTEDand the resource MUST NOT be created.sink(e.g. fall back to polling).artifacts/api-templates/sample-implicit-events.yamlPOST /resourcesdescription to document the422 EVENT_NOTIFICATIONS_NOT_SUPPORTEDerror path.CreateResource.sinkdescription to clarify that omittingsinkskips notifications, and that providing an unsupported sink returns an error.Resource.sinkdescription to reflect thatsinkis echoed only when delivery is accepted and active.EVENT_NOTIFICATIONS_NOT_SUPPORTEDto the 422 response enum and added a corresponding example with an actionable error messageWhich issue(s) this PR fixes:
Fixes #628
Does this PR introduce a breaking change?
Yes
No
Not clear behaviour so far so both allowing the resorce creation without notifications delivery as well as generating an error would be acceptable
This PR unifies behaviour and introduces a new Error Code
422 EVENT_NOTIFICATIONS_NOT_SUPPORTED, so backwards compatibility is not keptSpecial notes for reviewers:
Changelog input
Additional documentation
This section can be blank.