Skip to content

feat: let admins list the registry itself - #349

Merged
uniqueg merged 4 commits into
devfrom
feat/list-registry
Nov 3, 2026
Merged

uniqueg merged 4 commits into
devfrom
feat/list-registry

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Summary

Admins can list the registry among its own services, or remove it, as one backend operation each. UI issue elixir-cloud-aai/cloud-registry-ui#201 builds on this.

All three operations are at /ga4gh/registry/v1/service-info/listing, for admins in admin mode only (X-Request-Roles: admin): 401 without a token, 403 for other users and without the header.

Request Success Errors
GET 200 with the state
PUT 201 with the state and Location if added; 200 with the state if already listed, entry brought up to date 400; 409 with code duplicate-service (and serviceId), service-id-taken, pending-service, service-busy
DELETE 200 with the state 404 if not listed; 409 service-busy

The state is {"listed": true, "service_id": "<id>"} or {"listed": false}.

  • Entry: built from the service info and server.public_url with the API's base path. It has the service info's id, no owner and no role on it, counts for nobody's service limit, and is verified. An internal marker (_selfEntry, not served, sparse index) identifies it; updates and renames keep it.
  • Environment and URL scheme: checked as for registrations, so values that aren't allowed return 400 with the reason.
  • Service type: added on the fly and approved; on removal, removed unless other services have it.
  • Stays current: while listed, the app brings the entry up to date on startup, writing only if it differs. A failure to do so is a warning and doesn't stop the app. The verification stays, renewed if the URL or API type changes.
  • Atomicity without transactions: the type is stored first, then the entry in one write, then the type again in case it was removed concurrently. A failure removes a type the operation added. Removal revokes roles first, so that a failure there can be repeated. Identifiers are checked again under the service lock, so a rename in between returns service-busy.
  • GA4GH API: requests and responses are unchanged; the entry is served like any other service. deleteServiceType now shares remove_service_type(), with the same behaviour.

Docs: docs/api.md, docs/access-control.md, docs/configuration.md, docs/upgrading.md, deployment/README.md and the 1.0.0rc2 release notes.

Closes #347

How it was verified

  • coverage run --source cloud_registry,scripts -m pytest, mongomock, on the first commit of the branch: 2015 passed, 11 skipped. After the review fixes: tests/test_self_listing.py with 100 % coverage of self_listing.py.
  • tests/test_self_listing.py against mongo:7.0 in a container, on the final commit: passed. test_rename, test_service_types and test_verification too, before the review fixes: 234 passed.
  • pre-commit run --all-files and mkdocs build --strict, on the final commit: passed. Version guard: passed.
  • CI on the final commit: all jobs passed, including Test (mongomock) with its 100 % coverage gate and Test (MongoDB 7.0).
  • adversarial-reviewer and quality-reviewer, two rounds.

Declined review findings

  • service_id should be serviceId (quality, medium): kept. Fields the registry adds are snake_case (service_id of GET /verifications, as the comment on RegistryServiceInfo in the spec says); serviceId of duplicate conflicts is the exception, and it is kept in the 409 as it is the shared form of that conflict.
  • Tests stub private helpers (quality, medium): partly fixed (RegisterService is imported from its module). Races that need a stale read still stub _stored_entry, as no collection-level seam gives the same interleaving.
  • Move check_id() and fold in reserved identifiers (quality, low): kept; rename.py relies on the spec's pattern, which doesn't apply to an identifier from the config. The docstring and message are generalised.
  • _new_entry_id() docstring should say app context (quality, low): kept, as check_id() needs a request context.
  • Entry isn't checked against request length limits (adversarial, low): documented in docs/api.md, not enforced. The service info is the deployment's own config, and refusing would add schema validation for a case that only affects sending the entry back by hand.

Open questions

None for this PR; the design choices are in the report to the maintainer.

🤖 Generated with Claude Code

Summary by Sourcery

Enable administrators to add, update, inspect, and remove the registry’s own service listing while keeping it consistent with the deployment configuration.

New Features:

  • Add admin-only GET, PUT, and DELETE operations for listing the registry itself as a discoverable service.
  • Keep the self-listed registry entry synchronized with service information and deployment URL changes.

