Skip to content
Snippets Groups Projects

Move check_url_match_provider to api.checks instead of utils

Compare and
3 files
+ 15
16
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 14
0
@@ -22,6 +22,7 @@ from xml.etree import ElementTree
import pkg_resources
import xmlschema
from swh.deposit.errors import FORBIDDEN, DepositError
from swh.deposit.utils import NAMESPACES, parse_swh_metadata_provenance
MANDATORY_FIELDS_MISSING = "Mandatory fields are missing"
@@ -113,3 +114,16 @@ def check_metadata(metadata: ElementTree.Element) -> Tuple[bool, Optional[Dict]]
return True, {"metadata": suggested_fields}
return True, None
def check_url_match_provider(url: str, provider_url: str) -> None:
"""Check url matches the provider url.
Raises DepositError in case of mismatch
"""
provider_url = provider_url.rstrip("/") + "/"
if not url.startswith(provider_url):
raise DepositError(
FORBIDDEN, f"URL mismatch: {url} must start with {provider_url}",
)
Loading