Skip to content

refactor!: upgrade to FOCA 0.15 - #127

Closed
uniqueg wants to merge 18 commits into
devfrom
feat/foca-0.15
Closed

uniqueg wants to merge 18 commits into
devfrom
feat/foca-0.15

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Upgrades the registry to FOCA 0.15.0 (released on PyPI and Docker Hub).

  • Requirement foca>=0.15.0,<0.16; the image is built on
    elixircloud/foca:0.15.0-py3.12, pinned by digest. jsonschema and
    PyYAML are no longer direct requirements (both come with FOCA).
  • Breaking: the service info is served by FOCA from
    service_info.service (Helm: config.service_info.service) instead of
    custom.endpoints.service_info; the app's own service info module is
    removed. POST /service-info stays removed.
  • Breaking: the size limit of request bodies is FOCA's
    server.max_content_length (Helm: config.server.max_content_length,
    which also sets the ingress-nginx limit) instead of
    custom.max_content_length; FOCA also limits chunked bodies.
  • Configs and Helm values still setting the removed keys are rejected (the
    chart fails rendering, naming the new keys).
  • Errors are sent as application/json via FOCA's configurable error media
    type; FOCA's escape_log_value() replaces the local copy; traffic logging
    of GET /service-info is kept and tested.
  • Release notes (docs/releases/0.3.0.md) and READMEs updated. The feat: grant roles on services to groups #105
    TODO stays in the release notes on purpose (the release workflow fails on
    TODO until feat: grant roles on services to groups #105 is done).

Closes #104.

Verification

Local, on the final tree:

  • coverage run --source=cloud_registry -m pytest (Python 3.10, FOCA 0.15.0
    from PyPI): 683 passed; coverage report: 100 %.
  • pytest on Python 3.12: 683 passed.
  • ruff check ., ruff format --check .: passed.
  • mypy cloud_registry tests: no issues.
  • ast-grep scan, ast-grep test --skip-snapshot-tests: passed;
    semgrep --config .semgrep --error: no findings.
  • helm lint deployment --strict -f deployment/ci/test-values.yaml (with and
    without MongoDB auth, as in CI) and helm template: passed.
  • Wheel build: requires connexion, foca (>=0.15.0,<0.16), gunicorn, idna; no
    unexpected files.
  • docker compose up -d --build --wait with the CI smoke checks (probe,
    9 API checks against MongoDB, app version, license text): passed. The image
    is built from the pinned 0.15.0 digest, has no git and reports FOCA 0.15.0
    (run before the round-2 and Sourcery fixes, a startup check and a chart template
    change; CI ran it on the final tree: passed).

Not run locally: the full pre-commit run --all-files and gitleaks (hook
environments can't be fetched behind the sandbox proxy); the hooks above were
run directly. CI runs them.

CI (run 39593511239, final head f071ccb): all checks passed (static analysis incl. full pre-commit and gitleaks, tests on Python 3.10 and 3.12, Helm chart, Docker Compose smoke test, Read the Docs).

Review

Two local review rounds (adversarial and quality, then adversarial).
Fixed: unused requirements, chart checks for the removed keys, stale docs;
round 2: config.server: null passed on to FOCA (which refuses it) and
server.max_content_length: null silently lifting the body limit. Sourcery
flagged the latter (first a startup warning) as needing a human reviewer, so
the app now refuses to start with null, as the removed
custom.max_content_length and the chart do.

Declined review findings

None.

Open questions

None.

🤖 Generated with Claude Code

uniqueg and others added 17 commits October 21, 2026 13:19
FOCA 0.15.0 is not released yet, so its release candidate, commit
5f07646 on FOCA's `dev` branch, is installed from Git. The image
installs Git for the build and removes it again, and checks that FOCA
0.15 is installed, so that the app runs on FOCA 0.15 code although the
base image is still FOCA 0.14.0 (no 0.15.0 image exists yet).
`TODO(#104)` comments say how to switch to the release.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FOCA 0.15 provides `foca.utils.logging.escape_log_value()`, which the
app copied in `cloud_registry.utils` until then. Use FOCA's and remove
the copy and its tests (FOCA tests it).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FOCA 0.15 serves GA4GH service info from its config section
`service_info`, validates it against the GA4GH `Service` schema on
startup and serves the version of an installed package, as the app did
itself (#100). Use FOCA's instead:

- Move the service info from `custom.endpoints.service_info` to
  `service_info.service`, with `service_info.package: cloud-registry`
  for the version.
- Route `GET /service-info` to FOCA's controller
  (`foca.api.service_info`) in `additions.openapi.yaml`.
- Remove the app's controller, its service info module and the startup
  check, and their tests; FOCA covers them. App tests check that FOCA
  serves the configured service info with the package version, removes
  `null` fields, and that invalid service info, or service info still
  in the custom config, fails startup.

`GET /service-info` is unchanged for clients.

BREAKING CHANGE: the service info is configured in
`service_info.service` instead of `custom.endpoints.service_info`
(Helm chart: `config.service_info.service`); configs still setting the
latter are rejected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Errors were sent as `application/problem+json`, FOCA's default, while
the GA4GH specifications declare `application/json` for error
responses; #96 therefore declared `application/problem+json` in
addition. FOCA 0.15 makes the media type configurable:

- Set `exceptions.media_type: application/json`, which applies to all
  errors handled by FOCA (app exceptions, request validation, security
  errors, unknown routes and methods, FOCA's permissions API).
- Send the app's own problem details (`problem()`,
  `validation_problem()`) with the configured media type, too.
- Remove the `application/problem+json` declarations from
  `additions.openapi.yaml`, so that error responses are declared as in
  the GA4GH specification only.

Tests check the media type of each kind of error response and that the
specification declares only `application/json` for error responses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Describe the changes of the FOCA 0.15 upgrade for users in the 0.3.0
release notes: errors are sent as `application/json`, the service info
is served by FOCA from `service_info.service`, and configs must apply
FOCA 0.15's config changes.

Resolve the #104 part of the TODO note. The note still blocks the
release, for roles granted to groups (#105) and for requiring the FOCA
0.15.0 release instead of its release candidate.

Closes #104

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Install FOCA from commit 43d9526 on its `dev` branch, which adds
configurable traffic logging (FOCA #328) and limits request bodies
without `Content-Length` via `server.max_content_length` (FOCA #329).

FOCA's service info controller is now itself decorated (traffic
logging), so the test that `GET /service-info` is routed to it compares
the unwrapped functions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FOCA 0.15 limits request bodies itself (`server.max_content_length`):
bodies with a larger `Content-Length` are rejected (`413`) without
reading them, and bodies without one (e.g., chunked) are read up to
one byte over the limit, before authentication and validation, as the
app did itself (#119). Use FOCA's instead:

- Set `server.max_content_length: 1048576` in the base config and
  remove `custom.max_content_length` from the custom config model;
  configs still setting it are rejected on startup.
- Remove the app's before-request check (`check_streamed_size()`) and
  its setting of Flask's `MAX_CONTENT_LENGTH`. FOCA also rejects
  invalid `Content-Length` headers (`400`).
- The app's tests of the behaviour now run against FOCA's check; drop
  the tests of the removed config field.
- Chart: take the ingress-nginx body size limit, and its render-time
  validation, from `config.server.max_content_length`.
- Image: fail the build unless FOCA limits bodies without
  `Content-Length` (FOCA #329).

BREAKING CHANGE: the size limit of request bodies is configured in
`server.max_content_length` instead of `custom.max_content_length`
(Helm chart: `config.server.max_content_length`); configs still
setting the latter are rejected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since FOCA #328, FOCA's service info controller logs requests and
responses unless `service_info.log_traffic` is disabled, so
`GET /service-info` is logged again, as when the app served it with its
own controller. Check that it is.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Describe the size limit of request bodies as FOCA's
`server.max_content_length` (also for chunked bodies, and `400` for
invalid `Content-Length` headers), configs still setting
`custom.max_content_length` being rejected, and that requests for the
service info are logged as before. The TODO note for #105 stays.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FOCA 0.15.0 is released: require foca>=0.15.0,<0.16 from PyPI instead
of the release candidate from Git, and build the image on FOCA's
0.15.0 image (pinned by digest). Git is no longer installed for the
build, and the checks that the installed FOCA has the 0.15 features
are dropped, as the requirement ensures it. The release notes drop
the TODO item about the pin.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The app no longer validates with jsonschema or reads YAML itself (the
service info is served by FOCA), so neither is a direct requirement.
The tests' YAML parser is a dependency of FOCA. Drop the jsonschema
type stubs too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rendering fails if values still set config.custom.max_content_length
or config.custom.endpoints.service_info, which the app rejects since
the FOCA 0.15 upgrade, naming their replacements
(config.server.max_content_length, config.service_info.service), like
the chart's other checks for removed settings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since the service info is served by FOCA, the app no longer validates
with jsonschema itself; date-times aren't checked by Connexion's
request validation (without rfc3339-validator).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FOCA's `server.max_content_length` takes `null` as no limit, while the
removed `custom.max_content_length` rejected it, so an overlay could
silently lift the limit, allowing bodies of any size (also chunked
ones) before authentication. The app now logs a warning on startup,
and the README says what `null` means. The Helm chart still refuses
`null`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The values schema allows `config.server: null`, and the size limit of
ingress-nginx treated it as the default, but the overlay passed it on,
so FOCA replaced the base config's `server` with `null` and refused to
start. Like `custom: null`, it is now left out of the overlay.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This breaking release upgrades the registry to pinned FOCA 0.15.0, delegates service-info, request-size enforcement, error formatting, and logging utilities to FOCA, migrates Helm and application configuration to the new FOCA-owned keys with explicit rejection of removed settings, and updates API documentation, tests, and release guidance.

Sequence diagram for FOCA-served service info

sequenceDiagram
    participant Client
    participant FOCA
    participant Config

    Client->>FOCA: GET /service-info
    FOCA->>Config: Read service_info.service
    Config-->>FOCA: GA4GH Service info
    FOCA-->>Client: 200 Service info
Loading

Sequence diagram for FOCA request body limit

sequenceDiagram
    participant Client
    participant FOCA
    participant Registry

    Client->>FOCA: Request with body
    FOCA->>FOCA: Check server.max_content_length
    alt body exceeds limit
        FOCA-->>Client: 413 Content Too Large
    else body within limit
        FOCA->>Registry: Validate and dispatch request
        Registry-->>Client: Registry response
    end
Loading

Flow diagram for migrated configuration validation

flowchart TD
    Values[Helm values or application config] --> Legacy{Removed FOCA keys present?}
    Legacy -->|Yes: custom.max_content_length or custom.endpoints.service_info| Reject[Reject configuration with migration error]
    Legacy -->|No| NewKeys[Use server.max_content_length and service_info.service]
    NewKeys --> Render[Render Helm chart or start application]
Loading

File-Level Changes

Change Details Files
Upgrade the application and container runtime to FOCA 0.15.0 and consume FOCA-provided dependencies and utilities.
  • Constrain the FOCA dependency to the 0.15 release line and remove transitive direct requirements.
  • Pin the Docker base image to the FOCA 0.15.0 image digest.
  • Replace the local log-value escaping implementation with FOCA’s utility.
Dockerfile
requirements.txt
requirements_dev.txt
cloud_registry/exceptions.py
cloud_registry/ga4gh/registry/permissions.py
cloud_registry/ga4gh/registry/service.py
cloud_registry/ga4gh/registry/server.py
cloud_registry/ga4gh/registry/verification.py
cloud_registry/utils.py
Move service-info serving and request-body limits into FOCA configuration and remove the application-owned service-info implementation.
  • Configure service_info.service and service_info.package, with FOCA serving and validating GET /service-info.
  • Configure server.max_content_length, including FOCA handling for declared and chunked bodies and a warning when the limit is null.
  • Remove the service-info controller, model fields, validation module, and POST /service-info behavior while preserving traffic logging for GET /service-info.
cloud_registry/app.py
cloud_registry/config.yaml
cloud_registry/ga4gh/registry/server.py
cloud_registry/ga4gh/registry/service_info.py
cloud_registry/service_models/custom_config.py
cloud_registry/gunicorn_config.py
Align error responses and API documentation with FOCA’s configurable error media type and GA4GH requirements.
  • Set FOCA and application-generated problem details to application/json.
  • Update OpenAPI error response declarations across application, authentication, routing, access-control, and internal errors.
  • Add coverage for configured media types, invalid content lengths, unknown routes, permissions errors, and internal failures.
cloud_registry/config.yaml
cloud_registry/exceptions.py
cloud_registry/api/additions.openapi.yaml
README.md
tests/test_exceptions.py
tests/test_app.py
tests/ga4gh/registry/test_verification.py
tests/test_verification.py
Update Helm configuration, rendering safeguards, and deployment documentation for the breaking FOCA configuration changes.
  • Move chart examples and ingress body-size propagation to config.service_info.service and config.server.max_content_length.
  • Fail chart rendering when removed custom keys are supplied, naming their replacements.
  • Normalize null custom and server sections before passing overlays to FOCA and validate positive ingress limits.
deployment/templates/_helpers.tpl
deployment/templates/cloud-registry-configmap.yaml
deployment/values.schema.json
deployment/values.yaml
deployment/README.md
tests/test_chart.py
tests/test_config.py
Refresh tests and release documentation for the FOCA 0.15 migration and its breaking changes.
  • Replace service-info and body-limit fixtures and assertions with FOCA configuration and behavior.
  • Remove obsolete service-info and custom-config tests and add startup validation, warning, routing, logging, and migration checks.
  • Document upgrade requirements, new configuration paths, error media type, and request-size semantics.
tests/conftest.py
tests/mock_data.py
tests/ga4gh/registry/test_server.py
tests/ga4gh/registry/test_service_info.py
tests/service_models/test_custom_config.py
tests/test_utils.py
docs/releases/0.3.0.md
README.md

Assessment against linked issues

Issue Objective Addressed Explanation
#104 Upgrade cloud-registry and its deployment artifacts to FOCA 0.15, adapting configuration and application code to FOCA’s replacement features and behavior. ✅
#104 Serve GET /service-info through FOCA using the configured service info while preserving its client-facing behavior, and remove the application’s duplicate implementation and tests. ✅
#104 Configure all error responses to use application/json, remove application/problem+json from the OpenAPI declarations, and verify the media type across error sources. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (753c6d9) to head (f071ccb).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #127   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10         9    -1     
  Lines          775       704   -71     
=========================================
- Hits           775       704   -71     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review October 21, 2026 11:27

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Needs a human reviewer. Setting server.max_content_length to null now lets the app accept request bodies without a size limit; a large or sustained request could exhaust resources and cause an outage before reverting takes effect. The default remains 1 MiB, but this changes a protective boundary for deployments that disable the limit.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

A warning on startup still let `server.max_content_length: null`
remove the size limit of request bodies, so that bodies of any size
(also chunked ones) were read before the access token was checked.
As the removed `custom.max_content_length` and the Helm chart did, the
app now refuses it: `create_app()` raises a RuntimeError. Raised by
Sourcery ("needs a human reviewer").

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery assessment

Approved.

@uniqueg

uniqueg commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

Merged as 792194a. The merge request timed out (HTTP 504), but the squash landed on dev with the same tree as this PR's head (f071ccb); GitHub did not link it to this PR, so I am closing it by hand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build: upgrade to FOCA 0.15

1 participant