Skip to content

Commit 9d1eeaf

Browse files
committed
feat: Update default to prefer API keys for channels that aren't configured with repo-token as default
1 parent d7d3a97 commit 9d1eeaf

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/anaconda_auth/_conda/auth_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ def _load_token_domain(self, parsed_url: ParseResult) -> tuple[str, CredentialTy
5353

5454
# Set defaults for behavior when not overridden by configuration
5555
token_domain = channel_domain
56-
credential_type = CredentialType.REPO_TOKEN
56+
credential_type = CredentialType.API_KEY
5757

5858
# For specific channel domains, we override the defaults
5959
if channel_domain in TOKEN_DOMAIN_MAP:
6060
token_domain, credential_type, _ = TOKEN_DOMAIN_MAP[channel_domain]
6161
else:
62-
token_domain, credential_type = channel_domain, CredentialType.REPO_TOKEN
62+
token_domain, credential_type = channel_domain, CredentialType.API_KEY
6363

6464
# Allow users to override default via configuration
6565
config = AnacondaAuthConfig(domain=token_domain)

tests/test_conda_plugins.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,21 @@ def test_load_token_domain_anaconda_cloud_api_key(conda_search_path, monkeypatch
343343

344344
assert token_domain == "anaconda.com"
345345
assert credential_type == CredentialType.API_KEY
346+
347+
348+
def test_load_token_domain_user_provided_default(conda_search_path):
349+
channel_url = "https://some-domain.com/repo/some-channel"
350+
condarc = CondaRC()
351+
condarc.update_channel_settings(
352+
channel=channel_url + "/*",
353+
auth_type="anaconda-auth",
354+
)
355+
condarc.save()
356+
context.reset_context()
357+
358+
handler = AnacondaAuthHandler(channel_name=channel_url)
359+
url = channel_url + "/noarch/repodata.json"
360+
token_domain, credential_type = handler._load_token_domain(parsed_url=urlparse(url))
361+
362+
assert token_domain == "some-domain.com"
363+
assert credential_type == CredentialType.API_KEY

0 commit comments

Comments
 (0)