File 0001-Honor-hidden-parameter-in-stack-environment-show-com.patch of Package openstack-heat
From 51f89483d37ba16f15738b4278f02fa28639fd8c Mon Sep 17 00:00:00 2001
From: Chengen Du <chengen.du@canonical.com>
Date: Tue, 20 Dec 2022 18:00:00 +0800
Subject: [PATCH] Honor 'hidden' parameter in 'stack environment show' command
Related-Bug: #1999665
Story: 2010484
Task: 47052
Change-Id: Ifc51ff6a4deab05002ccded59383416f9a586aa0
(cherry picked from commit 1305a3152f75c6e62ec5094ea2bfc38f165204cf)
---
heat/engine/service.py | 12 +++++++++++-
heat/tests/test_engine_service.py | 3 ++-
...meter-in-stack-env-show-cmd-062065545dfef82a.yaml | 4 ++++
3 files changed, 17 insertions(+), 2 deletions(-)
create mode 100644 releasenotes/notes/honor-hidden-parameter-in-stack-env-show-cmd-062065545dfef82a.yaml
diff --git a/heat/engine/service.py b/heat/engine/service.py
index 285777156..e9268d509 100644
--- a/heat/engine/service.py
+++ b/heat/engine/service.py
@@ -12,6 +12,7 @@
# under the License.
import collections
+import copy
import datetime
import functools
import itertools
@@ -1340,7 +1341,16 @@ class EngineService(service.ServiceBase):
:rtype: dict
"""
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
def get_files(self, cnxt, stack_identity):
diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py
index 854979c27..f7843a677 100644
--- a/heat/tests/test_engine_service.py
+++ b/heat/tests/test_engine_service.py
@@ -1014,11 +1014,12 @@ class StackServiceTest(common.HeatTestCase):
env = {'parameters': {'KeyName': 'EnvKey'}}
tmpl = templatem.Template(t)
stack = parser.Stack(self.ctx, 'get_env_stack', tmpl)
+ stack.store()
mock_get_stack = self.patchobject(self.eng, '_get_stack')
mock_get_stack.return_value = mock.MagicMock()
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
found = self.eng.get_environment(self.ctx, stack.identifier())
diff --git a/releasenotes/notes/honor-hidden-parameter-in-stack-env-show-cmd-062065545dfef82a.yaml b/releasenotes/notes/honor-hidden-parameter-in-stack-env-show-cmd-062065545dfef82a.yaml
new file mode 100644
index 000000000..385e3d4d5
--- /dev/null
+++ b/releasenotes/notes/honor-hidden-parameter-in-stack-env-show-cmd-062065545dfef82a.yaml
@@ -0,0 +1,4 @@
+---
+fixes:
+ - |
+ Honor ``hidden`` parameter in ``stack environment show`` command
--
2.34.1