diff --git a/src/azure-cli-core/azure/cli/core/aaz/_command.py b/src/azure-cli-core/azure/cli/core/aaz/_command.py index 289e4195087..c47780b7dbf 100644 --- a/src/azure-cli-core/azure/cli/core/aaz/_command.py +++ b/src/azure-cli-core/azure/cli/core/aaz/_command.py @@ -180,7 +180,7 @@ def update_argument(self, param_name, argtype): super().update_argument(param_name, argtype) @staticmethod - def deserialize_output(value, client_flatten=True): + def deserialize_output(value, client_flatten=True, secret_hidden=True): """ Deserialize output of a command. """ if not isinstance(value, AAZBaseValue): @@ -191,7 +191,7 @@ def processor(schema, result): if result == AAZUndefined: return result - if client_flatten and isinstance(schema, AAZObjectType): + if isinstance(schema, AAZObjectType): # handle client flatten in result disc_schema = schema.get_discriminator(result) new_result = {} @@ -205,7 +205,11 @@ def processor(schema, result): # get k_schema from discriminator definition k_schema = disc_schema[k] - if k_schema._flags.get('client_flatten', False): + if secret_hidden and k_schema._flags.get('secret', False): + # hidden secret properties in output + continue + + if client_flatten and k_schema._flags.get('client_flatten', False): # flatten k when there are client_flatten flag in it's schema assert isinstance(k_schema, AAZObjectType) and isinstance(v, dict) for sub_k, sub_v in v.items(): diff --git a/src/azure-cli-core/azure/cli/core/tests/test_aaz_field.py b/src/azure-cli-core/azure/cli/core/tests/test_aaz_field.py index 246c5cc8de5..d623d1c4181 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_aaz_field.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_aaz_field.py @@ -589,6 +589,7 @@ def test_aaz_object_with_polymorphism_support(self): action_configuration.classification = AAZStrType() action_configuration.classification_comment = AAZStrType() action_configuration.severity = AAZStrType() + action_configuration.secret = AAZStrType(flags={"secret": True}) disc_run_playbook = element.discriminate_by('action_type', 'RunPlaybook') disc_run_playbook.logic_app_resource_id = AAZStrType() @@ -602,6 +603,7 @@ def test_aaz_object_with_polymorphism_support(self): "classification": "BenignPositive", "classification_comment": "comments 1", "severity": "High", + "secret": "secret-value", } }, { @@ -621,6 +623,7 @@ def test_aaz_object_with_polymorphism_support(self): "classification": "BenignPositive", "classification_comment": "comments 1", "severity": "High", + "secret": "secret-value", } }, { @@ -653,6 +656,7 @@ def test_aaz_object_with_polymorphism_support(self): "classification": "BenignPositive", "classification_comment": "comments 1", "severity": "High", + "secret": "secret-value", } }, { @@ -688,6 +692,7 @@ def test_aaz_object_with_polymorphism_support(self): "classification": "BenignPositive", "classification_comment": "comments 1", "severity": "High", + "secret": "secret-value", } }, { @@ -715,6 +720,7 @@ def test_aaz_object_with_polymorphism_support(self): "classification": "BenignPositive", "classification_comment": "comments 1", "severity": "High", + "secret": "secret-value", } }, { @@ -733,8 +739,8 @@ def test_aaz_object_with_polymorphism_support(self): ] }) - # test client flatten - self.assertTrue(AAZCommand.deserialize_output(v, client_flatten=True) == { + # test client flatten and secret hidden + self.assertTrue(AAZCommand.deserialize_output(v, client_flatten=True, secret_hidden=True) == { "actions": [ { "action_type": "ModifyProperties", @@ -757,6 +763,85 @@ def test_aaz_object_with_polymorphism_support(self): ] }) + self.assertTrue(AAZCommand.deserialize_output(v, client_flatten=True, secret_hidden=False) == { + "actions": [ + { + "action_type": "ModifyProperties", + "order": 0, + "classification": "BenignPositive", + "classification_comment": "comments 1", + "severity": "High", + "secret": "secret-value", + }, + { + "action_type": "RunPlaybook", + "order": 1, + "logic_app_resource_id": "123333", + "tenant_id": "111111", + }, + { + "action_type": "ModifyProperties", + "order": 2, + "classification": "FalsePositive" + } + ] + }) + + self.assertTrue(AAZCommand.deserialize_output(v, client_flatten=False, secret_hidden=True) == { + "actions": [ + { + "action_type": "ModifyProperties", + "order": 0, + "action_configuration": { + "classification": "BenignPositive", + "classification_comment": "comments 1", + "severity": "High", + } + }, + { + "action_type": "RunPlaybook", + "order": 1, + "logic_app_resource_id": "123333", + "tenant_id": "111111", + }, + { + "action_type": "ModifyProperties", + "order": 2, + "action_configuration": { + "classification": "FalsePositive" + } + } + ] + }) + + self.assertTrue(AAZCommand.deserialize_output(v, client_flatten=False, secret_hidden=False) == { + "actions": [ + { + "action_type": "ModifyProperties", + "order": 0, + "action_configuration": { + "classification": "BenignPositive", + "classification_comment": "comments 1", + "severity": "High", + "secret": "secret-value", + } + }, + { + "action_type": "RunPlaybook", + "order": 1, + "logic_app_resource_id": "123333", + "tenant_id": "111111", + }, + { + "action_type": "ModifyProperties", + "order": 2, + "action_configuration": { + "classification": "FalsePositive" + } + } + ] + }) + def test_aaz_types_process_patch_data(self): from azure.cli.core.aaz._field_type import AAZObjectType, AAZDictType, AAZListType, \ AAZIntType, AAZStrType, AAZBoolType, AAZFloatType