Skip to content
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
10 changes: 7 additions & 3 deletions src/azure-cli-core/azure/cli/core/aaz/_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 = {}
Expand All @@ -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():
Expand Down
89 changes: 87 additions & 2 deletions src/azure-cli-core/azure/cli/core/tests/test_aaz_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -602,6 +603,7 @@ def test_aaz_object_with_polymorphism_support(self):
"classification": "BenignPositive",
"classification_comment": "comments 1",
"severity": "High",
"secret": "secret-value",
}
},
{
Expand All @@ -621,6 +623,7 @@ def test_aaz_object_with_polymorphism_support(self):
"classification": "BenignPositive",
"classification_comment": "comments 1",
"severity": "High",
"secret": "secret-value",
}
},
{
Expand Down Expand Up @@ -653,6 +656,7 @@ def test_aaz_object_with_polymorphism_support(self):
"classification": "BenignPositive",
"classification_comment": "comments 1",
"severity": "High",
"secret": "secret-value",
}
},
{
Expand Down Expand Up @@ -688,6 +692,7 @@ def test_aaz_object_with_polymorphism_support(self):
"classification": "BenignPositive",
"classification_comment": "comments 1",
"severity": "High",
"secret": "secret-value",
}
},
{
Expand Down Expand Up @@ -715,6 +720,7 @@ def test_aaz_object_with_polymorphism_support(self):
"classification": "BenignPositive",
"classification_comment": "comments 1",
"severity": "High",
"secret": "secret-value",
}
},
{
Expand All @@ -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",
Expand All @@ -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
Expand Down