Skip to content

Commit

Permalink
fix: workspace parameter should not be required (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackchoey authored Apr 3, 2024
1 parent 6596e67 commit 3eb2b4a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/apic-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/apic-extension/azext_apic_extension/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
31 changes: 31 additions & 0 deletions src/apic-extension/azext_apic_extension/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3eb2b4a

Please sign in to comment.