Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where objects and arrays marked as secret weren't being masked #4236

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ Changed

Contributed by Nick Maludy (Encore Technologies).


Fixed
~~~~~

* Fixed a bug where ``secret: true`` was not applying to full object and array trees. (bugfix) #4234
Reported by @jjm

Contributed by Nick Maludy (Encore Technologies).

2.8.0 - July 10, 2018
---------------------

Expand Down
38 changes: 29 additions & 9 deletions st2common/st2common/util/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ def get_secret_parameters(parameters):

secret_parameters = {}
parameters_type = parameters.get('type')
# If the parameter itself is secret, then skip all processing below it
# and return the type of this parameter.
#
# **This causes the _full_ object / array tree to be secret (no children will be shown).**
#
# **Important** that we do this check first, so in case this parameter
# is an `object` or `array`, and the user wants the full thing
# to be secret, that it is marked as secret.
if parameters.get('secret', False):
return parameters_type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great 👍

That's also a more common scenario and it's much more performant :)


iterator = None
if parameters_type == 'object':
# if this is an object, then iterate over the properties within
Expand Down Expand Up @@ -95,7 +106,24 @@ def get_secret_parameters(parameters):
continue

parameter_type = options.get('type')
if parameter_type in ['object', 'array']:
if options.get('secret', False):
# If this parameter is secret, then add it our secret parameters
#
# **This causes the _full_ object / array tree to be secret
# (no children will be shown)**
#
# **Important** that we do this check first, so in case this parameter
# is an `object` or `array`, and the user wants the full thing
# to be secret, that it is marked as secret.
if isinstance(secret_parameters, list):
secret_parameters.append(parameter_type)
elif isinstance(secret_parameters, dict):
secret_parameters[parameter] = parameter_type
else:
return parameter_type
elif parameter_type in ['object', 'array']:
# otherwise recursively dive into the `object`/`array` and
# find individual parameters marked as secret
sub_params = get_secret_parameters(options)
if sub_params:
if isinstance(secret_parameters, list):
Expand All @@ -104,14 +132,6 @@ def get_secret_parameters(parameters):
secret_parameters[parameter] = sub_params
else:
return sub_params
elif options.get('secret', False):
# if this parameter is secret, then add it our secret parameters
if isinstance(secret_parameters, list):
secret_parameters.append(parameter_type)
elif isinstance(secret_parameters, dict):
secret_parameters[parameter] = parameter_type
else:
return parameter_type

return secret_parameters

Expand Down
Loading