feat(no-ticket): normalize the API host - #372
Open
cloudsmith-iduffy wants to merge 5 commits into
Open
Conversation
A loosely-written API host used to fail with an error that hid the cause. A value with no scheme aborted before the request. A trailing slash returned a 404 with a hint that blamed the user or org, when only the punctuation was wrong. Normalize the API host so these values work. The CLI adds the https scheme when the value gives none. It also removes surrounding whitespace and trailing slashes. `api.cloudsmith.io`, `//api.cloudsmith.io/` and ` https://api.cloudsmith.io/ ` all resolve to `https://api.cloudsmith.io`. This applies to `--api-host`, the `CLOUDSMITH_API_HOST` variable and the `api_host` config key.
Contributor
There was a problem hiding this comment.
Pull request overview
Normalizes API host values across CLI options, environment variables, configuration, and logout handling.
Changes:
- Adds HTTPS defaults, whitespace trimming, and trailing-slash removal.
- Applies normalization through options and logout.
- Adds tests and changelog documentation.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Reviewed changes |
|---|---|
cloudsmith_cli/cli/validators.py |
Adds host normalization. |
cloudsmith_cli/cli/tests/test_api_host_normalization.py |
Tests normalization and trust checks. |
cloudsmith_cli/cli/tests/commands/test_logout.py |
Tests normalized logout hosts. |
cloudsmith_cli/cli/decorators.py |
Documents default HTTPS behavior. |
cloudsmith_cli/cli/config.py |
Normalizes configured API hosts. |
cloudsmith_cli/cli/commands/logout.py |
Normalizes logout host selection. |
CHANGELOG.md |
Documents the feature. |
Suppressed comments (1)
cloudsmith_cli/cli/commands/logout.py:124
- This changes the keyring host used by
has_sso_tokens/delete_sso_tokens, but existing CLI versions could have stored SSO entries under a host spelling with a trailing slash. After upgrading, logout will look only under the normalized service name, report no tokens, and leave those legacy entries behind. Please retain a compatibility lookup/delete for legacy spellings or migrate them when using the canonical host.
api_host = (
validators.normalize_api_host(api_host)
or opts.api_host
or cloudsmith_api.Configuration().host
)
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
A blank host replaced a host that was already set. A CI variable set to whitespace therefore discarded the `api_host` from `config.ini`, and the CLI fell back to the public API host without a word. A user on a dedicated instance sent their API key to the wrong host. Return None for a blank value, so the existing host survives.
butlerx
approved these changes
Aug 21, 2026
Simplified help text for the --api-host option.
Updated help text for --api-host option to be more concise.
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.
Description
A loosely-written API host used to fail with an error that hid the cause. A value with no scheme aborted before the request. A trailing slash returned a 404 with a hint that blamed the user or org, when only the punctuation was wrong.
Before, against
master:Both now reach the API and return the real answer.
Normalize the API host so these values work. The CLI adds the https scheme when the value gives none. It also removes surrounding whitespace and trailing slashes.
api.cloudsmith.io,//api.cloudsmith.io/andhttps://api.cloudsmith.io/all resolve tohttps://api.cloudsmith.io.This applies to
--api-host, theCLOUDSMITH_API_HOSTvariable and theapi_hostconfig key.Type of Change