1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add option to hide sensitive ansible-test output.

This option is enabled automatically on Shippable.
This commit is contained in:
Matt Clay 2018-02-19 13:32:07 -08:00
parent b39534201f
commit 3a62eb5e03
3 changed files with 23 additions and 0 deletions

View file

@ -166,6 +166,8 @@ class AnsibleCoreCI(object):
self.instance_id = str(uuid.uuid4()) self.instance_id = str(uuid.uuid4())
self.endpoint = None self.endpoint = None
display.sensitive.add(self.instance_id)
def _get_parallels_endpoints(self): def _get_parallels_endpoints(self):
""" """
:rtype: tuple[str] :rtype: tuple[str]
@ -299,6 +301,9 @@ class AnsibleCoreCI(object):
password=con.get('password'), password=con.get('password'),
) )
if self.connection.password:
display.sensitive.add(self.connection.password)
status = 'running' if self.connection.running else 'starting' status = 'running' if self.connection.running else 'starting'
display.info('Status update: %s/%s on instance %s is %s.' % display.info('Status update: %s/%s on instance %s is %s.' %
@ -453,6 +458,8 @@ class AnsibleCoreCI(object):
self.endpoint = config['endpoint'] self.endpoint = config['endpoint']
self.started = True self.started = True
display.sensitive.add(self.instance_id)
return True return True
def _save(self): def _save(self):

View file

@ -491,6 +491,8 @@ class Display(object):
self.rows = 0 self.rows = 0
self.columns = 0 self.columns = 0
self.truncate = 0 self.truncate = 0
self.redact = False
self.sensitive = set()
if os.isatty(0): if os.isatty(0):
self.rows, self.columns = unpack('HHHH', fcntl.ioctl(0, TIOCGWINSZ, pack('HHHH', 0, 0, 0, 0)))[:2] self.rows, self.columns = unpack('HHHH', fcntl.ioctl(0, TIOCGWINSZ, pack('HHHH', 0, 0, 0, 0)))[:2]
@ -554,6 +556,10 @@ class Display(object):
:type fd: file :type fd: file
:type truncate: bool :type truncate: bool
""" """
if self.redact and self.sensitive:
for item in self.sensitive:
message = message.replace(item, '*' * len(item))
if truncate: if truncate:
if len(message) > self.truncate > 5: if len(message) > self.truncate > 5:
message = message[:self.truncate - 5] + ' ...' message = message[:self.truncate - 5] + ' ...'
@ -633,6 +639,10 @@ class CommonConfig(object):
self.verbosity = args.verbosity # type: int self.verbosity = args.verbosity # type: int
self.debug = args.debug # type: bool self.debug = args.debug # type: bool
self.truncate = args.truncate # type: int self.truncate = args.truncate # type: int
self.redact = args.redact # type: bool
if is_shippable():
self.redact = True
def docker_qualify_image(name): def docker_qualify_image(name):

View file

@ -80,6 +80,7 @@ def main():
config = args.config(args) config = args.config(args)
display.verbosity = config.verbosity display.verbosity = config.verbosity
display.truncate = config.truncate display.truncate = config.truncate
display.redact = config.redact
display.color = config.color display.color = config.color
display.info_stderr = (isinstance(config, SanityConfig) and config.lint) or (isinstance(config, IntegrationConfig) and config.list_targets) display.info_stderr = (isinstance(config, SanityConfig) and config.lint) or (isinstance(config, IntegrationConfig) and config.list_targets)
check_startup() check_startup()
@ -157,6 +158,11 @@ def parse_args():
default=display.columns, default=display.columns,
help='truncate some long output (0=disabled) (default: auto)') help='truncate some long output (0=disabled) (default: auto)')
common.add_argument('--redact',
dest='redact',
action='store_true',
help='redact sensitive values in output')
test = argparse.ArgumentParser(add_help=False, parents=[common]) test = argparse.ArgumentParser(add_help=False, parents=[common])
test.add_argument('include', test.add_argument('include',