Skip to content

fix typing #34227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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