Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/common.py
Show First 20 Lines • Show All 722 Lines • ▼ Show 20 Lines | ) -> Receipt: | ||||
except ParserError: | except ParserError: | ||||
raise DepositError( | raise DepositError( | ||||
BAD_REQUEST, | BAD_REQUEST, | ||||
"Malformed xml metadata", | "Malformed xml metadata", | ||||
"The xml received is malformed. " | "The xml received is malformed. " | ||||
"Please ensure your metadata file is correctly formatted.", | "Please ensure your metadata file is correctly formatted.", | ||||
) | ) | ||||
if not metadata: | if metadata is None: | ||||
raise DepositError( | raise DepositError( | ||||
BAD_REQUEST, | BAD_REQUEST, | ||||
"Empty body request is not supported", | "Empty body request is not supported", | ||||
"Atom entry deposit is supposed to send for metadata. " | "Atom entry deposit is supposed to send for metadata. " | ||||
"If the body is empty, there is no metadata.", | "If the body is empty, there is no metadata.", | ||||
) | ) | ||||
if ( | create_origin = metadata.get("swh:deposit", {}).get("swh:create_origin") | ||||
"atom:external_identifier" in metadata | if create_origin: | ||||
and headers.slug | origin_url = create_origin["swh:origin"]["@url"] | ||||
and metadata["atom:external_identifier"] != headers.slug | deposit.origin_url = origin_url | ||||
): | |||||
# TODO: When clients stopped using it, raise this error | if "atom:external_identifier" in metadata: | ||||
# even when they are equal. | # Deprecated tag. | ||||
ardumont: `stops using` | |||||
Done Inline ActionsEither stopped using or stop using is fine imo. It just depends where on the timeline you are (I'm writing this for people reading it in the future :p) vlorentz: Either `stopped using` or `stop using` is fine imo. It just depends where on the timeline you… | |||||
Done Inline Actionsheh, ok then. ardumont: heh, ok then. | |||||
# When clients stopped using it, this should raise an error | |||||
# unconditionally | |||||
if deposit.origin_url: | |||||
Done Inline Actionsmissing test case. ardumont: missing test case. | |||||
raise DepositError( | |||||
BAD_REQUEST, | |||||
"<external_identifier> is deprecated, you should only use " | |||||
"<swh:create_origin> from now on.", | |||||
) | |||||
if headers.slug and metadata["atom:external_identifier"] != headers.slug: | |||||
raise DepositError( | raise DepositError( | ||||
BAD_REQUEST, | BAD_REQUEST, | ||||
"The 'external_identifier' tag is deprecated, " | "The 'external_identifier' tag is deprecated, " | ||||
"the Slug header should be used instead.", | "the Slug header should be used instead.", | ||||
) | ) | ||||
# Determine if we are in the metadata-only deposit case | # Determine if we are in the metadata-only deposit case | ||||
try: | try: | ||||
swhid = parse_swh_reference(metadata) | swhid = parse_swh_reference(metadata) | ||||
except ValidationError as e: | except ValidationError as e: | ||||
raise DepositError( | raise DepositError( | ||||
PARSING_ERROR, "Invalid SWHID reference", str(e), | PARSING_ERROR, "Invalid SWHID reference", str(e), | ||||
) | ) | ||||
if swhid is not None and deposit.origin_url is not None: | |||||
raise DepositError( | |||||
BAD_REQUEST, | |||||
"<swh:reference> is for metadata-only deposits and " | |||||
"<swh:create_origin> is for code deposits, both cannot be used " | |||||
"in the same deposit.", | |||||
) | |||||
Done Inline Actionsmissing test case. ardumont: missing test case. | |||||
self._deposit_put( | self._deposit_put( | ||||
deposit=deposit, in_progress=headers.in_progress, | deposit=deposit, in_progress=headers.in_progress, | ||||
) | ) | ||||
if swhid is not None: | if swhid is not None: | ||||
swhid, swhid_ref, depo, depo_request = self._store_metadata_deposit( | swhid, swhid_ref, depo, depo_request = self._store_metadata_deposit( | ||||
deposit, swhid, metadata, raw_metadata | deposit, swhid, metadata, raw_metadata | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 367 Lines • Show Last 20 Lines |
stops using