Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0437444
create extension, update examples, remove import/export commands
arpishahmsft Oct 27, 2023
f9b1893
import export spec inline and remove version from examples
arpishahmsft Nov 7, 2023
8d872cd
import export spec - remove redundant az
arpishahmsft Nov 7, 2023
599a6be
auto lro poller and check import spec size for inlne option via comma…
arpishahmsft Nov 7, 2023
0544d1f
import export spec using a json file, link to json and commandline
arpishahmsft Nov 8, 2023
2ef6c9e
import json with any encdoing, auto indent json on export
arpishahmsft Nov 10, 2023
6569552
quick add working, not apim import
arpishahmsft Nov 14, 2023
b109ecc
quick add - fix envId bug
arpishahmsft Nov 15, 2023
4401bda
export metadata schema to a file customized
arpishahmsft Nov 20, 2023
4d8c5da
exmples export schema and create env
arpishahmsft Nov 20, 2023
41d4ccc
move quick add in api and remove redundant exmaple unicode
arpishahmsft Nov 20, 2023
9a6d0dd
add tests
arpishahmsft Nov 22, 2023
dd5ee3e
update metadata schema and additional tests
arpishahmsft Nov 23, 2023
b68051e
Merge branch 'Azure:main' into feature-arpishah/25282500-Extension
arpishahmsft Nov 23, 2023
8437ff0
improve code style
arpishahmsft Nov 24, 2023
e9765af
Merge branch 'feature-arpishah/25282500-Extension' of https://github.…
arpishahmsft Nov 24, 2023
ace20d6
fix local linting issues
arpishahmsft Nov 27, 2023
adba54c
remove default from update
arpishahmsft Nov 27, 2023
3e684ec
style flake corrections
arpishahmsft Nov 28, 2023
83fae12
remove default ws value from workspace update
arpishahmsft Nov 28, 2023
0f77828
Added help for api register command
arpishahmsft Nov 28, 2023
22e8b3f
Add APIC Seevice name in global fille
arpishahmsft Nov 28, 2023
a1c1e99
fx flake style error
arpishahmsft Nov 28, 2023
5e13cd3
add readme for extension
arpishahmsft Nov 28, 2023
e6af95f
update title of readme
arpishahmsft Nov 28, 2023
acec155
one more linter error
arpishahmsft Nov 28, 2023
ca2baa3
updated log line and tests
arpishahmsft Nov 29, 2023
ea8db47
change print statement to logger
arpishahmsft Nov 29, 2023
0ceb053
use logger warning
arpishahmsft Nov 29, 2023
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
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

/src/subscription/ @wilcobmsft

/src/apic-extension/ @arpishahmsft

/src/alias/ @Juliehzl

/src/managementpartner/ @jeffrey-ace
Expand Down
8 changes: 8 additions & 0 deletions src/apic-extension/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. :changelog:

Release History
===============

1.0.0b1
++++++
* Initial release.
286 changes: 286 additions & 0 deletions src/apic-extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
# Azure CLI APICenter Extension

This extension can help create and manage APICenter Resources

### How to use
Install this extension using the below CLI command
```
az extension add --name apic-extension
```

### API Center Extension Info
APICenter documentation: https://learn.microsoft.com/en-us/azure/api-center/

List Service Examples
```
az apic service show --resource-group api-center-test
```
```
az apic service show -g api-center-test
```

Show service Examples
```
az apic service show --resource-group api-center-test --service-name contosoeuap
```
```
az apic service show -g api-center-test -s contosoeuap
```

Delete Service Examples
```
az apic service delete --resource-group api-center-test --service-name contosoeuap
```
```
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"
```
```
az apic api create --resource-group api-center-test --service-name contosoeuap --api-name echo-api2 --description "CLI Test" --kind rest --title "Echo API"
```

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 --resource-group api-center-test -s contosoeuap --name echo-api --summary "Basic REST API service" --workspace-name default
```

LIST Api Example
```
az apic api list --resource-group api-center-test --service-name contosoeuap
```
```
az apic api list -g api-center-test -s contosoeuap
```

SHOW Api Examples
```
az apic api show -g api-center-test -s contosoeuap --name echo-api
```
```
az apic api show --resource-group api-center-test --service-name contosoeuap -w default --api echo-api
```

Delete API Examples
```
az apic api delete -g api-center-test -s contosoeuap --name echo-api
```
```
az apic api delete --resource-group contoso-resources --service-name contosoeuap --name echo-api
```

CREATE Api Version Examples
```
az apic api version create -g api-center-test -s contosoeuap --api-name echo-api --name 2023-01-01 --title "2023-01-01"
```
```
az apic api version create --resource-group api-center-test --service-name contosoeuap --api-name echo-api --name 2023-01-01 --title "2023-01-01"
```

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 --resource-group api-center-test --service-name contosoeuap --api-name echo-api --name 2023-01-01 --title "2023-01-01" --workspace-name default
```

