Repository navigation
feat: let admins list the registry itself - #349
Conversation
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]>
Reviewer's GuideThis PR introduces an admin-only Sequence diagram for admin self-listingsequenceDiagram
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
Sequence diagram for startup self-listing refreshsequenceDiagram
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
Flow diagram for self-listing lifecycleflowchart 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]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
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]>
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):401without a token,403for other users and without the header.GET200with the statePUT201with the state andLocationif added;200with the state if already listed, entry brought up to date400;409withcodeduplicate-service(andserviceId),service-id-taken,pending-service,service-busyDELETE200with the state404if not listed;409service-busyThe state is
{"listed": true, "service_id": "<id>"}or{"listed": false}.server.public_urlwith the API's base path. It has the service info'sid, 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.400with the reason.service-busy.deleteServiceTypenow sharesremove_service_type(), with the same behaviour.Docs:
docs/api.md,docs/access-control.md,docs/configuration.md,docs/upgrading.md,deployment/README.mdand 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.pywith 100 % coverage ofself_listing.py.tests/test_self_listing.pyagainstmongo:7.0in a container, on the final commit: passed.test_rename,test_service_typesandtest_verificationtoo, before the review fixes: 234 passed.pre-commit run --all-filesandmkdocs build --strict, on the final commit: passed. Version guard: passed.Test (mongomock)with its 100 % coverage gate andTest (MongoDB 7.0).adversarial-reviewerandquality-reviewer, two rounds.Declined review findings
service_idshould beserviceId(quality, medium): kept. Fields the registry adds aresnake_case(service_idofGET /verifications, as the comment onRegistryServiceInfoin the spec says);serviceIdof duplicate conflicts is the exception, and it is kept in the409as it is the shared form of that conflict.RegisterServiceis imported from its module). Races that need a stale read still stub_stored_entry, as no collection-level seam gives the same interleaving.check_id()and fold in reserved identifiers (quality, low): kept;rename.pyrelies 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, ascheck_id()needs a request context.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:
Enhancements:
Deployment:
Documentation:
Tests: