Skip to content

Commit 3f45fb2

Browse files
Copilotxiangyan99
andcommitted
Apply black formatting to AzureCliCredential files
Co-authored-by: xiangyan99 <[email protected]>
1 parent 1ced477 commit 3f45fb2

File tree

2 files changed

+44
-15
lines changed

2 files changed

+44
-15
lines changed

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ def get_token(
115115
receive an access token.
116116
"""
117117
if claims and claims.strip():
118-
raise CredentialUnavailableError(f"Fail to get token, please run az login --claims-challenge {claims}")
118+
raise CredentialUnavailableError(
119+
f"Fail to get token, please run az login --claims-challenge {claims}"
120+
)
119121

120122
options: TokenRequestOptions = {}
121123
if tenant_id:
@@ -125,7 +127,9 @@ def get_token(
125127
return AccessToken(token_info.token, token_info.expires_on)
126128

127129
@log_get_token
128-
def get_token_info(self, *scopes: str, options: Optional[TokenRequestOptions] = None) -> AccessTokenInfo:
130+
def get_token_info(
131+
self, *scopes: str, options: Optional[TokenRequestOptions] = None
132+
) -> AccessTokenInfo:
129133
"""Request an access token for `scopes`.
130134
131135
This is an alternative to `get_token` to enable certain scenarios that require additional properties
@@ -226,7 +230,9 @@ def get_safe_working_dir() -> str:
226230
if sys.platform.startswith("win"):
227231
path = os.environ.get("SYSTEMROOT")
228232
if not path:
229-
raise CredentialUnavailableError(message="Environment variable 'SYSTEMROOT' has no value")
233+
raise CredentialUnavailableError(
234+
message="Environment variable 'SYSTEMROOT' has no value"
235+
)
230236
return path
231237

232238
return "/bin"
@@ -246,7 +252,9 @@ def _run_command(command_args: List[str], timeout: int) -> str:
246252
# Ensure executable exists in PATH first. This avoids a subprocess call that would fail anyway.
247253
if sys.platform.startswith("win"):
248254
# On Windows, the expected executable is az.cmd, so we check for that first, falling back to 'az' in case.
249-
az_path = shutil.which(EXECUTABLE_NAME + ".cmd") or shutil.which(EXECUTABLE_NAME)
255+
az_path = shutil.which(EXECUTABLE_NAME + ".cmd") or shutil.which(
256+
EXECUTABLE_NAME
257+
)
250258
else:
251259
az_path = shutil.which(EXECUTABLE_NAME)
252260
if not az_path:
@@ -269,10 +277,13 @@ def _run_command(command_args: List[str], timeout: int) -> str:
269277
except subprocess.CalledProcessError as ex:
270278
# non-zero return from shell
271279
# Fallback check in case the executable is not found while executing subprocess.
272-
if ex.returncode == 127 or (ex.stderr is not None and ex.stderr.startswith("'az' is not recognized")):
280+
if ex.returncode == 127 or (
281+
ex.stderr is not None and ex.stderr.startswith("'az' is not recognized")
282+
):
273283
raise CredentialUnavailableError(message=CLI_NOT_FOUND) from ex
274284
if ex.stderr is not None and (
275-
("az login" in ex.stderr or "az account set" in ex.stderr) and "AADSTS" not in ex.stderr
285+
("az login" in ex.stderr or "az account set" in ex.stderr)
286+
and "AADSTS" not in ex.stderr
276287
):
277288
raise CredentialUnavailableError(message=NOT_LOGGED_IN) from ex
278289

@@ -286,7 +297,9 @@ def _run_command(command_args: List[str], timeout: int) -> str:
286297
raise ClientAuthenticationError(message=message) from ex
287298
except OSError as ex:
288299
# failed to execute 'cmd' or '/bin/sh'
289-
error = CredentialUnavailableError(message="Failed to execute '{}'".format(args[0]))
300+
error = CredentialUnavailableError(
301+
message="Failed to execute '{}'".format(args[0])
302+
)
290303
raise error from ex
291304
except Exception as ex:
292305
# could be a timeout, for example

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,17 @@ async def get_token(
106106
receive an access token.
107107
"""
108108
if claims and claims.strip():
109-
raise CredentialUnavailableError(f"Fail to get token, please run az login --claims-challenge {claims}")
109+
raise CredentialUnavailableError(
110+
f"Fail to get token, please run az login --claims-challenge {claims}"
111+
)
110112

111113
# only ProactorEventLoop supports subprocesses on Windows (and it isn't the default loop on Python < 3.8)
112-
if sys.platform.startswith("win") and not isinstance(asyncio.get_event_loop(), asyncio.ProactorEventLoop):
113-
return _SyncAzureCliCredential().get_token(*scopes, tenant_id=tenant_id, **kwargs)
114+
if sys.platform.startswith("win") and not isinstance(
115+
asyncio.get_event_loop(), asyncio.ProactorEventLoop
116+
):
117+
return _SyncAzureCliCredential().get_token(
118+
*scopes, tenant_id=tenant_id, **kwargs
119+
)
114120

115121
options: TokenRequestOptions = {}
116122
if tenant_id:
@@ -120,7 +126,9 @@ async def get_token(
120126
return AccessToken(token_info.token, token_info.expires_on)
121127

122128
@log_get_token_async
123-
async def get_token_info(self, *scopes: str, options: Optional[TokenRequestOptions] = None) -> AccessTokenInfo:
129+
async def get_token_info(
130+
self, *scopes: str, options: Optional[TokenRequestOptions] = None
131+
) -> AccessTokenInfo:
124132
"""Request an access token for `scopes`.
125133
126134
This is an alternative to `get_token` to enable certain scenarios that require additional properties
@@ -146,7 +154,9 @@ async def get_token_info(self, *scopes: str, options: Optional[TokenRequestOptio
146154
f"Fail to get token, please run az login --claims-challenge {claims_value}"
147155
)
148156
# only ProactorEventLoop supports subprocesses on Windows (and it isn't the default loop on Python < 3.8)
149-
if sys.platform.startswith("win") and not isinstance(asyncio.get_event_loop(), asyncio.ProactorEventLoop):
157+
if sys.platform.startswith("win") and not isinstance(
158+
asyncio.get_event_loop(), asyncio.ProactorEventLoop
159+
):
150160
return _SyncAzureCliCredential().get_token_info(*scopes, options=options)
151161
return await self._get_token_base(*scopes, options=options)
152162

@@ -197,7 +207,9 @@ async def _run_command(command_args: List[str], timeout: int) -> str:
197207
# Ensure executable exists in PATH first. This avoids a subprocess call that would fail anyway.
198208
if sys.platform.startswith("win"):
199209
# On Windows, the expected executable is az.cmd, so we check for that first, falling back to 'az' in case.
200-
az_path = shutil.which(EXECUTABLE_NAME + ".cmd") or shutil.which(EXECUTABLE_NAME)
210+
az_path = shutil.which(EXECUTABLE_NAME + ".cmd") or shutil.which(
211+
EXECUTABLE_NAME
212+
)
201213
else:
202214
az_path = shutil.which(EXECUTABLE_NAME)
203215
if not az_path:
@@ -220,10 +232,14 @@ async def _run_command(command_args: List[str], timeout: int) -> str:
220232
stderr = stderr_b.decode()
221233
except asyncio.TimeoutError as ex:
222234
proc.kill()
223-
raise CredentialUnavailableError(message="Timed out waiting for Azure CLI") from ex
235+
raise CredentialUnavailableError(
236+
message="Timed out waiting for Azure CLI"
237+
) from ex
224238
except OSError as ex:
225239
# failed to execute 'cmd' or '/bin/sh'
226-
error = CredentialUnavailableError(message="Failed to execute '{}'".format(args[0]))
240+
error = CredentialUnavailableError(
241+
message="Failed to execute '{}'".format(args[0])
242+
)
227243
raise error from ex
228244

229245
if proc.returncode == 0:

0 commit comments

Comments
 (0)