Skip to content

Commit

Permalink
remove admin override
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg1969 committed Jan 31, 2025
1 parent 09da505 commit 1ad3b9f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 30 deletions.
14 changes: 2 additions & 12 deletions anaconda_anon_usage/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
locate_prefix_by_name,
)

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


Expand All @@ -25,17 +25,7 @@ def _new_user_agent(ctx):
getattr(Context, "checked_prefix", None) or context.target_prefix or sys.prefix
)
try:
# 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 has_admin_tokens()
if is_enabled and not context.anaconda_anon_usage:
_debug("system token overriding the config setting")
token = token_string(prefix, is_enabled)
token = token_string(prefix, context.anaconda_anon_usage)
if token:
result += " " + token
except Exception: # pragma: nocover
Expand Down
22 changes: 5 additions & 17 deletions anaconda_anon_usage/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _search_path():
return result


def _system_token(fname, what, find_only=False):
def _system_token(fname, what):
"""
Returns an organization or machine token installed somewhere
in the conda path. Unlike most tokens, these will typically
Expand All @@ -104,9 +104,6 @@ def _system_token(fname, what, find_only=False):
fpath = join(path, fname)
if not isfile(fpath):
continue
if find_only:
_debug("Found %s token: %s", what, fpath)
return True
t_tokens = _saved_token(fpath, what, read_only=True)
if t_tokens:
for token in t_tokens.split("/"):
Expand All @@ -118,28 +115,19 @@ def _system_token(fname, what, find_only=False):


@cached
def organization_token(find_only=False):
def organization_token():
"""
Returns the organization token.
"""
return _system_token(ORG_TOKEN_NAME, "organization", find_only)
return _system_token(ORG_TOKEN_NAME, "organization")


@cached
def machine_token(find_only=False):
def machine_token():
"""
Returns the machine token.
"""
return _system_token(MACHINE_TOKEN_NAME, "machine", find_only)


@cached
def has_admin_tokens():
"""
Returns true of either a machine or org token is installed.
Used to trigger an override of the anaconda_anon_usage setting.
"""
return organization_token(True) or machine_token(True)
return _system_token(MACHINE_TOKEN_NAME, "machine")


@cached
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _config(value, ctype):
subprocess.run(["conda", "config", "--set", KEY, cvalue], capture_output=True)
if ctype == "env" or value == "default":
subprocess.run(["conda", "config", "--remove-key", KEY], capture_output=True)
return value in yes_modes or m_tokens.has_admin_tokens()
return value in yes_modes


all_modes = ["true", "false", "yes", "no", "on", "off", "default"]
Expand Down

0 comments on commit 1ad3b9f

Please sign in to comment.