Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: redesign parameters to specify APIM instance for import-from-apim command #45

Merged
merged 3 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@
class ImportFromApim(AAZCommand):
"""Imports APIs from an Azure API Management service instance.

:example: Import From APIM
az apic service import-from-apim -g api-center-test --service-name contosoeuap --source-resource-ids '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/servicegroup/providers/Microsoft.ApiManagement/service/contoso/apis/contosoapi'
:example: Import all APIs from APIM in same resource group
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@juliajuju93 can you help review the examples here? Please leave comments or approve the PR if they look good to you.

az apic service import-from-apim -g api-center-test --service-name contoso-apic --apim-name contoso-apim --apim-apis *

:example: Import selected APIs from APIM in same resource group
az apic service import-from-apim -g api-center-test --service-name contoso-apic --apim-name contoso-apim --apim-apis [echo,foo]

:example: Import all APIs from APIM in another subscription and resource group
az apic service import-from-apim -g api-center-test --service-name contoso-apic --apim-subscription 00000000-0000-0000-0000-000000000000 --apim-resource-group apim-rg --apim-name contoso-apim --apim-apis *
"""

_aaz_info = {
Expand Down
57 changes: 56 additions & 1 deletion src/apic-extension/azext_apic_extension/command_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
)
from .aaz.latest.apic.service import ImportFromApim

from azure.cli.core.aaz._arg import AAZStrArg, AAZListArg


class DefaultWorkspaceParameter:
# pylint: disable=too-few-public-methods
Expand Down Expand Up @@ -205,5 +207,58 @@ class ImportFromApimExtension(ImportFromApim):
def _build_arguments_schema(cls, *args, **kwargs):
# pylint: disable=protected-access
args_schema = super()._build_arguments_schema(*args, **kwargs)
args_schema.source_resource_ids._required = True
args_schema.source_resource_ids._required = False
args_schema.source_resource_ids._registered = False

args_schema.apim_subscription_id = AAZStrArg(
options=["--apim-subscription"],
help="The subscription id of the source APIM instance.",
required=False
)

args_schema.apim_resource_group = AAZStrArg(
options=["--apim-resource-group"],
help="The resource group of the source APIM instance.",
required=False
)

args_schema.apim_name = AAZStrArg(
options=["--apim-name"],
help="The name of the source APIM instance.",
required=True
)

args_schema.apim_apis = AAZListArg(
options=["--apim-apis"],
help="The APIs to be imported.",
required=True
)
args_schema.apim_apis.Element = AAZStrArg()

return args_schema

def pre_operations(self):
super().pre_operations()
args = self.ctx.args

# compose sourceResourceIds property in the request body
# Use same subscription id and resource group as API Center by default
resource_group = args.resource_group
subscription_id = self.ctx.subscription_id

# Use user provided subscription id
if args.apim_subscription_id:
subscription_id = args.apim_subscription_id

# Use user provided resource group
if args.apim_resource_group:
resource_group = args.apim_resource_group

source_resource_ids = []
for item in args.apim_apis:
source_resource_ids.append(
f"/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/"
f"Microsoft.ApiManagement/service/{args.apim_name}/apis/{item}"
)

args.source_resource_ids = source_resource_ids
Loading
Loading