Skip to content

Commit

Permalink
feat: rename command and param names (Azure#85)
Browse files Browse the repository at this point in the history
* feat: rename command and param names

* doc: update comments

* doc: update sample
  • Loading branch information
blackchoey authored Dec 18, 2024
1 parent 472231f commit 58016fd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def _build_arguments_schema(cls, *args, **kwargs):
# define Arg Group ""

_args_schema = cls._args_schema
_args_schema.integration_id = AAZStrArg(
options=["--integration-id"],
_args_schema.integration_name = AAZStrArg(
options=["-i", "--integration-name"],
help="The name of the integration.",
required=True,
fmt=AAZStrArgFormat(
Expand Down Expand Up @@ -191,7 +191,7 @@ def error_format(self):
def url_parameters(self):
parameters = {
**self.serialize_url_param(
"apiSourceName", self.ctx.args.integration_id,
"apiSourceName", self.ctx.args.integration_name,
required=True,
),
**self.serialize_url_param(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def _build_arguments_schema(cls, *args, **kwargs):
# define Arg Group ""

_args_schema = cls._args_schema
_args_schema.integration_id = AAZStrArg(
options=["--integration-id"],
_args_schema.integration_name = AAZStrArg(
options=["-i", "--integration-name"],
help="The name of the integration.",
required=True,
id_part="child_name_2",
Expand Down Expand Up @@ -127,7 +127,7 @@ def error_format(self):
def url_parameters(self):
parameters = {
**self.serialize_url_param(
"apiSourceName", self.ctx.args.integration_id,
"apiSourceName", self.ctx.args.integration_name,
required=True,
),
**self.serialize_url_param(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def _build_arguments_schema(cls, *args, **kwargs):
# define Arg Group ""

_args_schema = cls._args_schema
_args_schema.integration_id = AAZStrArg(
options=["--integration-id"],
_args_schema.integration_name = AAZStrArg(
options=["-i", "--integration-name"],
help="The name of the integration.",
required=True,
id_part="child_name_2",
Expand Down Expand Up @@ -128,7 +128,7 @@ def error_format(self):
def url_parameters(self):
parameters = {
**self.serialize_url_param(
"apiSourceName", self.ctx.args.integration_id,
"apiSourceName", self.ctx.args.integration_name,
required=True,
),
**self.serialize_url_param(
Expand Down
69 changes: 25 additions & 44 deletions src/apic-extension/azext_apic_extension/command_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

from azure.cli.core.aaz._arg import AAZStrArg, AAZListArg, AAZResourceIdArg
from azure.cli.core.aaz import register_command
from msrestazure.tools import is_valid_resource_id


class DefaultWorkspaceParameter:
Expand Down Expand Up @@ -319,18 +320,18 @@ class ShowIntegrationExtension(DefaultWorkspaceParameter, ShowIntegration):


@register_command(
"apic integration create azure-api-management",
"apic integration create apim",
is_preview=True,
)
class CreateApimIntegration(DefaultWorkspaceParameter, CreateIntegration):
# pylint: disable=C0301
"""Add Azure APIM as an API source
:example: Add Azure APIM in the same resource group as the Azure API Center instance as an API source
az apic integration create azure-api-management -g contoso-resources -n contoso --integration-id sync-from-my-apim --apim-name myapim
az apic integration create apim -g contoso-resources -n contoso --integration-name sync-from-my-apim --azure-apim myapim
:example: Add Azure APIM in another resource group as an API source
az apic integration create azure-api-management -g contoso-resources -n contoso --integration-id sync-from-my-apim --apim-name myapim --apim-resource-group myapim-resource-group
az apic integration create apim -g contoso-resources -n contoso --integration-name sync-from-my-apim --azure-apim /subscriptions/12345678-1234-1234-1234-123456789abc/resourceGroups/samplegroup/providers/Microsoft.ApiManagement/service/sampleapim
"""
# pylint: enable=C0301
Expand All @@ -354,24 +355,10 @@ def _build_arguments_schema(cls, *args, **kwargs):
help="The resource ID of the managed identity that has access to the API Management instance.",
)

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

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

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

Expand All @@ -382,20 +369,14 @@ def pre_operations(self):
super().pre_operations()
args = self.ctx.args

# 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

apim_resource_id = (f"/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/"
f"Microsoft.ApiManagement/service/{args.apim_name}")
if not is_valid_resource_id(args.azure_apim.to_serialized_data()):
# The APIM is in the same resource group
resource_group = args.resource_group
subscription_id = self.ctx.subscription_id
apim_resource_id = (f"/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/"
f"Microsoft.ApiManagement/service/{args.azure_apim}")
else:
apim_resource_id = args.azure_apim

args.azure_api_management_source = {
"msi_resource_id": args.msi_resource_id,
Expand All @@ -407,15 +388,15 @@ def pre_operations(self):


@register_command(
"apic integration create amazon-api-gateway",
"apic integration create aws",
is_preview=True,
)
class CreateAmazonApiGatewayIntegration(DefaultWorkspaceParameter, CreateIntegration):
# pylint: disable=C0301
"""Add Amazon API Gateway as an API source
:example: Add Amazon API Gateway as an API source
az apic integration create amazon-api-gateway -g contoso-resources -n contoso --integration-id sync-from-my-amazon-api-gateway --access-key-reference https://mykey.vault.azure.net/secrets/AccessKey --secret-access-key-reference https://mykey.vault.azure.net/secrets/SecretAccessKey --region-name us-east-2
az apic integration create aws -g contoso-resources -n contoso --integration-name sync-from-my-amazon-api-gateway --aws-access-key-reference https://mykey.vault.azure.net/secrets/AccessKey --aws-secret-access-key-reference https://mykey.vault.azure.net/secrets/SecretAccessKey --aws-region-name us-east-2
"""

@classmethod
Expand All @@ -432,19 +413,19 @@ def _build_arguments_schema(cls, *args, **kwargs):
# Create arg group for AmazonApiGatewaySource
# Add separate parameters for access-key, secret-access-key, and region-name
args_schema.access_key = AAZStrArg(
options=["--access-key-reference", "-a"],
options=["--aws-access-key-reference", "-a"],
arg_group="AmazonApiGatewaySource",
help="Amazon API Gateway Access Key. Must be an Azure Key Vault secret reference.",
required=True,
)
args_schema.secret_access_key = AAZStrArg(
options=["--secret-access-key-reference", "-s"],
options=["--aws-secret-access-key-reference", "-s"],
arg_group="AmazonApiGatewaySource",
help="Amazon API Gateway Secret Access Key. Must be an Azure Key Vault secret reference.",
required=True,
)
args_schema.region_name = AAZStrArg(
options=["--region-name"],
options=["--aws-region-name"],
arg_group="AmazonApiGatewaySource",
help="Amazon API Gateway Region (ex. us-east-2).",
required=True,
Expand Down Expand Up @@ -474,15 +455,15 @@ def pre_operations(self):

# `az apic import` commands
@register_command(
"apic import amazon-api-gateway",
"apic import aws",
is_preview=True,
)
class ImportAmazonApiGatewaySource(DefaultWorkspaceParameter, Import):
# pylint: disable=C0301
"""Import an Amazon API Gateway API source
:example: Import an Amazon API Gateway API source
az apic import amazon-api-gateway -g contoso-resources -n contoso --access-key-reference https://mykey.vault.azure.net/secrets/AccessKey --secret-access-key-reference https://mykey.vault.azure.net/secrets/SecretAccessKey --region-name us-east-2
az apic import aws -g contoso-resources -n contoso --aws-access-key-reference https://mykey.vault.azure.net/secrets/AccessKey --aws-secret-access-key-reference https://mykey.vault.azure.net/secrets/SecretAccessKey --aws-region-name us-east-2
"""

@classmethod
Expand All @@ -500,19 +481,19 @@ def _build_arguments_schema(cls, *args, **kwargs):
# Create arg group for AmazonApiGatewaySource
# Add separate parameters for access-key, secret-access-key, and region-name
args_schema.access_key = AAZStrArg(
options=["--access-key-reference", "-a"],
options=["--aws-access-key-reference", "-a"],
arg_group="AmazonApiGatewaySource",
help="Amazon API Gateway Access Key. Must be an Azure Key Vault secret reference.",
required=True,
)
args_schema.secret_access_key = AAZStrArg(
options=["--secret-access-key-reference", "-s"],
options=["--aws-secret-access-key-reference", "-s"],
arg_group="AmazonApiGatewaySource",
help="Amazon API Gateway Secret Access Key. Must be an Azure Key Vault secret reference.",
required=True,
)
args_schema.region_name = AAZStrArg(
options=["--region-name"],
options=["--aws-region-name"],
arg_group="AmazonApiGatewaySource",
help="Amazon API Gateway Region (ex. us-east-2).",
required=True,
Expand Down

0 comments on commit 58016fd

Please sign in to comment.