Skip to content

Commit

Permalink
fix typing (Azure#34227)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyan99 authored Feb 8, 2024
1 parent 1e03df0 commit 86bb315
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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, "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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, "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()

Expand Down

0 comments on commit 86bb315

Please sign in to comment.