swh.coarnotify.server.utils module#

Utils.

swh.coarnotify.server.utils.send_cn(notification: OutboundNotification) bool[source]#

Send a COAR Notification.

The client is defined in settings.CN_CLIENT

Parameters:

notification – an OutboundNotification

Returns:

True if the recipient inbox has been reached.

swh.coarnotify.server.utils.create_accept_cn(cn: InboundNotification, summary: str | None = None) OutboundNotification[source]#

Create an Outbound CN to reply to an acceptable CN.

https://coar-notify.net/specification/1.0.1/accept/

Parameters:
  • cn – an inbound notification

  • summary – an optional summary to include in the CN

Returns:

an outbound CN

swh.coarnotify.server.utils.create_unprocessable_cn(notification: InboundNotification) OutboundNotification[source]#

Create an Outbound CN to reply to an unprocessable CN.

https://coar-notify.net/specification/1.0.1/unprocessable/

Parameters:

notification – an inbound CN

Returns:

an outbound CN

swh.coarnotify.server.utils.create_reject_cn(notification: InboundNotification) OutboundNotification[source]#

Create an Outbound CN to reply to a rejected CN.

https://coar-notify.net/specification/1.0.1/reject/

Parameters:

notification – an inbound CN

Returns:

an outbound CN

swh.coarnotify.server.utils.uuid_from_urn(urn: str) UUID[source]#

Extract a UUID from a URN.

Parameters:

urn – a UUID URN (urn:uuid:xxx)

Raises:

serializers.ValidationError – URN is not a valid UUID URN

Returns:

a uuid

swh.coarnotify.server.utils.to_sorted_tuple(value: str | list[str]) tuple[source]#

Convert a single string or a list to a sorted tuple.

Parameters:

value – a string or a list

Returns:

a sorted tuple of strings

swh.coarnotify.server.utils.validate_sender_inbox(request: Request, payload: dict) bool[source]#

Validate sender’s inbox.

The value of origin inbox must match the value from the authenticated sender.

Parameters:
  • request – an HTTP request

  • payload – the CN payload

Raises:

serializers.ValidationError – inbox urls mismatch

Returns:

True if the user’s inbox url matches the one in the notification

swh.coarnotify.server.utils.validate_context(at_context: list[str]) None[source]#

Validate the notification @context.

https://coar-notify.net/specification/1.0.1/

Parameters:

at_context – a list of URI

Raises:

serializers.ValidationErrorat_context does not match the specs

swh.coarnotify.server.utils.validate_required_keys(payload: dict) None[source]#

Validate the payload shape.

https://coar-notify.net/specification/1.0.1/

Parameters:

payload – the CN payload

Raises:

serializers.ValidationError – payload does not match the specs

swh.coarnotify.server.utils.reject(notification: InboundNotification, error_message: str) None[source]#

Mark notification as rejected and send a Reject CN.

Parameters:
  • notification – an InboundNotification

  • error_message – a reason for the rejection

swh.coarnotify.server.utils.unprocessable(notification: InboundNotification, error_message: str) None[source]#

Mark notification as unprocessable and send an Unprocessable CN.

Parameters:
  • notification – an InboundNotification

  • error_message – a reason for the rejection

swh.coarnotify.server.utils.inbox_headers(request: Request) dict[str, str][source]#

Headers to signpost our Inbox address.

Parameters:

request – an HTTP request

Returns:

headers to include on our views

Return type:

dict[str, str]