Skip to content

Commit ec528f2

Browse files
authored
{Image-copy} Mask the value of the --sas-token parameter when displaying it in the terminal (#9516)
1 parent 3fd83ba commit ec528f2

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/image-copy/HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Release History
44
===============
55

6+
1.0.4
7+
++++++
8+
* Mask the value of the `--sas-token` parameter when displaying it in the terminal
9+
610
1.0.3
711
++++++
812
* Fix the issue for sasTokenParsing, removing python related warnings from the sasToken(cmd_output was unfiltered)

src/image-copy/azext_imagecopy/cli_utils.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
def 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+
5262
def 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

src/image-copy/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from codecs import open
99
from setuptools import find_packages, setup
1010

11-
VERSION = "1.0.3"
11+
VERSION = "1.0.4"
1212

1313
CLASSIFIERS = [
1414
'Development Status :: 4 - Beta',

0 commit comments

Comments
 (0)