Skip to content

Commit 159fa17

Browse files
authored
[Identity] Update AzureCliCredential executable search (#41806)
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
1 parent 56bc902 commit 159fa17

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

sdk/identity/azure-identity/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Bugs Fixed
1010

1111
- Fixed an issue with `AzurePowerShellCredential` not working correctly for users still using older versions of PowerShell (e.g., Windows PowerShell 5.1) where `-AsPlainText` is not supported in the `ConvertFrom-SecureString` cmdlet. ([#41675](https://github.com/Azure/azure-sdk-for-python/pull/41675))
12+
- Fixed an issue with `AzureCliCredential` being unable to find the correct `az` executable for certain Python versions on Windows. ([#41806](https://github.com/Azure/azure-sdk-for-python/pull/41806))
1213

1314
### Other Changes
1415

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,11 @@ def sanitize_output(output: str) -> str:
234234

235235
def _run_command(command_args: List[str], timeout: int) -> str:
236236
# Ensure executable exists in PATH first. This avoids a subprocess call that would fail anyway.
237-
az_path = shutil.which(EXECUTABLE_NAME)
237+
if sys.platform.startswith("win"):
238+
# On Windows, the expected executable is az.cmd, so we check for that first, falling back to 'az' in case.
239+
az_path = shutil.which(EXECUTABLE_NAME + ".cmd") or shutil.which(EXECUTABLE_NAME)
240+
else:
241+
az_path = shutil.which(EXECUTABLE_NAME)
238242
if not az_path:
239243
raise CredentialUnavailableError(message=CLI_NOT_FOUND)
240244

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ async def close(self) -> None:
184184

185185
async def _run_command(command_args: List[str], timeout: int) -> str:
186186
# Ensure executable exists in PATH first. This avoids a subprocess call that would fail anyway.
187-
az_path = shutil.which(EXECUTABLE_NAME)
187+
if sys.platform.startswith("win"):
188+
# On Windows, the expected executable is az.cmd, so we check for that first, falling back to 'az' in case.
189+
az_path = shutil.which(EXECUTABLE_NAME + ".cmd") or shutil.which(EXECUTABLE_NAME)
190+
else:
191+
az_path = shutil.which(EXECUTABLE_NAME)
188192
if not az_path:
189193
raise CredentialUnavailableError(message=CLI_NOT_FOUND)
190194

0 commit comments

Comments
 (0)