Skip to content

feat(no-ticket): normalize the API host - #372

Open
cloudsmith-iduffy wants to merge 5 commits into
masterfrom
iduffy/normalize-api-host
Open

feat(no-ticket): normalize the API host#372
cloudsmith-iduffy wants to merge 5 commits into
masterfrom
iduffy/normalize-api-host

Conversation

@cloudsmith-iduffy

@cloudsmith-iduffy cloudsmith-iduffy commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

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:

$ cloudsmith whoami --api-host api.cloudsmith.io
Detail: MissingSchema
Invalid URL 'api.cloudsmith.io/user/self/': No scheme supplied.

$ cloudsmith whoami --api-host https://api.cloudsmith.io/
Failed to retrieve your authentication status! (404 - Not Found)
Hint: This usually means the user/org is wrong or not visible.

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/ 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.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactoring
  • Other (please describe)

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.
@cloudsmith-iduffy
cloudsmith-iduffy requested a review from a team as a code owner August 21, 2026 20:10
Copilot AI lite review requested due to automatic review settings August 21, 2026 20:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Simplified help text for the --api-host option.
Updated help text for --api-host option to be more concise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants