swh.coarnotify.server.validators module#
Validators.
- swh.coarnotify.server.validators.url_match(url1: str, url2: str) bool[source]#
Compare two URLs ignoring trailing slashes.
- Parameters:
url1 – an URL
url2 – another URL
- Returns:
True if the url matches
- swh.coarnotify.server.validators.simple_url_validator(url: str) bool[source]#
Simple https? URL validator.
Uses django’s
URLValidatorand returns False instead of raising an exception.- Parameters:
url – an URL to validate
- Returns:
True if the URL is valid and its protocol is HTTP or HTTPS.
- swh.coarnotify.server.validators.validate_notification(graph: Graph, root_id: URIRef, inbox_url: str) frozenset[Node][source]#
Validate the generic COAR Notification shape.
https://coar-notify.net/specification/1.0.1/
- Parameters:
graph – RDF graph
root_id – the document ID
inbox_url – our Inbox URL
- Raises:
serializers.ValidationError – payload does not match the specs
- Returns:
a set of types for the notification (to identify handler for it)
- swh.coarnotify.server.validators.validate_mention(graph: Graph, root_id: URIRef) str[source]#
Validate a CN Announce Relationship.
https://coar-notify.net/specification/1.0.1/announce-relationship/
This validation happens outside the Inbox API (it is triggered by the background tasks) so instead of using
serializers.ValidationErrorwe simply raise aValueErrorwith a message listing all the errors we encountered.- Parameters:
graph – RDF graph
root_id – the document ID
- Returns:
The SWHID or Origin URL mentioned
- Raises:
ValueError – the mention is not valid