@@ -379,40 +379,45 @@ def list_acr_tags(registry_name: str, repo_name: str) -> list[str]:
379379 f"Listing tags for ACR repository: { registry_name } .azurecr.io/{ repo_name } "
380380 )
381381 # Check whether Azure CLI is already authenticated before attempting login.
382- auth_check = sp .run (["az" , "account" , "show" ], capture_output = True , text = True )
382+ auth_check = sp .run (
383+ ["az" , "account" , "show" , "--output" , "none" ],
384+ capture_output = True ,
385+ text = True ,
386+ )
387+
383388 if auth_check .returncode != 0 :
384389 logger .info ("Azure CLI is not authenticated; attempting managed identity login" )
385390 login_result = sp .run (
386- ["az" , "login" , "--identity" ], capture_output = True , text = True
391+ ["az" , "login" , "--identity" , "--output" , "none" ],
392+ capture_output = True ,
393+ text = True ,
387394 )
395+
388396 if login_result .returncode != 0 :
389- error_msg = (
397+ login_error = (
390398 login_result .stderr .strip () if login_result .stderr else "Unknown error"
391399 )
392- raise Exception (f"Azure CLI login failed: { error_msg } " )
393- if login_result .returncode != 0 :
394- login_error = (
395- login_result .stderr .strip () if login_result .stderr else "Unknown error"
396- )
397- logger .warning (
398- "Managed identity login failed; checking for an existing Azure CLI session. "
399- f"az login --identity error: { login_error } "
400- )
401- account_show_result = sp .run (
402- ["az" , "account" , "show" , "--output" , "json" ],
403- capture_output = True ,
404- text = True ,
405- )
406- if account_show_result .returncode != 0 :
407- raise Exception (
408- "Azure CLI authentication failed: managed identity login was unsuccessful "
409- f"and no existing authenticated session was found. az login --identity "
410- f"error: { login_error } "
400+ logger .warning (
401+ "Managed identity login failed; checking for an existing Azure CLI session. "
402+ f"az login --identity error: { login_error } "
403+ )
404+
405+ account_show_result = sp .run (
406+ ["az" , "account" , "show" , "--output" , "none" ],
407+ capture_output = True ,
408+ text = True ,
409+ )
410+ if account_show_result .returncode != 0 :
411+ raise Exception (
412+ "Azure CLI authentication failed: managed identity login was unsuccessful "
413+ "and no existing authenticated session was found. "
414+ f"az login --identity error: { login_error } "
415+ )
416+
417+ logger .info (
418+ "Managed identity login failed, but an existing Azure CLI session is "
419+ "authenticated; proceeding with the existing session."
411420 )
412- logger .info (
413- "Managed identity login failed, but an existing Azure CLI session is "
414- "authenticated; proceeding with the existing session."
415- )
416421 # get tags command
417422 acr_tags_command = [
418423 "az" ,
0 commit comments