app.services.intake_checks¶
Request validation and refusal checks of CI push intake.
Pure helpers used by app.services.intake (which owns the
order of the checks, the run log and the write); see that module’s
docstring for the full contract. Nothing here touches storage.
Public API: MAX_BODY_BYTES, MAX_CONTENT_BYTES,
CandidateSubmission, auth_error(),
peek_source_id(), decode_body(), authenticate(),
named_source(), validate_submission(),
check_registration(), build_document(),
check_document(), issues_json().
- app.services.intake_checks.MAX_BODY_BYTES = 8388608¶
Largest accepted request body (JSON escaping may inflate content).
- app.services.intake_checks.MAX_CONTENT_BYTES = 1048576¶
Largest accepted Markdown document (UTF-8 bytes).
- class app.services.intake_checks.CandidateSubmission(*, source_id, project, adr_uuid, ref, content, path=None, delivery_id=None, author=None)¶
Bases:
BaseModelBody of
PUT/POST /api/v1/candidates; extra keys -> 422.
- app.services.intake_checks.auth_error(message, *, presented)¶
Build the 401 for a missing or unacceptable push token.
- Parameters:
- Return type:
- Returns:
The error.
- app.services.intake_checks.authenticate(sources, token, source_id)¶
Check the push token against the named registration.
- Parameters:
sources (
Sequence[SourceRegistration]) – All configured registrations.token (
str) – Presented bearer token.source_id (
str|None) – Requested registration id, if the body names one.
- Return type:
- Returns:
The registration;
Nonewhen the body names none but the token is valid for some registration.- Raises:
AuthenticationError – If the token is not acceptable.
- app.services.intake_checks.build_document(source, submission)¶
Build the ingest input from a submission.
- Parameters:
source (
SourceRegistration) – The registration.submission (
CandidateSubmission) – The validated body.
- Return type:
- Returns:
The document.
- Raises:
PayloadTooLargeError –
content_too_large.ValidationFailedError –
bad_encoding.
- app.services.intake_checks.check_document(prepared, submission)¶
Refuse unusable documents and UUID mismatches.
- Parameters:
prepared (
PreparedDocument) – Parsed document.submission (
CandidateSubmission) – The validated body.
- Raises:
ValidationFailedError –
invalid_document(withissues) oruuid_mismatch.- Return type:
- app.services.intake_checks.check_registration(source, submission)¶
Check push intake, scope and ref against the registration.
- Parameters:
source (
SourceRegistration) – The authenticated registration.submission (
CandidateSubmission) – The validated body.
- Raises:
ForbiddenError –
push_disabled/project_out_of_scope.ValidationFailedError –
published_ref_not_allowed.
- Return type:
- app.services.intake_checks.decode_body(body)¶
Decode a JSON body.
- app.services.intake_checks.issues_json(issues)¶
Serialise issues to JSON values.
- app.services.intake_checks.named_source(sources, token, source_id)¶
Check the push token against one registration.
- Parameters:
sources (
Sequence[SourceRegistration]) – All configured registrations.token (
str) – Presented bearer token.source_id (
str) – Requested registration id.
- Return type:
- Returns:
The registration.
- Raises:
AuthenticationError – If the registration is unknown or the token is not one of its push tokens (same answer for both).
- app.services.intake_checks.peek_source_id(raw)¶
Read
source_idfrom a decoded body, if it is a string.
- app.services.intake_checks.validate_submission(raw)¶
Validate the decoded body.
- Parameters:
raw (
object) – Decoded JSON (Nonewhen the body was not JSON).- Return type:
- Returns:
The submission.
- Raises:
ValidationFailedError –
invalid_requestwitherrors.