Honor 'hidden' parameter in 'stack environment show' command

Related-Bug: #1999665
Story: 2010484
Task: 47052
Change-Id: Ifc51ff6a4deab05002ccded59383416f9a586aa0
This commit is contained in:
Chengen Du 2022-12-20 18:00:00 +08:00 committed by Takashi Kajinami
parent b452ea7089
commit 1305a3152f
3 changed files with 17 additions and 2 deletions

View File

@ -12,6 +12,7 @@
# under the License. # under the License.
import collections import collections
import copy
import datetime import datetime
import functools import functools
import itertools import itertools
@ -1354,7 +1355,16 @@ class EngineService(service.ServiceBase):
:rtype: dict :rtype: dict
""" """
s = self._get_stack(cnxt, stack_identity, show_deleted=True) s = self._get_stack(cnxt, stack_identity, show_deleted=True)
return s.raw_template.environment tmpl = templatem.Template.load(cnxt, s.raw_template_id, s.raw_template)
param_schemata = tmpl.all_param_schemata(tmpl.files)
env = copy.deepcopy(s.raw_template.environment)
for section in [env_fmt.PARAMETERS, env_fmt.PARAMETER_DEFAULTS]:
for param_name in env.get(section, {}).keys():
if (param_name not in param_schemata
or not param_schemata[param_name].hidden):
continue
env[section][param_name] = str('******')
return env
@context.request_context @context.request_context
def get_files(self, cnxt, stack_identity): def get_files(self, cnxt, stack_identity):

View File

@ -978,11 +978,12 @@ class StackServiceTest(common.HeatTestCase):
env = {'parameters': {'KeyName': 'EnvKey'}} env = {'parameters': {'KeyName': 'EnvKey'}}
tmpl = templatem.Template(t) tmpl = templatem.Template(t)
stack = parser.Stack(self.ctx, 'get_env_stack', tmpl) stack = parser.Stack(self.ctx, 'get_env_stack', tmpl)
stack.store()
mock_get_stack = self.patchobject(self.eng, '_get_stack') mock_get_stack = self.patchobject(self.eng, '_get_stack')
mock_get_stack.return_value = mock.MagicMock() mock_get_stack.return_value = mock.MagicMock()
mock_get_stack.return_value.raw_template.environment = env mock_get_stack.return_value.raw_template.environment = env
self.patchobject(parser.Stack, 'load', return_value=stack) self.patchobject(templatem.Template, 'load', return_value=tmpl)
# Test # Test
found = self.eng.get_environment(self.ctx, stack.identifier()) found = self.eng.get_environment(self.ctx, stack.identifier())

View File

@ -0,0 +1,4 @@
---
fixes:
- |
Honor ``hidden`` parameter in ``stack environment show`` command