Enhancements:

  • Preserve self-listing metadata through service updates and renames, including verified status and service-limit exemptions.
  • Improve service-type removal reuse and safely handle concurrent listing, removal, and rename operations.

Deployment:

  • Document deployment and upgrade considerations for enabling registry self-listing.

Documentation:

  • Document the self-listing API, access control, configuration behavior, and release changes.

Tests:

  • Add comprehensive coverage for self-listing lifecycle, validation, concurrency, synchronization, and failure handling.

uniqueg and others added 3 commits November 3, 2026 22:02
Add `GET`, `PUT` and `DELETE /service-info/listing`, for admins, to tell
whether the registry is listed among its services, to add it, and to
remove it. The entry is built from the service info and the public URL
with the API's base path, keeps a marker field, which isn't served, on
updates and renames, has no owner, counts for nobody's service limit and
is verified. While listed, the app brings it up to date on startup.

The service type is added on the fly, and removed with the entry unless
other services have it. Without transactions, the type is stored first,
removed again if storing the entry fails, and stored once more after it,
so that no entry stays without its type. A pending type is refused, as
listing must not approve services of other users.

Closes #347

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Revoke roles before the entry is deleted, so that a failure leaves it
listed and the request can be repeated. Check the entry's identifier
again under its lock, so that a rename in between returns `service-busy`
instead of a wrong `404` or `duplicate-service`. Log a listing only when
the entry was added. Document the remaining limits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Bring the entry up to date from the document read once it is locked, so
that a change just before the lock isn't missed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg added this to the v1.0.0-rc2 milestone Nov 3, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This PR introduces an admin-only /service-info/listing API that registers the registry itself as a verified, ownerless service, maintains its entry and service type across updates, renames, restarts, and concurrent operations, and documents and tests the complete lifecycle.

Sequence diagram for admin self-listing

sequenceDiagram
    actor Admin
    participant API
    participant SelfListing
    participant Services
    participant ServiceTypes

    Admin->>API: PUT /ga4gh/registry/v1/service-info/listing
    API->>SelfListing: putSelfListing()
    SelfListing->>SelfListing: _entry_data()
    SelfListing->>SelfListing: _new_entry_id()
    SelfListing->>Services: changing(service_id)
    SelfListing->>ServiceTypes: store_service_type()
    ServiceTypes-->>SelfListing: approved type
    SelfListing->>Services: _insert() or _refresh()
    Services-->>SelfListing: entry stored or updated
    SelfListing->>ServiceTypes: store_service_type()
    SelfListing-->>API: 201 or 200 SelfListing
    API-->>Admin: listing state and optional Location
Loading

Sequence diagram for startup self-listing refresh

sequenceDiagram
    participant App
    participant SelfListing
    participant Services
    participant ServiceTypes

    App->>SelfListing: refresh_self_listing()
    SelfListing->>Services: _stored_entry()
    Services-->>SelfListing: self entry
    SelfListing->>SelfListing: _entry_data()
    SelfListing->>ServiceTypes: is_pending()
    ServiceTypes-->>SelfListing: type status
    SelfListing->>Services: _refresh()
    Services-->>SelfListing: entry updated or unchanged
    SelfListing-->>App: warning on validation or conflict, startup continues
Loading

Flow diagram for self-listing lifecycle

flowchart LR
    Admin[Admin] -->|PUT /service-info/listing| Validate[RegisterService.validate]
    Validate --> StoreType[store_service_type]
    StoreType --> StoreEntry[_insert or _refresh]
    StoreEntry --> Verify[Verified ownerless self entry]
    Verify --> Listed[GET /services serves entry]
    Listed -->|App startup| Refresh[refresh_self_listing]
    Listed -->|DELETE /service-info/listing| Revoke[remove_permissions]
    Revoke --> RemoveEntry[Delete self entry]
    RemoveEntry --> RemoveType[remove_service_type]
Loading

File-Level Changes

