From dd81200255e6a567b23d396d0b2801e79c277526 Mon Sep 17 00:00:00 2001 From: Sylvia Lei Date: Mon, 10 Feb 2020 19:25:26 +0800 Subject: [PATCH] Add a table transformer for 'az acr task identity show' --- .../azure/cli/command_modules/acr/_format.py | 16 ++++++++++++++++ .../azure/cli/command_modules/acr/commands.py | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_format.py b/src/azure-cli/azure/cli/command_modules/acr/_format.py index 64927fd83bf..99ab505f413 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_format.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_format.py @@ -50,6 +50,10 @@ def task_output_format(result): return _output_format(result, _task_format_group) +def task_identity_format(result): + return _output_format(result, _task_identity_format_group) + + def taskrun_output_format(result): return _output_format(result, _taskrun_format_group) @@ -188,6 +192,18 @@ def _task_format_group(item): ]) +def _task_identity_format_group(item): + identities = _get_array_value(item, 'userAssignedIdentities') + identities_by_line = str('\n'.join(identities)) if identities else ' ' + + return OrderedDict([ + ('PRINCIPAL ID', _get_value(item, 'principalId')), + ('TENANT ID', _get_value(item, 'tenantId')), + ('TYPE', _get_value(item, 'type')), + ('USER ASSIGNED IDENTITIES', identities_by_line) + ]) + + def _taskrun_format_group(item): return OrderedDict([ ('NAME', _get_value(item, 'name')), diff --git a/src/azure-cli/azure/cli/command_modules/acr/commands.py b/src/azure-cli/azure/cli/command_modules/acr/commands.py index 93a92c079b6..4920bbef4fd 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/commands.py +++ b/src/azure-cli/azure/cli/command_modules/acr/commands.py @@ -17,6 +17,7 @@ replication_output_format, build_output_format, task_output_format, + task_identity_format, taskrun_output_format, run_output_format, helm_list_output_format, @@ -223,7 +224,7 @@ def load_command_table(self, _): # pylint: disable=too-many-statements g.command('update', 'acr_task_update') g.command('identity assign', 'acr_task_identity_assign') g.command('identity remove', 'acr_task_identity_remove') - g.command('identity show', 'acr_task_identity_show') + g.command('identity show', 'acr_task_identity_show', table_transformer=task_identity_format) g.command('credential add', 'acr_task_credential_add') g.command('credential update', 'acr_task_credential_update') g.command('credential remove', 'acr_task_credential_remove')