Skip to content

Commit cdab548

Browse files
authored
[Identity] Adjust log level for EnvCred warning (#31814)
If within a DAC, use log level WARNING instead of INFO when paritial envionment variables are set. The warning can sometimes be interpreted as an error by the user. Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
1 parent 46bcc9d commit cdab548

5 files changed

Lines changed: 11 additions & 6 deletions

File tree

sdk/identity/azure-identity/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
### Other Changes
1818

1919
- Update typing of async credentials to match the `AsyncTokenCredential` protocol.
20+
- If within `DefaultAzureCredential`, `EnvironmentCredential` will now use log level INFO instead of WARNING to inform users of an incomplete environment configuration. ([#31814](https://github.com/Azure/azure-sdk-for-python/pull/31814))
2021

2122
## 1.14.0 (2023-08-08)
2223

sdk/identity/azure-identity/azure/identity/_credentials/default.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def __init__(self, **kwargs: Any) -> None: # pylint: disable=too-many-statement
146146

147147
credentials: List["TokenCredential"] = []
148148
if not exclude_environment_credential:
149-
credentials.append(EnvironmentCredential(authority=authority, **kwargs))
149+
credentials.append(EnvironmentCredential(authority=authority, _within_dac=True, **kwargs))
150150
if not exclude_workload_identity_credential:
151151
if all(os.environ.get(var) for var in EnvironmentVariables.WORKLOAD_IDENTITY_VARS):
152152
client_id = workload_identity_client_id

sdk/identity/azure-identity/azure/identity/_credentials/environment.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ def __init__(self, **kwargs: Any) -> None:
100100
)
101101
set_variables = [v for v in expected_variables if v in os.environ]
102102
if set_variables:
103-
_LOGGER.warning(
104-
"Incomplete environment configuration. These variables are set: %s", ", ".join(set_variables)
103+
_LOGGER.log(
104+
logging.INFO if kwargs.get("_within_dac") else logging.WARNING,
105+
"Incomplete environment configuration for EnvironmentCredential. These variables are set: %s",
106+
", ".join(set_variables),
105107
)
106108
else:
107109
_LOGGER.info("No environment configuration found.")

sdk/identity/azure-identity/azure/identity/aio/_credentials/default.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def __init__(self, **kwargs: Any) -> None:
136136

137137
credentials = [] # type: List[AsyncTokenCredential]
138138
if not exclude_environment_credential:
139-
credentials.append(EnvironmentCredential(authority=authority, **kwargs))
139+
credentials.append(EnvironmentCredential(authority=authority, _within_dac=True, **kwargs))
140140
if not exclude_workload_identity_credential:
141141
if all(os.environ.get(var) for var in EnvironmentVariables.WORKLOAD_IDENTITY_VARS):
142142
client_id = workload_identity_client_id

sdk/identity/azure-identity/azure/identity/aio/_credentials/environment.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ def __init__(self, **kwargs: Any) -> None:
7575
expected_variables = set(EnvironmentVariables.CERT_VARS + EnvironmentVariables.CLIENT_SECRET_VARS)
7676
set_variables = [v for v in expected_variables if v in os.environ]
7777
if set_variables:
78-
_LOGGER.warning(
79-
"Incomplete environment configuration. These variables are set: %s", ", ".join(set_variables)
78+
_LOGGER.log(
79+
logging.INFO if kwargs.get("_within_dac") else logging.WARNING,
80+
"Incomplete environment configuration for EnvironmentCredential. These variables are set: %s",
81+
", ".join(set_variables),
8082
)
8183
else:
8284
_LOGGER.info("No environment configuration found.")

0 commit comments

Comments
 (0)