|
48 | 48 | ) |
49 | 49 | from .aaz.latest.apic.service import ImportFromApim |
50 | 50 |
|
| 51 | +from azure.cli.core.aaz._arg import AAZStrArg, AAZListArg |
| 52 | + |
51 | 53 |
|
52 | 54 | class DefaultWorkspaceParameter: |
53 | 55 | # pylint: disable=too-few-public-methods |
@@ -205,5 +207,58 @@ class ImportFromApimExtension(ImportFromApim): |
205 | 207 | def _build_arguments_schema(cls, *args, **kwargs): |
206 | 208 | # pylint: disable=protected-access |
207 | 209 | args_schema = super()._build_arguments_schema(*args, **kwargs) |
208 | | - args_schema.source_resource_ids._required = True |
| 210 | + args_schema.source_resource_ids._required = False |
| 211 | + args_schema.source_resource_ids._registered = False |
| 212 | + |
| 213 | + args_schema.apim_subscription_id = AAZStrArg( |
| 214 | + options=["--apim-subscription"], |
| 215 | + help="The subscription id of the source APIM instance.", |
| 216 | + required=False |
| 217 | + ) |
| 218 | + |
| 219 | + args_schema.apim_resource_group = AAZStrArg( |
| 220 | + options=["--apim-resource-group"], |
| 221 | + help="The resource group of the source APIM instance.", |
| 222 | + required=False |
| 223 | + ) |
| 224 | + |
| 225 | + args_schema.apim_name = AAZStrArg( |
| 226 | + options=["--apim-name"], |
| 227 | + help="The name of the source APIM instance.", |
| 228 | + required=True |
| 229 | + ) |
| 230 | + |
| 231 | + args_schema.apim_apis = AAZListArg( |
| 232 | + options=["--apim-apis"], |
| 233 | + help="The APIs to be imported.", |
| 234 | + required=True |
| 235 | + ) |
| 236 | + args_schema.apim_apis.Element = AAZStrArg() |
| 237 | + |
209 | 238 | return args_schema |
| 239 | + |
| 240 | + def pre_operations(self): |
| 241 | + super().pre_operations() |
| 242 | + args = self.ctx.args |
| 243 | + |
| 244 | + # compose sourceResourceIds property in the request body |
| 245 | + # Use same subscription id and resource group as API Center by default |
| 246 | + resource_group = args.resource_group |
| 247 | + subscription_id = self.ctx.subscription_id |
| 248 | + |
| 249 | + # Use user provided subscription id |
| 250 | + if args.apim_subscription_id: |
| 251 | + subscription_id = args.apim_subscription_id |
| 252 | + |
| 253 | + # Use user provided resource group |
| 254 | + if args.apim_resource_group: |
| 255 | + resource_group = args.apim_resource_group |
| 256 | + |
| 257 | + source_resource_ids = [] |
| 258 | + for item in args.apim_apis: |
| 259 | + source_resource_ids.append( |
| 260 | + f"/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/" |
| 261 | + f"Microsoft.ApiManagement/service/{args.apim_name}/apis/{item}" |
| 262 | + ) |
| 263 | + |
| 264 | + args.source_resource_ids = source_resource_ids |
0 commit comments