From 3eb2b4aaf0edbe813f6db5e7a7e8b4f5a38fe99d Mon Sep 17 00:00:00 2001 From: Chaoyi Yuan Date: Wed, 3 Apr 2024 12:30:28 +0800 Subject: [PATCH] fix: workspace parameter should not be required (#2) --- src/apic-extension/README.md | 17 ++++------ .../azext_apic_extension/commands.py | 14 +++++++++ .../azext_apic_extension/custom.py | 31 +++++++++++++++++++ 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/src/apic-extension/README.md b/src/apic-extension/README.md index 93d4b9f3b52..0a50541b50c 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" @@ -50,10 +45,10 @@ 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" --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 @@ -90,10 +85,10 @@ 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" --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 @@ -127,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 @@ -209,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 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 a5959e53898..298454e4355 100644 --- a/src/apic-extension/azext_apic_extension/custom.py +++ b/src/apic-extension/azext_apic_extension/custom.py @@ -23,9 +23,40 @@ 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 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._registered = False + 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(DefaultWorkspaceParameter, UpdateAPIDeployment): + pass + +class UpdateAPIVersionExtension(DefaultWorkspaceParameter, UpdateAPIVersion): + pass + +class UpdateEnvironmentExtension(DefaultWorkspaceParameter, UpdateEnvironment): + pass class ImportSpecificationExtension(ImportSpecification): @classmethod