Skip to content

Commit 6805d14

Browse files
committed
copilot suggestion updates and style fixes
1 parent 1f810ac commit 6805d14

File tree

1 file changed

+31
-38
lines changed

1 file changed

+31
-38
lines changed

src/aosm/azext_aosm/common/registry.py

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,13 @@ def copy_image_to_target_acr(
243243
# the format of input.json. Our usage here won't work cross-tenant since
244244
# we're attempting to get the token (source) with the same context as that
245245
# in which we are creating the ACR (i.e. the target tenant)
246-
246+
247247
# Get access token with ACR scope to ensure proper repository permissions
248248
get_token_cmd = [
249-
str(shutil.which("az")),
250-
"account",
251-
"get-access-token",
252-
"--scope",
249+
str(shutil.which("az")),
250+
"account",
251+
"get-access-token",
252+
"--scope",
253253
ACR_OAUTH_SCOPE
254254
]
255255
# Dont use call_subprocess_raise_output here as we don't want to log the
@@ -283,7 +283,7 @@ def copy_image_to_target_acr(
283283
try:
284284
# Extract source registry name for the --registry parameter
285285
source_registry_name = self.registry_name.replace(".azurecr.io", "")
286-
286+
287287
# Get the full resource ID for the source registry
288288
source_registry_id_cmd = [
289289
str(shutil.which("az")),
@@ -296,14 +296,23 @@ def copy_image_to_target_acr(
296296
"--output",
297297
"tsv"
298298
]
299-
called_process = subprocess.run( # noqa: S603
300-
source_registry_id_cmd,
301-
encoding="utf-8",
302-
capture_output=True,
303-
text=True,
304-
check=True,
305-
)
306-
source_registry_id = called_process.stdout.strip()
299+
try:
300+
called_process = subprocess.run( # noqa: S603
301+
source_registry_id_cmd,
302+
encoding="utf-8",
303+
capture_output=True,
304+
text=True,
305+
check=True,
306+
)
307+
source_registry_id = called_process.stdout.strip()
308+
except subprocess.CalledProcessError as exc:
309+
error_output = exc.stderr or exc.stdout or str(exc)
310+
raise ClientRequestError(
311+
"Failed to resolve source registry "
312+
f"'{source_registry_name}'. Please ensure the registry exists "
313+
"and that you have sufficient permissions. "
314+
f"Details: {error_output}"
315+
) from exc
307316

308317
acr_import_image_cmd = [
309318
str(shutil.which("az")),
@@ -362,35 +371,19 @@ def copy_image_to_target_acr(
362371
error,
363372
)
364373

365-
def _get_subscription_id(self) -> str:
366-
"""Get the current subscription ID."""
367-
try:
368-
get_sub_cmd = [str(shutil.which("az")), "account", "show", "--query", "id", "--output", "tsv"]
369-
called_process = subprocess.run( # noqa: S603
370-
get_sub_cmd,
371-
encoding="utf-8",
372-
capture_output=True,
373-
text=True,
374-
check=True,
375-
)
376-
return called_process.stdout.strip()
377-
except subprocess.CalledProcessError as error:
378-
logger.debug(error, exc_info=True)
379-
raise ClientRequestError("Failed to get subscription ID") from error
380-
381374
def _get_source_acr_resource_group(self) -> str:
382375
"""Get the resource group name for the source ACR."""
383376
try:
384377
registry_name_without_domain = self.registry_name.replace(".azurecr.io", "")
385378
get_rg_cmd = [
386-
str(shutil.which("az")),
387-
"acr",
388-
"show",
389-
"--name",
390-
registry_name_without_domain,
391-
"--query",
392-
"resourceGroup",
393-
"--output",
379+
str(shutil.which("az")),
380+
"acr",
381+
"show",
382+
"--name",
383+
registry_name_without_domain,
384+
"--query",
385+
"resourceGroup",
386+
"--output",
394387
"tsv"
395388
]
396389
called_process = subprocess.run( # noqa: S603

0 commit comments

Comments
 (0)