Repository: canonical/charmcraft

Issue:
The presence of CHARMCRAFT_AUTH should be logged
Currently we're logging all CHARMCRAFT_* environment variables, but specifically excluding `CHARMCRAFT_AUTH` to not leak secrets.

However, it's very useful, for debugging purposes, know that `CHARMCRAFT_AUTH` is present or not, so we should log it with a different value, something like...

```
System details: (...); Environment: DESKTOP_SESSION='plasma', CHARMCRAFT_AUTH='<hidden>', ...
```

Discussion:

Patch:
diff --git a/charmcraft/main.py b/charmcraft/main.py
index 716cc14a..bf24e730 100644
--- a/charmcraft/main.py
+++ b/charmcraft/main.py
@@ -102,16 +102,20 @@ EXTRA_ENVIRONMENT = ("DESKTOP_SESSION", "XDG_CURRENT_DESKTOP")
 
 def _get_system_details():
     """Produce details about the system."""
-    # prepare the useful environment variables: all CHARMCRAFT* (except AUTH keys)
+    # prepare the useful environment variables: all CHARMCRAFT* (hiding AUTH keys)
     # and desktop/session
-    useful_env = {name for name in os.environ if name.startswith("CHARMCRAFT")}
-    useful_env.discard(ALTERNATE_AUTH_ENV_VAR)
-    useful_env.update(EXTRA_ENVIRONMENT)
-
-    os_platform = utils.get_os_platform()
-    env_string = ", ".join(f"{k}={v!r}" for k, v in sorted(os.environ.items()) if k in useful_env)
+    useful_env = {
+        name: value
+        for name, value in os.environ.items()
+        if name.startswith("CHARMCRAFT") or name in EXTRA_ENVIRONMENT
+    }
+    if ALTERNATE_AUTH_ENV_VAR in useful_env:
+        useful_env[ALTERNATE_AUTH_ENV_VAR] = "<hidden>"
+    env_string = ", ".join(f"{name}={value!r}" for name, value in sorted(useful_env.items()))
     if not env_string:
         env_string = "None"
+
+    os_platform = utils.get_os_platform()
     return f"System details: {os_platform}; Environment: {env_string}"
 
 


Test patch:
diff --git a/tests/test_main.py b/tests/test_main.py
index 5c5aa3c9..48202da2 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -334,8 +334,8 @@ def test_systemdetails_charmcraft_environment():
     )
 
 
-def test_systemdetails_no_auth():
-    """System details specifically excluding secrets."""
+def test_systemdetails_hidden_auth():
+    """System details specifically hiding secrets."""
     with patch("os.environ", {ALTERNATE_AUTH_ENV_VAR: "supersecret"}):
         with patch("charmcraft.utils.get_os_platform") as platform_mock:
             platform_mock.return_value = utils.OSPlatform(
@@ -344,7 +344,7 @@ def test_systemdetails_no_auth():
             result = _get_system_details()
     assert result == (
         "System details: OSPlatform(system='test-system', release='test-release', "
-        "machine='test-machine'); Environment: None"
+        f"machine='test-machine'); Environment: {ALTERNATE_AUTH_ENV_VAR}='<hidden>'"
     )