Detect which API version an appliance serves - #5
Merged
Merged
Conversation
The REST API carries its version in the path — /api/v8.1/... — and nothing negotiates
one for the caller, so every consumer has to pick a version up front and hard-code a
guess. detect_api_version() removes the guess: it probes /api/v{version}/system/about
for each version this package ships and returns the newest one the appliance routes.
That endpoint is the discriminator because it requires a bearer token, so an anonymous
probe separates the two cases by status alone: 401 (or 403, or 200 where it is
ungated) means the version is served, 404 means routing found nothing. No credentials
needed, so it can run before any exist.
Only 8.1 ships today, which makes the answer trivial now and correct later — the
candidate list is VERSION_TO_PACKAGE, so adding a version to the package is all it
takes for detection to consider it.
Best-effort by contract. Unreachable appliances, proxies that rewrite statuses and
anything else unexpected all return None, so a caller falls back to a version of its
own choosing instead of failing. Probes run concurrently, so detection costs about one
round trip.
detect_rest_api(host) additionally sweeps port x version and returns a
RestApiEndpoint(port, api_version), for deployments reached through a port-forwarding
proxy rather than on 443.
Also adds pytest-asyncio and a testpaths setting, which the repository needed to run
its first tests.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The REST API carries its version in the path — /api/v8.1/... — and nothing negotiates one for the caller, so every consumer has to pick a version up front and hard-code a guess. detect_api_version() removes the guess: it probes /api/v{version}/system/about for each version this package ships and returns the newest one the appliance routes.
That endpoint is the discriminator because it requires a bearer token, so an anonymous probe separates the two cases by status alone: 401 (or 403, or 200 where it is ungated) means the version is served, 404 means routing found nothing. No credentials needed, so it can run before any exist.
Only 8.1 ships today, which makes the answer trivial now and correct later — the candidate list is VERSION_TO_PACKAGE, so adding a version to the package is all it takes for detection to consider it.
Best-effort by contract. Unreachable appliances, proxies that rewrite statuses and anything else unexpected all return None, so a caller falls back to a version of its own choosing instead of failing. Probes run concurrently, so detection costs about one round trip.
detect_rest_api(host) additionally sweeps port x version and returns a RestApiEndpoint(port, api_version), for deployments reached through a port-forwarding proxy rather than on 443.
Also adds pytest-asyncio and a testpaths setting, which the repository needed to run its first tests.