From 866a41c6eeac618577cdec732811f2ac5023e742 Mon Sep 17 00:00:00 2001 From: Yitong Feng Date: Thu, 4 Aug 2022 18:55:00 +0800 Subject: [PATCH] [AKS][TA] remove source_resource_id of rolebinding update command --- src/aks-preview/azext_aks_preview/_help.py | 3 --- src/aks-preview/azext_aks_preview/_params.py | 15 +++++++++------ src/aks-preview/azext_aks_preview/commands.py | 4 ++-- src/aks-preview/azext_aks_preview/custom.py | 16 ++++++++++++++-- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/aks-preview/azext_aks_preview/_help.py b/src/aks-preview/azext_aks_preview/_help.py index 4255dff9454..889303ad569 100644 --- a/src/aks-preview/azext_aks_preview/_help.py +++ b/src/aks-preview/azext_aks_preview/_help.py @@ -1850,9 +1850,6 @@ - name: --roles type: string short-summary: Specify the space-separated roles. - - name: --source-resource-id -s - type: string - short-summary: Specify the source resource id of the binding. """ helps['aks trustedaccess rolebinding delete'] = """ diff --git a/src/aks-preview/azext_aks_preview/_params.py b/src/aks-preview/azext_aks_preview/_params.py index 59433eeabf0..6c3e7799537 100644 --- a/src/aks-preview/azext_aks_preview/_params.py +++ b/src/aks-preview/azext_aks_preview/_params.py @@ -692,12 +692,15 @@ def load_arguments(self, _): c.argument('role_binding_name', options_list=[ '--name', '-n'], required=True, help='The role binding name.') - for scope in ['aks trustedaccess rolebinding create', 'aks trustedaccess rolebinding update']: - with self.argument_context(scope) as c: - c.argument('roles', nargs='*', - help='space-separated roles: Microsoft.Demo/samples/reader Microsoft.Demo/samples/writer ...') - c.argument('source_resource_id', options_list=['--source-resource-id', '-s'], - help='The source resource id of the binding') + with self.argument_context('aks trustedaccess rolebinding create') as c: + c.argument('roles', nargs='*', + help='space-separated roles: Microsoft.Demo/samples/reader Microsoft.Demo/samples/writer ...') + c.argument('source_resource_id', options_list=['--source-resource-id', '-s'], + help='The source resource id of the binding') + + with self.argument_context('aks trustedaccess rolebinding update') as c: + c.argument('roles', nargs='*', + help='space-separated roles: Microsoft.Demo/samples/reader Microsoft.Demo/samples/writer ...') def _get_default_install_location(exe_name): diff --git a/src/aks-preview/azext_aks_preview/commands.py b/src/aks-preview/azext_aks_preview/commands.py index f3e032c0d11..9766512e77d 100644 --- a/src/aks-preview/azext_aks_preview/commands.py +++ b/src/aks-preview/azext_aks_preview/commands.py @@ -199,6 +199,6 @@ def load_command_table(self, _): with self.command_group('aks trustedaccess rolebinding', trustedaccess_role_binding_sdk, client_factory=cf_trustedaccess_role_binding) as g: g.custom_command('list', 'aks_trustedaccess_role_binding_list') g.custom_show_command('show', 'aks_trustedaccess_role_binding_get') - g.custom_command('create', 'aks_trustedaccess_role_binding_create_or_update') - g.custom_command('update', 'aks_trustedaccess_role_binding_create_or_update') + g.custom_command('create', 'aks_trustedaccess_role_binding_create') + g.custom_command('update', 'aks_trustedaccess_role_binding_update') g.custom_command('delete', 'aks_trustedaccess_role_binding_delete', confirmation=True) diff --git a/src/aks-preview/azext_aks_preview/custom.py b/src/aks-preview/azext_aks_preview/custom.py index bd893840ce1..16e601a906a 100644 --- a/src/aks-preview/azext_aks_preview/custom.py +++ b/src/aks-preview/azext_aks_preview/custom.py @@ -2218,8 +2218,8 @@ def aks_trustedaccess_role_binding_get(cmd, client, resource_group_name, cluster return client.get(resource_group_name, cluster_name, role_binding_name) -def aks_trustedaccess_role_binding_create_or_update(cmd, client, resource_group_name, cluster_name, role_binding_name, - source_resource_id, roles): +def aks_trustedaccess_role_binding_create(cmd, client, resource_group_name, cluster_name, role_binding_name, + source_resource_id, roles): TrustedAccessRoleBinding = cmd.get_models( "TrustedAccessRoleBinding", resource_type=CUSTOM_MGMT_AKS_PREVIEW, @@ -2229,5 +2229,17 @@ def aks_trustedaccess_role_binding_create_or_update(cmd, client, resource_group_ return client.create_or_update(resource_group_name, cluster_name, role_binding_name, roleBinding) +def aks_trustedaccess_role_binding_update(cmd, client, resource_group_name, cluster_name, role_binding_name, roles): + TrustedAccessRoleBinding = cmd.get_models( + "TrustedAccessRoleBinding", + resource_type=CUSTOM_MGMT_AKS_PREVIEW, + operation_group="trusted_access_role_bindings", + ) + existedBinding = client.get(resource_group_name, cluster_name, role_binding_name) + + roleBinding = TrustedAccessRoleBinding(source_resource_id=existedBinding.source_resource_id, roles=roles) + return client.create_or_update(resource_group_name, cluster_name, role_binding_name, roleBinding) + + def aks_trustedaccess_role_binding_delete(cmd, client, resource_group_name, cluster_name, role_binding_name): return client.delete(resource_group_name, cluster_name, role_binding_name)