LIST Api Version Examples
```
az apic api version list -g api-center-test -s contosoeuap --api-name echo-api
```
```
az apic api version list --resource-group api-center-test --service-name contosoeuap --api-name echo-api
```

SHOW Api Version Example
```
az apic api version show -g api-center-test -s contosoeuap --api-name echo-api --name 2023-01-01
```
```
az apic api version show --resource-group api-center-test --service-name contosoeuap --api-name echo-api --name 2023-01-01
```

DELETE Api Version Example
```
az apic api version delete -g api-center-test -s contosoeuap --api-name echo-api --name 2023-01-01
```
```
az apic api version delete --resource-group api-center-test --service-name contosoeuap --api-name echo-api --name 2023-01-01
```

CREATE API Definition Example
```
az apic api definition create -g api-center-test -s contosoeuap --api-name echo-api --version 2023-01-01 --name "openapi" --title "OpenAPI"
```

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
```

SHOW API Definition Example
```
az apic api definition show -g api-center-test -s contosoeuap --api-name echo-api --version 2023-01-01 --name "openapi"
```

LIST API Definition Example
```
az apic api definition list -g api-center-test -s contosoeuap --api-name echo-api --version 2023-01-01
```

DELETE API Definition Example
```
az apic api definition delete -g api-center-test -s contosoeuap --api-name echo-api --version 2023-01-01 --name "openapi"
```

IMPORT Specification Examples
Import Specification inline option
```
az apic api definition import-specification -g api-center-test -s contosoeuap --api-name echo-api --version-name 2023-01-01 --definition-name openapi--format "inline" --value '{"openapi":"3.0.1","info":{"title":"httpbin.org","description":"API Management facade for a very handy and free online HTTP tool.","version":"1.0"}}' --specification '{"name":"openapi","version":"3.0.0"}'
```

Import Specification Inline option where spec is provided by sending a file
```
az apic api definition import-specification -g api-center-test -s contosoeuap --api-name echo-api --version-name 2023-01-01 --definition-name openapi --format inline --specification '{"name":"openapi","version":"3.0.0"}' --file-name C:\Users\arpishah\examples\cli-examples\spec-examples\cat-facts-api.json
```

Import Specification Link option where spec is provided via a link
```
az apic api definition import-specification -g api-center-test -s contosoeuap - --api-name echo-api --version-name 2023-01-01 --definition-name openapi --format "link" --value https://alzaslonaztest.blob.core.windows.net/arpitestblobs/cat-facts-api.json --specification '{"name":"openapi","version":"3.0.0"}'
```

Export Specification Examples
Export Spec to a file
```
az apic api definition export-specification -g api-center-test -s contosoeuap --api-name echo-api-10 --version-name 2023-11-08 --definition-name arpitest4 --file-name C:\Users\arpishah\examples\cli-examples\exported-results\exported-spec-inline.json
```

CREATE Api Deployment

```
az apic api deployment create -g api-center-test -s contosoeuap --name production --title "Production deployment" --description "Public cloud production deployment." --api echo-api --server C:/Users/arpishah/examples/cli-examples/payload-examples/deplcreate.json --environment-id "/workspaces/default/environments/production" --definition-id "/workspaces/default/apis/echo-api/versions/2023-01-01/definitions/openapi"
where examples/deplcreate.json contains
{"runtime-uri": ["https://api.contoso.com"]}
```

UPDATE Api Deployment
```
az apic api deployment update -g api-center-test -s contosoeuap --name production --title "Production deployment 10" --api echo-api –w default
```

LIST Api Deployment
```
az apic api deployment list -g api-center-test -s contosoeuap --api-name echo-api
```

SHOW Api Deployment
```
az apic api deployment show -g api-center-test -s contosoeuap --name production --api-name echo-api
```

DELETE Api Deployment
```
Az apic api deployment delete -g api-center-test -s contosoeuap --name production --api-name echo-api
```

CREATE Environment
```
az apic environment create -g api-center-test -s contosoeuap --name public-3 --title "Public cloud" --kind "development" --server "C:\Users\arpishah\examples\cli-examples\payload-examples\envcreate1.json"
Where envcreate1.json contains
{
"type": "Azure API Management",
"managementPortalUri": [
"management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-resource-group/providers/Microsoft.ApiManagement/service/my-api-management-service"
]
}
```

UPDATE Environment
```
az apic environment update -g api-center-test -s contosoeuap --name public --title "Public cloud" -w default
```

LIST Environment
```
az apic environment list -g api-center-test -s contosoeuap
```

SHOW Environment
```
az apic environment show -g api-center-test -s contosoeuap --name public
```

DELETE Environment
```
az apic environment delete -g api-center-test -s contosoeuap --name public
```

CREATE Metadata Schema
```
az apic metadata-schema create --resource-group api-center-test --service-name contosoeuap --name "test1" --file-name "C:\Users\arpishah\examples\cli-examples\payload-examples\schemacreate.json"
Where schemacreate.json contains metadata schema
{
"type": "string",
"title": "First name",
"pattern": "^[a-zA-Z0-9 ]+$"
}
```

UPDATE Metadata Schema
```
az apic metadata-schema update --resource-group api-center-test --service-name contosoeuap --name "test1" --file-name "C:\Users\arpishah\examples\cli-examples\payload-examples\schemaupdate.json"
Where schemaupdate.json contains metadata schema
{
"type": "string",
"title": "Last name",
"pattern": "^[a-zA-Z0-9 ]+$"
}
```

LIST Metadata Schema
```
az apic metadata-schema list -g api-center-test -s contosoeuap
```

SHOW Metadata Schema
```
az apic metadata-schema show --resource-group api-center-test --service-name contosoeuap --name "test1"
```

DELETE Metadata Schema
```
az apic metadata-schema delete --resource-group api-center-test --service-name contosoeuap --name "test1"
```

EXPORT Metadata Schema
EXPORT Metadata Schema assigned to an API
```
az apic metadata-schema export-metadata-schema -g api-center-test -s contosoeuap --assigned-to api --file-name C:\Users\arpishah\examples\cli-examples\exported-results\exported-schema-3.json
```

EXPORT Metadata Schema assigned to a Deployment
```
az apic metadata-schema export-metadata-schema -g api-center-test -s contosoeuap --assigned-to deployment --file-name C:\Users\arpishah\examples\cli-examples\exported-results\exported-schema-5.json
```

EXPORT Metadata Schema assigned to an Environment
```
az apic metadata-schema export-metadata-schema -g api-center-test -s contosoeuap --assigned-to environment --file-name C:\Users\arpishah\examples\cli-examples\exported-results\exported-schema-6.json
```

Register API or Quick Add
```
az apic api register -g api-center-test -s contosoeuap --api-location "C:/Users/arpishah/examples/cli-examples/spec-examples/openai.json" --environment-name public
```
42 changes: 42 additions & 0 deletions src/apic-extension/azext_apic_extension/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader
from azext_apic_extension._help import helps # pylint: disable=unused-import


class ApicExtensionCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
custom_command_type = CliCommandType(
operations_tmpl='azext_apic_extension.custom#{}')
super().__init__(cli_ctx=cli_ctx,
custom_command_type=custom_command_type)

def load_command_table(self, args):
from azext_apic_extension.commands import load_command_table
from azure.cli.core.aaz import load_aaz_command_table
try:
from . import aaz
except ImportError:
aaz = None
if aaz:
load_aaz_command_table(
loader=self,
aaz_pkg_name=aaz.__name__,
args=args
)
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azext_apic_extension._params import load_arguments
load_arguments(self, command)


COMMAND_LOADER_CLS = ApicExtensionCommandsLoader
33 changes: 33 additions & 0 deletions src/apic-extension/azext_apic_extension/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: disable=line-too-long
# pylint: disable=too-many-lines

from knack.help_files import helps # pylint: disable=unused-import

helps['apic api register'] = """
type: command
short-summary: Single Command for registering api, api version, api definition, import spec, create deployment provided a spec file.
parameters:
- name: --api-location -l
type: string
short-summary: Location of spec file .
- name: --resource-group -g
type: string
short-summary: Resource group name.
- name: --service -s
type: string
short-summary: APICenter Catalog or Service name.
- name: --environment-name -e
type: string
short-summary: Name of environment created before.
examples:
- name: Register api by providing spec file.
text: |
az apic api register -g api-center-test -s contosoeuap --api-location "examples/cli-examples/spec-examples/openai.json" --environment-name public
"""
Loading