Skip to content

refactor!: use FOCA 0.18 features - #261

Merged
uniqueg merged 13 commits into
devfrom
refactor/foca-0-18
Oct 27, 2026
Merged

uniqueg merged 13 commits into
devfrom
refactor/foca-0-18

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Summary

This PR upgrades the app to FOCA 0.18 and replaces the app's own copies of features that FOCA now provides.

FOCA is pinned to the release foca>=0.18.0,<0.19 (pyproject.toml), and the base image to elixircloud/foca:0.18.0-py3.13, pinned by digest. The merge conditions hold:

  • FOCA v0.18.0 is released, and the pins are switched to the release.
  • v0.5.0 of this repo is tagged. This PR targets 0.6.0.

Closes #226

What changes

  • Problem details:
    • Validation errors now get their details from FOCA (exceptions.validation_details: true).
    • problem() is now a thin wrapper around FOCA's problem_response(). It only adds the codes of conflicts (feat: tell 409 conflicts apart #247), so it stays rather than being deleted as the issue proposed.
    • MAX_DETAIL_LENGTH, shorten_detail() (FOCA's is used), validation_problem(), and the handler and logger setup in create_app() are deleted.
    • The tests use locked_enforcer() instead of get_enforcer().
  • Startup checks:
    • FOCA now does these: the group claim and group mapping checks (as ValueError), require_admin (moved from custom.access_control.require_admin to security.access_control.require_admin), the placeholder service info warning, and require_no_service_clients().
    • Deleted: check_admin_groups(), check_no_service_clients(), warn_placeholder_service_info() and the PLACEHOLDER_* constants.
    • custom.access_control stays, unlike in the issue text: it also holds service_types and max_unused_service_types, which were added after the issue was written. Only require_admin moves.
    • The chart reads require_admin from its new place and rejects the old key.
  • Public URL and typed custom config:
    • server.public_url replaces custom.endpoints.service; ServiceConfig, get_public_url() and _format_host() are deleted.
    • create_app() refuses to start without server.public_url.
    • Location headers come from FOCA's get_public_url().
    • foca.get_custom_config(CustomConfig) replaces the app's own.
    • The chart sets the public URL from hostName (https://<hostName>/) or the new publicUrl value. publicUrl is in the values schema, with a pattern for http(s) URLs without query or fragment. The chart rejects config.custom.endpoints.service.
    • The chart now generates an empty custom: {}, so that config.custom: null still works.
  • Gunicorn: the image runs with --config python:foca.gunicorn_config (same settings). cloud_registry/gunicorn_config.py and its tests are deleted; tests of the image command and the health-check port remain.
  • Docs:
    • docs/upgrading.md has a new section "From 0.5.0", and deployment/README.md a new section "To app version 0.6.0". Both cover the breaking changes and the behaviour differences listed in the issue, plus response-validation errors, which are now logged.
    • The chart README names the required image version.
    • Configuration docs are updated for the public URL, the server settings and require_admin.

Verification

  • Full suite on MongoDB 7.0.34, with Helm 3.19 installed locally so the chart tests ran too: 1473 passed, coverage 100%. After the review fixes: 184 chart tests and the app/config tests passed.
  • Full suite on mongomock: passed.
  • ruff check, ruff format, mypy cloud_registry tests: clean.
  • mkdocs build --strict: clean.
  • pre-commit run --all-files: passed.
  • scripts/check_release_pins.py reported both dev pins, as intended; with the release pins, it passes.
  • With the release pins (FOCA 0.18.0 from PyPI): full suite on MongoDB 7.0.34, 1594 passed, coverage 100%.
  • Reviews: two rounds with the adversarial and quality reviewer subagents. No high findings. The medium one (the chart README's image compatibility) is fixed, and so are most of the lows: chart tests for publicUrl and hostName, publicUrl validation, docstrings, dev overlay order, and the upgrade notes on response-validation logs and the pre-0.4.0 step.

Declined review findings

  • The chart's admin check counts only group mappings and only accepts issuers given as strings, while FOCA 0.18 also counts policies rules and accepts issuer objects. The README now says to set require_admin: false when only rules grant admin. Issuer objects belong to feat: support several token issuers #257 (several token issuers).
  • Shared constants for code strings and an explicit code for plain conflicts: FOCA's problem_response() sends the mapped code. A comment and tests/test_conflicts.py guard this.
  • Validating config.server.public_url overrides in the chart: FOCA validates it at startup, and the schema covers publicUrl.
  • foca-common stays at 0.2.0 for now. Its schema $comment still mentions FOCA 0.17 until a library release for 0.18 exists.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Upgrade the application to FOCA 0.18 and migrate shared configuration, validation, startup checks, URL handling, and Gunicorn behavior to the library.

Enhancements:

  • Adopt FOCA 0.18 for shared problem handling, startup validation, public URL management, typed custom configuration, and container Gunicorn settings.
  • Move public URL and admin requirement configuration to FOCA-managed settings and update the Helm chart to generate and validate the new configuration.
  • Remove application-owned configuration, validation, startup-check, URL-building, and Gunicorn code now provided by FOCA.

Build:

  • Pin the Python dependency and container base image to FOCA 0.18.

Deployment:

  • Update Helm deployment configuration and compatibility checks for FOCA 0.18, including public URL configuration and the relocated admin requirement.

Documentation:

  • Document the configuration and deployment changes required when upgrading from app version 0.5.0 to 0.6.0.

Tests:

  • Update application, chart, configuration, and image tests for FOCA 0.18 behavior and interfaces.

uniqueg and others added 9 commits October 26, 2026 17:09
Validation details come from FOCA (exceptions.validation_details), and
problem() builds on FOCA's problem_response(), adding only the codes of
conflicts. Tests use locked_enforcer() instead of the removed
get_enforcer().

Refs #226

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FOCA checks the group settings, requires admins
(security.access_control.require_admin, moved from
custom.access_control.require_admin), warns of placeholders in the
service info and refuses service clients
(require_no_service_clients()); the app's own copies are removed. The
chart reads require_admin from its new place and rejects the old key.

Refs #226

Co-Authored-By: Claude Opus 5.5 <[email protected]>
server.public_url replaces custom.endpoints.service; the app refuses to
start without it, and FOCA's get_public_url() builds the Location
header. The chart sets it from hostName or the new value publicUrl and
rejects the old key. FOCA's get_custom_config() replaces the app's.

Refs #226

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The image loads foca.gunicorn_config (same settings);
cloud_registry.gunicorn_config is removed. Tests keep the checks of
the image command and its health check port.

Refs #226

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Chart docs name the required image version, tests render publicUrl,
docstrings and the dev overlay are clearer.

Refs #226

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

sourcery-ai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This PR upgrades the application to FOCA 0.18 and refactors duplicated configuration, error handling, startup validation, URL, and Gunicorn functionality to use FOCA's implementations, while migrating the Helm chart, documentation, and comprehensive test suite to the new 0.6.0 configuration contract.

Sequence diagram for FOCA-backed application startup

sequenceDiagram
    participant Gunicorn
    participant App as cloud_registry.app
    participant FOCA
    participant Config

    Gunicorn->>App: create_app()
    App->>FOCA: Foca.create_app()
    FOCA->>Config: validate config and startup checks
    FOCA-->>App: configured Connexion app
    App->>FOCA: require_no_service_clients()
    App->>Config: check server.public_url
    App-->>Gunicorn: ready app or startup error
Loading

Sequence diagram for FOCA problem response handling

sequenceDiagram
    participant Request
    participant App as cloud_registry app
    participant Problem as problem()
    participant FOCA

    Request->>App: HTTP request
    App->>Problem: problem(exception)
    Problem->>FOCA: problem_response(exception, extensions)
    FOCA-->>Problem: problem details response
    Problem-->>Request: JSON error response
Loading

Flow diagram for Helm public URL configuration

flowchart TD
    Values[Helm values]
    Choice{publicUrl set?}
    Explicit[server.public_url = publicUrl]
    Host[server.public_url = https://hostName/]
    Render[Rendered config]
    Reject[Reject removed legacy keys]

    Values --> Choice
    Choice -->|yes| Explicit
    Choice -->|no| Host
    Explicit --> Render
    Host --> Render
    Values --> Reject
Loading

File-Level Changes

Change Details Files
Upgrade the FOCA dependency and container base image to 0.18, adopting FOCA-provided configuration, startup validation, error handling, URL construction, typed custom-config access, and Gunicorn settings.
  • Pin Python and image dependencies to the FOCA 0.18 release.
  • Delegate validation problem details, URL generation, detail shortening, startup checks, and service-client rejection to FOCA.
  • Replace untyped custom-config helpers with foca.get_custom_config(CustomConfig) and remove duplicated models and utilities.
  • Run Gunicorn with foca.gunicorn_config and delete the app-owned configuration module.
Dockerfile
pyproject.toml
cloud_registry/app.py
cloud_registry/exceptions.py
cloud_registry/ga4gh/registry/permissions.py
cloud_registry/ga4gh/registry/server.py
cloud_registry/ga4gh/registry/service.py
cloud_registry/ga4gh/registry/service_info.py
cloud_registry/ga4gh/registry/service_types.py
cloud_registry/ga4gh/registry/verification.py
cloud_registry/gunicorn_config.py
cloud_registry/service_models/custom_config.py
cloud_registry/utils.py
tests/test_exceptions.py
tests/test_image_command.py
tests/test_gunicorn_config.py
Migrate public URL and access-control configuration to FOCA's schema and enforce the new startup requirements.
  • Replace custom.endpoints.service with required server.public_url, using FOCA for Location headers and URL validation.
  • Move require_admin to security.access_control.require_admin; remove the app's duplicate group and placeholder checks.
  • Update development and test overlays for the required public URL and typed FOCA configuration.
cloud_registry/config.yaml
config.dev.yaml
tests/config_overlay.yaml
tests/conftest.py
tests/mock_data.py
tests/test_app.py
tests/test_config.py
Update the Helm chart to generate, validate, and document the FOCA 0.18 configuration contract.
  • Generate server.public_url from publicUrl or hostName and preserve null-custom-config behavior with an empty custom mapping.
  • Reject removed custom configuration keys and validate public URL and admin settings during rendering.
  • Update chart schema, values, deployment documentation, upgrade guidance, and compatibility requirements.
deployment/templates/_helpers.tpl
deployment/values.schema.json
deployment/values.yaml
deployment/README.md
tests/test_chart.py
Revise application documentation and tests for FOCA-owned behavior and the 0.6.0 breaking configuration changes.
  • Document migration from 0.5.0, changed startup checks, response-validation logging, public URLs, server settings, and the new admin key.
  • Adapt access-control, service, service-info, conflict, and configuration tests to FOCA APIs and behavior.
  • Remove obsolete tests for deleted helpers and add image-command and chart coverage for the new integration.
docs/upgrading.md
docs/configuration.md
docs/reference.md
tests/test_access_control.py
tests/ga4gh/registry/test_service.py
tests/ga4gh/registry/test_service_info.py
tests/test_conflicts.py
tests/test_service_types.py
tests/test_utils.py
tests/test_image_command.py

Assessment against linked issues

Issue Objective Addressed Explanation
#226 Upgrade the app to FOCA 0.18 and replace the app's duplicate Gunicorn settings, startup checks, typed custom-config access, public-URL handling, and problem-details behavior with FOCA's shared features. ✅
#226 Update the app configuration and Helm chart for the new FOCA settings, including server.public_url and security.access_control.require_admin, and reject obsolete configuration keys with upgrade guidance. ✅
#226 Update tests and documentation to cover the new behavior and explain the breaking changes and upgrade path. ✅

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 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (4e2c9fe) to head (b20fac6).

Additional details and impacted files
@@            Coverage Diff             @@
##               dev      #261    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           20        19     -1     
  Lines         1975      1862   -113     
==========================================
- Hits          1975      1862   -113     

☔ 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 mentioned this pull request Oct 27, 2026
3 tasks done
Replace the temporary pins of the FOCA dev commit and its dev image
by the release (PyPI and the 0.18.0-py3.13 image, by digest).

Refs #226

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg marked this pull request as ready for review October 27, 2026 02:47

@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 found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="deployment/templates/_helpers.tpl" line_range="151" />
<code_context>
-{{- end -}}
 {{- if and (eq $requireAdmin "true") (not (has "admin" (values $mapping))) -}}
-{{- fail "config.security.access_control.group_mapping must map a group to the role admin (e.g., the admin group of the identity provider), or set config.custom.access_control.require_admin to false" -}}
+{{- fail "config.security.access_control.group_mapping must map a group to the role admin (e.g., the admin group of the identity provider), or set config.security.access_control.require_admin to false" -}}
 {{- end -}}
 {{- $_ := required "hostName must be set" .Values.hostName -}}
</code_context>
<issue_to_address>
**Operators cannot disable admin check**

When no group mapping grants `admin` while `require_admin` remains true, `$requireAdmin` and `$mapping` trigger the validation failure, whose message recommends the removed `config.custom.access_control.require_admin` key; the chart rejects that key, so operators following the message still cannot render the chart.

Update the failure message to name a supported way to disable the admin requirement.
</issue_to_address>

### Comment 2
<location path="tests/test_image_command.py" line_range="22" />
<code_context>
+    Without preloading the app, so that each worker creates it after
+    forking (MongoDB clients must not be shared across forks).
+    """
+    assert image_command()[:3] == [
+        "gunicorn",
+        "--config",
</code_context>
<issue_to_address>
**Extra Gunicorn overrides go unnoticed**

When the Docker command adds `--workers 2` after its config argument, `test_image_command` checks only the first three command elements, then checks the app URI and `preload_app`; adding `--workers 2` after the config argument still passes, although the image no longer uses FOCA's default worker settings.

Assert the complete expected image command, or assert the worker setting as well.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: deployment/templates/_helpers.tpl:151, tests/test_image_command.py:22


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

Comment thread deployment/templates/_helpers.tpl Resolved
Comment thread tests/test_image_command.py Resolved

@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 merged commit 6e1d43c into dev Oct 27, 2026
19 checks passed
@uniqueg
uniqueg deleted the refactor/foca-0-18 branch October 27, 2026 03:35
uniqueg added a commit to elixir-cloud-aai/protes that referenced this pull request Oct 29, 2026
Upgrade to FOCA 0.18 (foca>=0.18.0,<0.19, base image 0.18.0-py3.13)
and replace proTES's copies of what FOCA now provides, as Cloud
Registry did (elixir-cloud-aai/cloud-registry#261):

- require_admin moves from custom.access_control to FOCA's
  security.access_control.require_admin; the old key stops the app
  and the chart with a hint
- FOCA's startup checks replace the admin and group claim checks and
  the placeholder warning of the service info; proTES keeps its check
  of enforced access control and the warning without user groups
- service clients are refused by require_no_service_clients()
- the image runs Gunicorn with foca.gunicorn_config (same settings);
  pro_tes.gunicorn_config is gone
- foca.get_custom_config(CustomConfig) replaces proTES's own
- validation details are set explicitly (FOCA's new default)

Tests apply rules changed in the database directly with
mark_changed(), and the docs tell operators to restart proTES after
such changes (FOCA 0.18 caches the enforcer).

BREAKING CHANGE: custom.access_control.require_admin is now
security.access_control.require_admin; the image loads
foca.gunicorn_config; rejected requests get the validation reason as
detail.

Closes #331

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

refactor!: use the shared FOCA 0.18 features

1 participant