Change Details Files
Adds admin-only self-listing operations and models the registry entry as a managed service.
  • Defines GET, PUT, and DELETE behavior, response schemas, authorization expectations, conflict codes, and documentation.
  • Builds the entry from configured service info and public URL, with no owner, no service-limit accounting, verified status, and an internal marker hidden from API responses.
  • Supports idempotent listing, removal, renames, stale-role cleanup, service-type lifecycle, and startup reconciliation.
cloud_registry/api/additions.openapi.yaml
cloud_registry/ga4gh/registry/self_listing.py
cloud_registry/ga4gh/registry/service.py
cloud_registry/app.py
cloud_registry/config.yaml
cloud_registry/ga4gh/registry/rename.py
cloud_registry/ga4gh/registry/service_types.py
Implements race-safe, transaction-free coordination between self-listing entries, service types, and concurrent service mutations.
  • Uses service locks, repeated identifier checks, duplicate-key handling, and compensating cleanup for partial failures.
  • Preserves the internal marker across service updates and renames, and shares service-type removal behavior with the existing delete endpoint.
  • Adds a sparse database index to locate the self entry efficiently.
cloud_registry/ga4gh/registry/self_listing.py
cloud_registry/ga4gh/registry/service.py
cloud_registry/ga4gh/registry/service_types.py
cloud_registry/config.yaml
Adds broad behavioral coverage and updates operational and API documentation.
  • Tests authorization, success and error responses, validation, duplicates, pending types, concurrency, cleanup, renames, refresh behavior, verification, and startup reconciliation.
  • Documents endpoint usage, lifecycle semantics, deployment/configuration implications, upgrade handling, and release notes.
tests/test_self_listing.py
docs/api.md
docs/access-control.md
docs/configuration.md
docs/upgrading.md
deployment/README.md
docs/releases/1.0.0rc2.md

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 Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (8b83f1e) to head (5656db4).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##               dev      #349    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           22        23     +1     
  Lines         2436      2625   +189     
==========================================
+ Hits          2436      2625   +189     

☔ 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 November 3, 2026 21:20

@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 4 issues

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

## Individual Comments

### Comment 1
<location path="cloud_registry/ga4gh/registry/self_listing.py" line_range="371-373" />
<code_context>
+                _remove_unused_type(service_type)
+            raise
+        # also if the type was removed concurrently, as a service has it now
+        store_service_type(service_type)
+        # if it was removed and added again as pending meanwhile
+        sync_pending_flag(service_id, service_type)
+    return created
+
</code_context>
<issue_to_address>
**Unlisting leaves an orphaned type**

When an admin's `PUT /service-info/listing` and `DELETE /service-info/listing` overlap while the entry is already listed, `changing()` allows concurrent changes to the same service, so a `PUT` can refresh the entry and pause before its final `store_service_type()` while `DELETE` removes the entry and its now-unused type. The `PUT` then recreates the type and returns success, leaving the registry unlisted but its service type stored.

Serialize listing mutations with a per-entry exclusive lock, or otherwise coordinate the final type write with deletion.

Also at `cloud_registry/ga4gh/registry/self_listing.py:483-485`.
</issue_to_address>

### Comment 2
<location path="cloud_registry/ga4gh/registry/self_listing.py" line_range="368" />
<code_context>
+                raise NotFound
+        except Exception:
+            if added:
+                _remove_unused_type(service_type)
+            raise
+        # also if the type was removed concurrently, as a service has it now
</code_context>
<issue_to_address>
**Rollback deletes a replacement type**

When a type is removed and re-added as pending between `_store()` adding it and checking `is_pending()`, `_store()` treats `added` as proof that the currently stored type is still its own. If another admin deletes that type and a user registers it again as pending before the pending check, `_store()` refuses the listing and `_remove_unused_type()` deletes the replacement type too, losing the user's newly registered type.

Make rollback conditional on the type document still being the approved document created by this operation, or coordinate type deletion and listing so rollback cannot remove a replacement.

Also at `cloud_registry/ga4gh/registry/service_types.py:694-720`.
</issue_to_address>

