From ea3069403cb90b95783d13640d479150dfc4f865 Mon Sep 17 00:00:00 2001 From: Chaoyi Yuan Date: Fri, 29 Mar 2024 16:23:36 +0800 Subject: [PATCH 1/4] fix: workspace parameter should not be required --- .../azext_apic_extension/commands.py | 14 ++++++ .../azext_apic_extension/custom.py | 45 +++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/apic-extension/azext_apic_extension/commands.py b/src/apic-extension/azext_apic_extension/commands.py index c4ea801b8de..5ad21c5d2c5 100644 --- a/src/apic-extension/azext_apic_extension/commands.py +++ b/src/apic-extension/azext_apic_extension/commands.py @@ -14,10 +14,16 @@ from .custom import ExportMetadataSchemaExtension from .custom import CreateMetadataSchemaExtension from .custom import UpdateMetadataSchemaExtension +from .custom import UpdateAPIExtension +from .custom import UpdateAPIDefinitionExtension +from .custom import UpdateAPIVersionExtension +from .custom import UpdateAPIDeploymentExtension +from .custom import UpdateEnvironmentExtension def load_command_table(self, _): # pylint: disable=unused-argument with self.command_group('apic api definition') as g: + self.command_table['apic api definition update'] = UpdateAPIDefinitionExtension(loader=self) self.command_table['apic api definition import-specification'] = ImportSpecificationExtension(loader=self) self.command_table['apic api definition export-specification'] = ExportSpecificationExtension(loader=self) with self.command_group('apic metadata-schema') as g: @@ -26,3 +32,11 @@ def load_command_table(self, _): # pylint: disable=unused-argument self.command_table['apic metadata-schema export-metadata-schema'] = ExportMetadataSchemaExtension(loader=self) with self.command_group('apic api') as g: g.custom_command("register", "register_apic") + with self.command_group('apic api') as g: + self.command_table['apic api update'] = UpdateAPIExtension(loader=self) + with self.command_group('apic api version') as g: + self.command_table['apic api version update'] = UpdateAPIVersionExtension(loader=self) + with self.command_group('apic api deployment') as g: + self.command_table['apic api deployment update'] = UpdateAPIDeploymentExtension(loader=self) + with self.command_group('apic environment') as g: + self.command_table['apic environment update'] = UpdateEnvironmentExtension(loader=self) diff --git a/src/apic-extension/azext_apic_extension/custom.py b/src/apic-extension/azext_apic_extension/custom.py index b9d015ded75..d08815ce9a5 100644 --- a/src/apic-extension/azext_apic_extension/custom.py +++ b/src/apic-extension/azext_apic_extension/custom.py @@ -22,10 +22,55 @@ from .aaz.latest.apic.metadata_schema import Create from .aaz.latest.apic.metadata_schema import Update from .aaz.latest.apic.metadata_schema import ExportMetadataSchema +from .aaz.latest.apic.api import Update as UpdateAPI +from .aaz.latest.apic.api.definition import Update as UpdateAPIDefinition +from .aaz.latest.apic.api.deployment import Update as UpdateAPIDeployment +from .aaz.latest.apic.api.version import Update as UpdateAPIVersion +from .aaz.latest.apic.environment import Update as UpdateEnvironment logger = get_logger(__name__) +class UpdateAPIExtension(UpdateAPI): + @classmethod + def _build_arguments_schema(cls, *args, **kwargs): + args_schema = super()._build_arguments_schema(*args, **kwargs) + args_schema.workspace_name._required = False + args_schema.workspace_name._default = "default" + return args_schema + +class UpdateAPIDefinitionExtension(UpdateAPIDefinition): + @classmethod + def _build_arguments_schema(cls, *args, **kwargs): + args_schema = super()._build_arguments_schema(*args, **kwargs) + args_schema.workspace_name._required = False + args_schema.workspace_name._default = "default" + return args_schema + +class UpdateAPIDeploymentExtension(UpdateAPIDeployment): + @classmethod + def _build_arguments_schema(cls, *args, **kwargs): + args_schema = super()._build_arguments_schema(*args, **kwargs) + args_schema.workspace_name._required = False + args_schema.workspace_name._default = "default" + return args_schema + +class UpdateAPIVersionExtension(UpdateAPIVersion): + @classmethod + def _build_arguments_schema(cls, *args, **kwargs): + args_schema = super()._build_arguments_schema(*args, **kwargs) + args_schema.workspace_name._required = False + args_schema.workspace_name._default = "default" + return args_schema + +class UpdateEnvironmentExtension(UpdateEnvironment): + @classmethod + def _build_arguments_schema(cls, *args, **kwargs): + args_schema = super()._build_arguments_schema(*args, **kwargs) + args_schema.workspace_name._required = False + args_schema.workspace_name._default = "default" + return args_schema + class ImportSpecificationExtension(ImportSpecification): @classmethod def _build_arguments_schema(cls, *args, **kwargs): From 3044daef0e27b20a8bdc38137ee979b10b65f933 Mon Sep 17 00:00:00 2001 From: Chaoyi Yuan Date: Tue, 2 Apr 2024 14:21:01 +0800 Subject: [PATCH 2/4] feat: hide workspace param --- .../azext_apic_extension/custom.py | 48 +++++++------------ 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/src/apic-extension/azext_apic_extension/custom.py b/src/apic-extension/azext_apic_extension/custom.py index d08815ce9a5..d1356e91881 100644 --- a/src/apic-extension/azext_apic_extension/custom.py +++ b/src/apic-extension/azext_apic_extension/custom.py @@ -30,46 +30,32 @@ logger = get_logger(__name__) - -class UpdateAPIExtension(UpdateAPI): +class DefaultWorkspaceParameter: @classmethod def _build_arguments_schema(cls, *args, **kwargs): args_schema = super()._build_arguments_schema(*args, **kwargs) args_schema.workspace_name._required = False - args_schema.workspace_name._default = "default" + args_schema.workspace_name._registered = False return args_schema -class UpdateAPIDefinitionExtension(UpdateAPIDefinition): - @classmethod - def _build_arguments_schema(cls, *args, **kwargs): - args_schema = super()._build_arguments_schema(*args, **kwargs) - args_schema.workspace_name._required = False - args_schema.workspace_name._default = "default" - return args_schema + def pre_operations(self): + args = self.ctx.args + args.workspace_name = "default" + +class UpdateAPIExtension(DefaultWorkspaceParameter, UpdateAPI): + pass + +class UpdateAPIDefinitionExtension(DefaultWorkspaceParameter, UpdateAPIDefinition): + pass -class UpdateAPIDeploymentExtension(UpdateAPIDeployment): - @classmethod - def _build_arguments_schema(cls, *args, **kwargs): - args_schema = super()._build_arguments_schema(*args, **kwargs) - args_schema.workspace_name._required = False - args_schema.workspace_name._default = "default" - return args_schema +class UpdateAPIDeploymentExtension(DefaultWorkspaceParameter, UpdateAPIDeployment): + pass -class UpdateAPIVersionExtension(UpdateAPIVersion): - @classmethod - def _build_arguments_schema(cls, *args, **kwargs): - args_schema = super()._build_arguments_schema(*args, **kwargs) - args_schema.workspace_name._required = False - args_schema.workspace_name._default = "default" - return args_schema +class UpdateAPIVersionExtension(DefaultWorkspaceParameter, UpdateAPIVersion): + pass -class UpdateEnvironmentExtension(UpdateEnvironment): - @classmethod - def _build_arguments_schema(cls, *args, **kwargs): - args_schema = super()._build_arguments_schema(*args, **kwargs) - args_schema.workspace_name._required = False - args_schema.workspace_name._default = "default" - return args_schema +class UpdateEnvironmentExtension(DefaultWorkspaceParameter, UpdateEnvironment): + pass class ImportSpecificationExtension(ImportSpecification): @classmethod From 7b19912fb6aa250f88fd1d8001b9db89106f31b3 Mon Sep 17 00:00:00 2001 From: Chaoyi Yuan Date: Wed, 3 Apr 2024 10:05:08 +0800 Subject: [PATCH 3/4] doc: remove workspace param in example --- src/apic-extension/README.md | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/apic-extension/README.md b/src/apic-extension/README.md index a3c17e2279e..797b3051611 100644 --- a/src/apic-extension/README.md +++ b/src/apic-extension/README.md @@ -35,11 +35,6 @@ az apic service delete --resource-group api-center-test --service-name contosoeu az apic service delete --resource-group arpi-test-rg1 -s apictestcli3 ``` -Show Workspace Example -``` -Az apic workspace show -g api-center-test -s contosoeuap --name devdiv -``` - Create API Examples ``` az apic api create -g api-center-test -s contosoeuap --name echo-api --title "Echo API" --kind "rest" @@ -53,7 +48,7 @@ Update API Examples az apic api update -g api-center-test -s contosoeuap --name echo-api --summary "Basic REST API service" -w default ``` ``` -az apic api update --resource-group api-center-test -s contosoeuap --name echo-api --summary "Basic REST API service" --workspace-name default +az apic api update --resource-group api-center-test -s contosoeuap --name echo-api --summary "Basic REST API service" ``` LIST Api Example @@ -93,7 +88,7 @@ UPDATE Api Version Examples Az apic api version update -g api-center-test -s contosoeuap --api-name echo-api --name 2023-01-01 --title "2023-01-01" -w default ``` ``` -az apic api version update --resource-group api-center-test --service-name contosoeuap --api-name echo-api --name 2023-01-01 --title "2023-01-01" --workspace-name default +az apic api version update --resource-group api-center-test --service-name contosoeuap --api-name echo-api --name 2023-01-01 --title "2023-01-01" ``` LIST Api Version Examples From d4843539fc338b6ef44c11ce2884ebb645fca087 Mon Sep 17 00:00:00 2001 From: Chaoyi Yuan Date: Wed, 3 Apr 2024 11:12:15 +0800 Subject: [PATCH 4/4] doc: remove workspace param in example --- src/apic-extension/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/apic-extension/README.md b/src/apic-extension/README.md index 797b3051611..13de4aef74e 100644 --- a/src/apic-extension/README.md +++ b/src/apic-extension/README.md @@ -45,7 +45,7 @@ az apic api create --resource-group api-center-test --service-name contosoeuap - Update API Examples ``` -az apic api update -g api-center-test -s contosoeuap --name echo-api --summary "Basic REST API service" -w default +az apic api update -g api-center-test -s contosoeuap --name echo-api --summary "Basic REST API service" ``` ``` az apic api update --resource-group api-center-test -s contosoeuap --name echo-api --summary "Basic REST API service" @@ -85,7 +85,7 @@ az apic api version create --resource-group api-center-test --service-name conto UPDATE Api Version Examples ``` -Az apic api version update -g api-center-test -s contosoeuap --api-name echo-api --name 2023-01-01 --title "2023-01-01" -w default +Az apic api version update -g api-center-test -s contosoeuap --api-name echo-api --name 2023-01-01 --title "2023-01-01" ``` ``` az apic api version update --resource-group api-center-test --service-name contosoeuap --api-name echo-api --name 2023-01-01 --title "2023-01-01" @@ -122,7 +122,7 @@ az apic api definition create -g api-center-test -s contosoeuap --api-name echo- UPDATE API Definition Example ``` -az apic api definition update -g api-center-test -s contosoeuap --api-name echo-api --version 2023-01-01 --name "openapi" --title "OpenAPI" -w default +az apic api definition update -g api-center-test -s contosoeuap --api-name echo-api --version 2023-01-01 --name "openapi" --title "OpenAPI" ``` SHOW API Definition Example @@ -204,7 +204,7 @@ Where envcreate1.json contains UPDATE Environment ``` -az apic environment update -g api-center-test -s contosoeuap --name public --title "Public cloud" -w default +az apic environment update -g api-center-test -s contosoeuap --name public --title "Public cloud" ``` LIST Environment