1919def run_cli_command (cmd , return_as_json = False ):
2020 try :
2121 cmd_output = check_output (cmd , stderr = STDOUT , universal_newlines = True )
22- logger .debug ('command: %s ended with output: %s' , cmd , cmd_output )
22+ logger .debug ('command: %s ended with output: %s' , _mask_output_token ( cmd ) , cmd_output )
2323
2424 if return_as_json :
2525 if cmd_output :
@@ -40,15 +40,25 @@ def run_cli_command(cmd, return_as_json=False):
4040 raise CLIError ("Command returned an unexpected empty string." )
4141 return cmd_output
4242 except CalledProcessError as ex :
43- logger .error ('command failed: %s' , cmd )
43+ logger .error ('command failed: %s' , _mask_output_token ( cmd ) )
4444 logger .error ('output: %s' , ex .output )
4545 raise ex
4646 except Exception as ex :
47- logger .error ('command ended with an error: %s' , cmd )
47+ logger .error ('command ended with an error: %s' , _mask_output_token ( cmd ) )
4848 logger .error ('args: %s' , ex .args )
4949 raise ex
5050
5151
52+ def _mask_output_token (cmd ):
53+ output = cmd [:]
54+ token_param_name = "--sas-token"
55+ if token_param_name in output :
56+ idx = output .index (token_param_name )
57+ output [idx + 1 ] = "******"
58+
59+ return output
60+
61+
5262def prepare_cli_command (cmd , output_as_json = True , tags = None , subscription = None , only_show_errors = None ):
5363 full_cmd = [sys .executable , '-m' , 'azure.cli' ] + cmd
5464
0 commit comments