Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@AlbertDeFusco
Copy link
Contributor

@AlbertDeFusco AlbertDeFusco commented Sep 18, 2025

Currently it is possible to use the [plugin.auth] table in ~/.anaconda/config.toml to change details of auth and API requests for domain, ssl_verify, and other settings.

~/.anaconda/config.toml configuration

Here, two top-level keys are added to support multiple site configuration, retrieval, and setting a default site. The [sites] table is used to store key-value pairs for the name of the site and configuration options. The goal is to provide site-based look-ups for configuration of BaseClient and login details.

The keys in [site.<site-name>] tables are the same as [plugin.auth]

Here's an example

default_site = "my-site"

[sites."my-site"]
domain = "my.site.com"
auth_domain_override = "auth-test.site.com"
ssl_verify = false
client_id = "12345"

The site information is read using AnacondaAuthSitesConfig. For the above config.toml:

from anaconda_auth.config import AnacondaAuthSitesConfig
site_config = AnacondaAuthSitesConfig.load_site() # return the site config for the configured default, 'my-site'
site_config = AnacondaAuthSitesConfig.load_site(at=None) # same as above
site_config = AnacondaAuthSitesConfig.load_site(at='anaconda.com') # always available
site_config = AnacondaAuthSitesConfig.load_site(at='my-site') # the new my-site table
site_config = AnacondaAuthSitesConfig.load_site(at='my.site.com') # the domain name of the my-site alias

Or using the sites dictionary

from anaconda_auth.config import AnacondaAuthSitesConfig
config = AnacondaAuthSitesConfig()
print(config.default_site) # string set to "my-site"
print(config.sites["anaconda.com"]) # always available
print(config.sites["my-site"]) # the new my-site table
print(config.sites["my.site.com"]) # the domain name of the my-site alias

Finally, the site "anaconda.com" is a special site and you cannot have a custom site called 'anaconda.com'. To make changes to this site use [plugin.auth].

CLI

The four anaconda auth subcommands now accept --at to control the site. It will accept a site name or domain name for a configured site.

Load site config in BaseClient

anaconda_auth.client.BaseClient now supports site= kwarg. This kwarg allows two types either str (site name or domain name) or anaconda_auth.config.AnacondaAuthSite. Note that AnacondaAuthConfig (which reads from config.toml) is derived from AnacondaAuthSite. Any further kwargs override the supplied site. When site=None the default site config.

from anaconda_auth.client import BaseClient

client = BaseClient()  # uses the default_site
client = BaseClient(ssl_verify=False) # overrides default site configuration

client = BaseClient(site="my-site") # load the site config using values in ~/.anaconda/config.toml
client = BaseClient(site="my-site", api_key='foo', extra_headers={'key', 'value'}) # load and override site config

from anaconda_auth.config import AnacondaAuthSite

site = AnacondaAuthSite(domain='localhost')
client = BaseClient(site=site) # load site with supplied config object
client = BaseClient(site=site, api_key='bar') # load and override

TODO

  • default and requested site retrieval in BaseClient
  • support --at <site> for auth CLI commands (login, logout, api-key, whoami)
  • consider global cli flag anaconda --site <site> ... and env var ANACONDA_SITE=<site> (may have to make changes to cli-base)

Note: tests will pass when anaconda-cli-base is released with this PR: anaconda/anaconda-cli-base#75

@AlbertDeFusco AlbertDeFusco marked this pull request as ready for review September 30, 2025 19:08
@AlbertDeFusco
Copy link
Contributor Author

adjust this message to say name or domain

anaconda auth login --at stage2.anaconda.com
UnknownSiteName: The site name stage2.anaconda.com has not been configured in /Users/adefusco/.anaconda/config.toml

To see a more detailed error message run the command again as
  anaconda --verbose auth login --at stage2.anaconda.com

@AlbertDeFusco
Copy link
Contributor Author

add auth_domain_override to client init

Copy link
Collaborator

@mattkram mattkram left a comment

Choose a reason for hiding this comment

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

Looking great. I left a few comments about some design and naming issues, but overall we are very close.

Copy link
Collaborator

@mattkram mattkram left a comment

Choose a reason for hiding this comment

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

I think we're ready! Just one small comment about a preferred function rename but other than that let's :shipit:

@AlbertDeFusco AlbertDeFusco merged commit b4d0d0e into main Oct 28, 2025
9 checks passed
@AlbertDeFusco AlbertDeFusco deleted the feat/site-config branch October 28, 2025 01:29
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.

2 participants