diff --git a/sdk/identity/azure-identity-broker/azure/identity/broker/_utils.py b/sdk/identity/azure-identity-broker/azure/identity/broker/_utils.py index 861cf94a65d3..971cc170f790 100644 --- a/sdk/identity/azure-identity-broker/azure/identity/broker/_utils.py +++ b/sdk/identity/azure-identity-broker/azure/identity/broker/_utils.py @@ -35,7 +35,11 @@ def wrapper(*args, **kwargs): def resolve_tenant( - default_tenant: str, tenant_id: Optional[str] = None, *, additionally_allowed_tenants: List[str] = [], **_ + default_tenant: str, + tenant_id: Optional[str] = None, + *, + additionally_allowed_tenants: Optional[List[str]] = None, + **_ ) -> str: """Returns the correct tenant for a token request given a credential's configuration. @@ -59,6 +63,8 @@ def resolve_tenant( return default_tenant if not default_tenant: return tenant_id + if additionally_allowed_tenants is None: + additionally_allowed_tenants = [] if "*" in additionally_allowed_tenants or tenant_id in additionally_allowed_tenants: _LOGGER.info( "A token was requested for a different tenant than was configured on the credential, " diff --git a/sdk/identity/azure-identity/azure/identity/_internal/utils.py b/sdk/identity/azure-identity/azure/identity/_internal/utils.py index ae2adf66059f..708b4ce354a8 100644 --- a/sdk/identity/azure-identity/azure/identity/_internal/utils.py +++ b/sdk/identity/azure-identity/azure/identity/_internal/utils.py @@ -73,7 +73,11 @@ def validate_tenant_id(tenant_id: str) -> None: def resolve_tenant( - default_tenant: str, tenant_id: Optional[str] = None, *, additionally_allowed_tenants: List[str] = [], **_ + default_tenant: str, + tenant_id: Optional[str] = None, + *, + additionally_allowed_tenants: Optional[List[str]] = None, + **_ ) -> str: """Returns the correct tenant for a token request given a credential's configuration. @@ -97,6 +101,8 @@ def resolve_tenant( return default_tenant if not default_tenant: return tenant_id + if additionally_allowed_tenants is None: + additionally_allowed_tenants = [] if "*" in additionally_allowed_tenants or tenant_id in additionally_allowed_tenants: _LOGGER.info( "A token was requested for a different tenant than was configured on the credential, " diff --git a/sdk/identity/azure-identity/azure/identity/aio/_credentials/azd_cli.py b/sdk/identity/azure-identity/azure/identity/aio/_credentials/azd_cli.py index 7162dc97f2aa..9d888918f471 100644 --- a/sdk/identity/azure-identity/azure/identity/aio/_credentials/azd_cli.py +++ b/sdk/identity/azure-identity/azure/identity/aio/_credentials/azd_cli.py @@ -171,13 +171,13 @@ async def _run_command(command: str, timeout: int) -> str: stdout_b, stderr_b = await asyncio.wait_for(proc.communicate(), timeout) output = stdout_b.decode() stderr = stderr_b.decode() + except asyncio.TimeoutError as ex: + proc.kill() + raise CredentialUnavailableError(message="Timed out waiting for Azure Developer CLI") from ex except OSError as ex: # failed to execute 'cmd' or '/bin/sh' error = CredentialUnavailableError(message="Failed to execute '{}'".format(args[0])) raise error from ex - except asyncio.TimeoutError as ex: - proc.kill() - raise CredentialUnavailableError(message="Timed out waiting for Azure Developer CLI") from ex if proc.returncode == 0: return output diff --git a/sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_cli.py b/sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_cli.py index ac8b88c0a848..e28385b035fb 100644 --- a/sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_cli.py +++ b/sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_cli.py @@ -149,13 +149,13 @@ async def _run_command(command: str, timeout: int) -> str: stdout_b, stderr_b = await asyncio.wait_for(proc.communicate(), timeout) output = stdout_b.decode() stderr = stderr_b.decode() + except asyncio.TimeoutError as ex: + proc.kill() + raise CredentialUnavailableError(message="Timed out waiting for Azure CLI") from ex except OSError as ex: # failed to execute 'cmd' or '/bin/sh' error = CredentialUnavailableError(message="Failed to execute '{}'".format(args[0])) raise error from ex - except asyncio.TimeoutError as ex: - proc.kill() - raise CredentialUnavailableError(message="Timed out waiting for Azure CLI") from ex if proc.returncode == 0: return output diff --git a/sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_powershell.py b/sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_powershell.py index c8b5584ad235..b55d38d79792 100644 --- a/sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_powershell.py +++ b/sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_powershell.py @@ -114,6 +114,13 @@ async def run_command_line(command_line: List[str], timeout: int) -> str: proc = await start_process(command_line) stdout, stderr = await asyncio.wait_for(proc.communicate(), timeout) + except asyncio.TimeoutError as ex: + proc.kill() + raise CredentialUnavailableError( + message="Timed out waiting for Azure PowerShell.\n" + "To mitigate this issue, please refer to the troubleshooting guidelines here at " + "https://aka.ms/azsdk/python/identity/powershellcredential/troubleshoot." + ) from ex except OSError as ex: # failed to execute "cmd" or "/bin/sh"; Azure PowerShell may or may not be installed error = CredentialUnavailableError( @@ -122,13 +129,6 @@ async def run_command_line(command_line: List[str], timeout: int) -> str: "https://aka.ms/azsdk/python/identity/powershellcredential/troubleshoot.".format(command_line[0]) ) raise error from ex - except asyncio.TimeoutError as ex: - proc.kill() - raise CredentialUnavailableError( - message="Timed out waiting for Azure PowerShell.\n" - "To mitigate this issue, please refer to the troubleshooting guidelines here at " - "https://aka.ms/azsdk/python/identity/powershellcredential/troubleshoot." - ) from ex decoded_stdout = stdout.decode()