### Comment 3
<location path="cloud_registry/ga4gh/registry/self_listing.py" line_range="515" />
<code_context>
+        if is_pending(type_document(service.data["type"])):
+            raise PendingSelfListing
+        _refresh(service, stored, key)
+    except (InvalidService, DuplicateService, PendingSelfListing) as exc:
+        logger.warning(
+            "Entry of the registry among its services not updated: %s",
</code_context>
<issue_to_address>
**Transient refresh failures abort startup**

When a database operation during startup refresh fails transiently after earlier startup database checks succeeded, a transient MongoDB error from `service.validate()`, `is_pending()` or `_refresh()` escapes `refresh_self_listing()` because only validation conflicts and `DuplicateKeyError` are caught; `create_app()` then fails to boot the worker instead of logging a warning and continuing.

Handle transient refresh/database errors according to the intended best-effort startup behavior, logging them without aborting app creation.
</issue_to_address>

### Comment 4
<location path="cloud_registry/ga4gh/registry/self_listing.py" line_range="191" />
<code_context>
+    info = get_service_info()
+    data = {field: info[field] for field in ENTRY_FIELDS if field in info}
+    data["organization"] = {
+        field: info["organization"][field] for field in sorted(ORGANIZATION_FIELDS)
+    }
+    public_url = str(get_config().server.public_url).rstrip("/")
</code_context>
<issue_to_address>
**Optional organization fields crash listing**

When the configured organization omits an optional field such as `url` or `name`, `_entry_data()` indexes every field in `ORGANIZATION_FIELDS`, so the missing field raises `KeyError`. PUT returns a server error, and startup refresh can fail before its warning handler.

Build the organization data using only fields present in the configured organization.
</issue_to_address>

Linked issues

#347 feat: let admins list the registry itself · 10 of 10 met

# Requirement Status Notes
1 Provide admin-only operations to add or remove the registry, and expose whether it is listed. ✅ Met GET, PUT, and DELETE are defined at /service-info/listing; the endpoint is admin-only.
2 Build the entry from the service info and public URL with the API base path; add its service type if missing. ✅ Met The entry data uses the configured service info and public URL, and the type is stored as part of listing.
3 Refuse listing with a clear error if the registry's environment is not allowed. ✅ Met The entry is validated with the same environment checks as service registrations.
4 Remove the entry and remove its service type unless other services use it. ✅ Met Unlisting removes the type through remove_service_type(), which preserves types still in use.
5 Make adding and removing one backend operation so separate client calls cannot leave the entry and type inconsistent. ✅ Met Listing coordinates type storage, entry storage, and cleanup; unlisting revokes roles before deleting the entry and then removes an unused type.
6 Ensure the entry has no personal owner and counts as verified. ✅ Met The entry is stored with no creator and a verification timestamp.
7 Refresh the entry at startup so its version and description follow the service info. ✅ Met create_app() calls refresh_self_listing() during startup.
8 Expose whether the registry is listed for the UI's button. ✅ Met GET returns the listed state and, when listed, the entry identifier.
9 Design the endpoint against the service registry specification and existing rename and service-type rules. ✅ Met The endpoint is specified in OpenAPI, preserves the self-entry marker across service updates and renames, and handles pending types and rename races.
10 Implement the feature with tests and documentation. ✅ Met The change adds implementation and tests, and updates the API, access-control, configuration, upgrading, deployment, and release documentation.

Sourcery assessment

Needs a human reviewer. 4 findings to address first, and a mistaken listing can leave a registry service record and service type in the database, publicly served as verified; reverting the code does not remove them. The record can be removed or corrected, so the persisted effect is repairable.

Blocking findings: cloud_registry/ga4gh/registry/self_listing.py:373, cloud_registry/ga4gh/registry/self_listing.py:368, cloud_registry/ga4gh/registry/self_listing.py:515, cloud_registry/ga4gh/registry/self_listing.py:191


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

Check whether the type is pending before the rollback can apply: a type
this operation added isn't pending, so a pending one was removed and
added again by a user, and must stay.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 4a3b2e4 into dev Nov 3, 2026
32 checks passed
@uniqueg
uniqueg deleted the feat/list-registry branch November 3, 2026 21:42
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.

feat: let admins list the registry itself

1 participant