Skip to content

Commit

Permalink
Fix Azure#26857: separate stdout from stderr in AzureCliCredential
Browse files Browse the repository at this point in the history
  • Loading branch information
micromaomao committed Oct 20, 2022
1 parent f23a72b commit 73901fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions sdk/identity/azure-identity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

* `AzureCliCredential` now works even when `az` prints warnings to stderr.

### Other Changes

## 1.12.0b2 (2022-10-11)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _run_command(command):
working_directory = get_safe_working_dir()

kwargs = {
"stderr": subprocess.STDOUT,
"stderr": subprocess.PIPE,
"cwd": working_directory,
"universal_newlines": True,
"env": dict(os.environ, AZURE_CORE_NO_COLOR="true"),
Expand All @@ -154,14 +154,14 @@ def _run_command(command):
return subprocess.check_output(args, **kwargs)
except subprocess.CalledProcessError as ex:
# non-zero return from shell
if ex.returncode == 127 or ex.output.startswith("'az' is not recognized"):
if ex.returncode == 127 or ex.stderr.startswith("'az' is not recognized"):
raise CredentialUnavailableError(message=CLI_NOT_FOUND)
if "az login" in ex.output or "az account set" in ex.output:
if "az login" in ex.stderr or "az account set" in ex.stderr:
raise CredentialUnavailableError(message=NOT_LOGGED_IN)

# return code is from the CLI -> propagate its output
if ex.output:
message = sanitize_output(ex.output)
if ex.stderr:
message = sanitize_output(ex.stderr)
else:
message = "Failed to invoke Azure CLI"
raise ClientAuthenticationError(message=message)
Expand Down

0 comments on commit 73901fc

Please sign in to comment.