Skip to content

Commit

Permalink
move system token override logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg1969 committed Nov 25, 2024
1 parent 1faaa65 commit 2ecbb47
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
14 changes: 12 additions & 2 deletions anaconda_anon_usage/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from conda.auxlib.decorators import memoizedproperty
from conda.base.context import Context, ParameterLoader, PrimitiveParameter, context

from .tokens import token_string
from .tokens import system_token, token_string
from .utils import _debug


Expand All @@ -18,7 +18,17 @@ def _new_user_agent(ctx):
getattr(Context, "checked_prefix", None) or context.target_prefix or sys.prefix
)
try:
token = token_string(prefix, context.anaconda_anon_usage)
# If an organization token exists, it overrides the value of
# context.anaconda_anon_usage. For most users, this has no
# effect. But this does provide a system administrator the
# ability to enable telemetry without modifying a user's
# configuration by installing an organization token. The
# effect is similar to placing "anaconda_anon_usage: true"
# in /etc/conda/.condarc.
is_enabled = context.anaconda_anon_usage or system_token()
if is_enabled and not context.anaconda_anon_usage:
_debug("system token overriding the config setting")
token = token_string(prefix, is_enabled)
if token:
result += " " + token
except Exception: # pragma: nocover
Expand Down
4 changes: 1 addition & 3 deletions anaconda_anon_usage/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ def token_string(prefix=None, enabled=True):
appended to the conda user agent.
"""
parts = ["aau/" + __version__]
if enabled or system_token():
if not enabled:
_debug("anaconda_anon_usage enabled by system token")
if enabled:
values = all_tokens(prefix)
if values.client:
parts.append("c/" + values.client)
Expand Down
5 changes: 0 additions & 5 deletions tests/unit/test_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ def test_token_string_with_system(system_token):
assert "o/" + system_token in token_string


def test_token_string_disabled_override_system(system_token):
token_string = tokens.token_string(enabled=False)
assert "o/" + system_token in token_string


def test_token_string_no_client_token(monkeypatch, system_token):
def _mock_saved_token(*args, **kwargs):
return ""
Expand Down

0 comments on commit 2ecbb47

Please sign in to comment.