Skip to content

feat!: return 201 Created for new services - #110

Merged
uniqueg merged 4 commits into
devfrom
feat/created-location
Oct 20, 2026
Merged

uniqueg merged 4 commits into
devfrom
feat/created-location

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Summary

New services are answered with 201 Created (#78).

  • Status codes: POST /services returns 201 with a Location header pointing to the new service; PUT /services/{serviceId} returns 201 with Location when it registers a new service, and 200 when it replaces one. The body is still the service identifier. Errors are unchanged (no Location; the owner rollback still returns 400/500).
  • Public URLs: one helper, get_public_url(), builds them from custom.endpoints.service (never from the request's Host), the proxy prefix api_path, the app's root path and the percent-encoded path. IPv6 hosts are bracketed (zone IDs encoded). The Location path is the collection path of the request plus the identifier, so it keeps the API base path.
  • Identifiers . and .. (also percent-encoded) are rejected on PUT (400), as clients would resolve their URLs elsewhere; generated identifiers can't be dot segments, and ID character sets with / or only dots are rejected at startup.
  • Docker Compose: config.dev.yaml sets the public URL to http://localhost:8080, so that Location headers work locally.
  • Spec (additions.openapi.yaml; GA4GH spec untouched): 201 response ServiceCreated with Location, shared ServiceId schema, PUT 200 (updated) and 201.
  • Docs: README paragraph on the status codes and a "Public URLs" section (Helm sets them from host_name; other deployments must configure them).
  • UI (cloud-registry-ui at f9d048f): no change needed; createService, createServiceWithId and updateService check response.ok and only use the returned identifier.

Closes #78.

Breaking changes

  • POST /services, and PUT /services/{serviceId} for new services, return 201 Created instead of 200 OK.
  • PUT /services/. and PUT /services/.. return 400; services registered with these identifiers before can be read and deleted, but must be registered again to be updated.

Verification

  • pytest: 243 passed, 100% coverage. New tests: 201 and Location for POST and PUT (followed to GET), 200 without Location for replacements, no Location on errors (400, 409, rollback), proxy prefixes and encoding, dot identifiers, public URL building (prefixes, slashes, encoding, IPv6 hosts and zones).
  • ruff check, ruff format --check, mypy cloud_registry tests: clean. ast-grep scan: clean. gitleaks dir .: no leaks.
  • Reviews (adversarial + quality, 2 rounds): fixed: Compose public URL, dot identifiers, IPv6 hosts (bracketing, zone IDs, not for hosts with ports), Location path from the collection path, test structure (literal expected URLs, one Location assertion), spec schema, README section. Declined: deriving expected URLs in tests from the config (literal values were preferred in round 1, so tests don't share the implementation's logic); a startup warning for the unreachable default host (documented instead).
  • CI: all checks pass (tests on Python 3.10 and 3.12, Helm chart, Docker Compose, static analysis, Read the Docs, Codecov).
  • Sourcery: 2 findings, both fixed in 6580335 (ID character sets with / or only dots rejected, generated ./.. replaced; bracketed IPv6 hosts with zone IDs); 243 tests, 100% coverage, CI green again.

Open questions

None.

🤖 Generated with Claude Code

uniqueg and others added 3 commits October 20, 2026 20:30
`POST /services` returns `201 Created` with a `Location` header
pointing to the new service, and `PUT /services/{serviceId}` returns
`201` with `Location` when it creates a service and `200` when it
replaces one. The body is still the service ID.

Public URLs are built by one helper, `get_public_url()`, from
`custom.endpoints.service`, the proxy prefix `api_path`, the script
root and the percent-encoded request path.

Closes #78

BREAKING CHANGE: `POST /services`, and `PUT /services/{serviceId}`
for new services, return `201` instead of `200`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reject the service IDs `.` and `..` (also percent-encoded), whose
`Location` clients would resolve elsewhere, bracket IPv6 hosts in
public URLs, and build the `Location` path from the collection path
passed by the controllers. Set public URLs for Docker Compose
(`http://localhost:8080`) and document them in a "Public URLs" section.
Share a `ServiceId` schema in the spec and tidy up the tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Bracket only hosts that are IPv6 addresses, with percent-encoded zone
IDs (RFC 6874), so that misconfigured hosts with ports aren't
bracketed. Derive the collection path of PUT requests by removing the
service ID, add a type alias for registration responses, explain the
ID pattern, and document that services registered with the IDs `.` or
`..` must be registered again to be updated.

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

sourcery-ai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Service registration now returns RESTful creation responses (201 Created plus a configuration-derived Location) while retaining 200 for replacements, with centralized URL construction, dot-segment validation, OpenAPI updates, tests, and deployment documentation.

Sequence diagram for service registration responses

sequenceDiagram
    participant Client
    participant API
    participant Registry
    participant Config

    Client->>API: POST /services or PUT /services/{serviceId}
    API->>Registry: _register_service(collection_path, service_id)
    alt New service
        Registry->>Config: get_public_url(path)
        Config-->>Registry: Location URL
        Registry-->>API: serviceId, 201, Location
        API-->>Client: 201 Created + identifier + Location
    else Existing service replacement
        Registry-->>API: serviceId
        API-->>Client: 200 OK + identifier
    end
Loading

Flow diagram for service identifier validation

flowchart TD
    Request["PUT /services/{serviceId}"] --> Validate{serviceId is . or ..?}
    Validate -->|Yes| BadRequest["400 Bad Request"]
    Validate -->|No| Register["Register or replace service"]
    Register --> Response["201 for new service; 200 for replacement"]
Loading

File-Level Changes

Change Details Files
Changed service registration responses to distinguish creation from replacement and expose the created resource URL.
  • Return 201 Created with a Location header for new POST and PUT registrations.
  • Continue returning 200 OK without Location for PUT replacements and preserve existing error/rollback behavior.
  • Build the response tuple and public URL from the request collection path and registered identifier.
cloud_registry/ga4gh/registry/server.py
tests/ga4gh/registry/test_server.py
tests/test_access_control.py
tests/test_app.py
Added centralized, configuration-driven construction of public service URLs.
  • Compose URLs from the configured service endpoint, proxy prefix, application root path, and percent-encoded resource path.
  • Normalize slashes and correctly format IPv6 hosts, including encoded zone identifiers.
  • Avoid deriving public URLs from the incoming request host.
cloud_registry/utils.py
tests/test_utils.py
Updated API validation and OpenAPI documentation for creation responses and safe identifiers.
  • Document shared ServiceId and ServiceCreated schemas with a URI Location header.
  • Document distinct PUT 200 update and 201 create responses.
  • Reject . and .. service identifiers while allowing other dotted identifiers.
cloud_registry/api/additions.openapi.yaml
tests/test_app.py
Documented public URL configuration and updated local development defaults.
  • Explain status-code changes, dot-identifier behavior, proxy api_path semantics, and deployment configuration requirements.
  • Configure Docker Compose development URLs as http://localhost:8080.
README.md
config.dev.yaml

Assessment against linked issues

Issue Objective Addressed Explanation
#78 Update the additions API contract so POST creation returns 201 with a Location header while retaining the identifier body, and PUT distinguishes creation (201) from replacement (200). ✅
#78 Implement the matching controller behavior, including a Location URL that resolves to the created service and distinguishing PUT create versus replace. ✅
#78 Add tests and documentation for the new response contract, and ensure client compatibility is checked. ✅

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

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #110   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            8         8           
  Lines          462       492   +30     
=========================================
+ Hits           462       492   +30     

☔ 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 20, 2026 19:18

@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="cloud_registry/utils.py" line_range="56" />
<code_context>
+    conf = get_custom_config().endpoints.service
+    host = _format_host(conf.external_host)
+    # `api_path` is configured as it appears in URLs, so it isn't encoded
+    parts = (conf.api_path, quote(request.script_root + path))
+    url_path = "/".join(filter(None, (part.strip("/") for part in parts)))
+    return f"{conf.url_prefix}://{host}:{conf.external_port}/{url_path}"
</code_context>
<issue_to_address>
**Generated IDs break returned links**

When the configured ID charset and length can generate `/`, `.` or `..`, `get_public_url` leaves `/` as a path separator, while clients normalize `.` and `..` path segments. The returned `Location` then points to a different path, so clients cannot retrieve the newly registered service there.

Encode generated IDs as individual path segments and reject `.` and `..` before registering the service.

Also at `cloud_registry/ga4gh/registry/server.py:196-197`, `cloud_registry/api/additions.openapi.yaml:118`.
</issue_to_address>

### Comment 2
<location path="cloud_registry/utils.py" line_range="72" />
<code_context>
+        Host; IPv6 addresses in brackets, with zone IDs percent-encoded (RFC
+        6874).
+    """
+    address, _, zone = host.partition("%")
+    try:
+        ipaddress.IPv6Address(address)
</code_context>
<issue_to_address>
**Scoped IPv6 URLs are malformed**

When `external_host` is configured as a bracketed scoped IPv6 address, such as `[fe80::1%eth0]`, `_format_host` partitions the zone before removing the brackets, so `IPv6Address` rejects the partial address and the exception path returns the original host. `get_public_url` then emits a raw `%` in `Location`, which clients cannot reliably use.

Remove the brackets before validating the IPv6 address, then rebuild the bracketed host with the zone delimiter encoded as `%25`.

Also at `cloud_registry/utils.py:76-77`.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: cloud_registry/utils.py:56, cloud_registry/utils.py:72


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

Comment thread cloud_registry/utils.py Resolved
Comment thread cloud_registry/utils.py Resolved
Reject ID character sets with `/` or only dots, generate new IDs
instead of `.` and `..`, and accept bracketed IPv6 hosts with zone IDs
in the public URL configuration.

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 merged commit 45e3306 into dev Oct 20, 2026
11 checks passed
@uniqueg
uniqueg deleted the feat/created-location branch October 20, 2026 19:31
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.

API: 201 Created for new services

1 participant