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

[Breadth Coverage] Onboard Custom Providers Commands #1627

Merged
merged 6 commits into from
May 9, 2020
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
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,5 @@
/src/log-analytics-solution/ @zhoxing-ms

/src/kusto/ @ilayr @orhasban @astauben

/src/custom-providers/ @jsntcy
8 changes: 8 additions & 0 deletions src/custom-providers/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. :changelog:

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

0.1.0
++++++
* Initial release.
43 changes: 43 additions & 0 deletions src/custom-providers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Azure CLI Custom Providers Extension
This is a extension for Custom Providers features.

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

### Included Features
#### Manage custom resource provider:


##### Create or update a custom resource provider

```
az custom-providers resource-provider create -n MyRP -g MyRG --action name=ping endpoint=https://test.azurewebsites.net/api routing_type=Proxy --resource-type name=users endpoint=https://test.azurewebsites.net/api routing_type="Proxy, Cache" --validation validation_type=swagger specification=https://raw.githubusercontent.com/test.json
```

##### Update the tags for a custom resource provider
```
az custom-providers resource-provider update -g MyRG -n MyRP --tags a=b
```

##### Get a custom resource provider
```
az custom-providers resource-provider show -g MyRG -n MyRP
```

##### Get all the custom resource providers within a resource group or in the current subscription
```
az custom-providers resource-provider list
```
```
az custom-providers resource-provider list -g MyRG
```

##### Delete a custom resource provider
```
az custom-providers resource-provider delete -g MyRG -n MyRP
```

If you have issues, please give feedback by opening an issue at https://github.com/Azure/azure-cli-extensions/issues.
32 changes: 32 additions & 0 deletions src/custom-providers/azext_custom_providers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader

from azext_custom_providers._help import helps # pylint: disable=unused-import


class CustomprovidersCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
from azext_custom_providers._client_factory import cf_custom_providers
custom_providers_custom = CliCommandType(
operations_tmpl='azext_custom_providers.custom#{}',
client_factory=cf_custom_providers)
super(CustomprovidersCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=custom_providers_custom)

def load_command_table(self, args):
from azext_custom_providers.commands import load_command_table
load_command_table(self, args)
return self.command_table

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


COMMAND_LOADER_CLS = CustomprovidersCommandsLoader
14 changes: 14 additions & 0 deletions src/custom-providers/azext_custom_providers/_client_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------


def cf_custom_providers(cli_ctx, *_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from .vendored_sdks.customproviders import CustomProvidersClient
return get_mgmt_service_client(cli_ctx, CustomProvidersClient)


def cf_custom_resource_provider(cli_ctx, *_):
return cf_custom_providers(cli_ctx).custom_resource_provider
96 changes: 96 additions & 0 deletions src/custom-providers/azext_custom_providers/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# coding=utf-8
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=too-many-lines
# pylint: disable=line-too-long
from knack.help_files import helps # pylint: disable=unused-import


helps['custom-providers resource-provider'] = """
type: group
short-summary: Commands to manage custom resource provider.
"""

helps['custom-providers resource-provider create'] = """
type: command
short-summary: Create or update the custom resource provider.
parameters:
- name: --action -a
short-summary: Add an action to the custom resource provider.
long-summary: |
Usage: --action name=ping endpoint="https://test.azurewebsites.net/api/{requestPath}" routing_type=Proxy

name: Required. The name of the action.
endpoint: Required. The endpoint URI that the custom resource provider will proxy requests to.
routing_type: The routing types that are supported for action requests. Possible values include: 'Proxy'.

Multiple actions can be specified by using more than one `--action` argument.
- name: --resource-type -r
short-summary: Add a custom resource type to the custom resource provider.
long-summary: |
Usage: --resource-type name=user endpoint="https://test.azurewebsites.net/api/{requestPath}" routing_type="Proxy, Cache"

name: Required. The name of the resource type.
endpoint: Required. The endpoint URI that the custom resource provider will proxy requests to.
routing_type: The routing types that are supported for resource requests. Possible values include: 'Proxy', 'Proxy,Cache'.

Multiple resource types can be specified by using more than one `--resource-type` argument.
- name: --validation -v
short-summary: Add a validation to the custom resource provider.
long-summary: |
Usage: --validation specification="https://raw.githubusercontent.com/" validation_type="Swagger"

specification: A link to the validation specification.vThe specification must be hosted on raw.githubusercontent.com.
validation_type: The type of validation to run against a matching request. Possible values include: 'Swagger'.

Multiple validations can be specified by using more than one `--validation` argument.
examples:
- name: Create or update a custom resource provider.
text: |-
az custom-providers resource-provider create -n MyRP -g MyRG \\
--action name=ping endpoint=https://test.azurewebsites.net/api routing_type=Proxy \\
--resource-type name=users endpoint=https://test.azurewebsites.net/api routing_type="Proxy, Cache" \\
--validation validation_type=swagger specification=https://raw.githubusercontent.com/test.json
"""

helps['custom-providers resource-provider update'] = """
type: command
short-summary: Update the custom resource provider. Only tags can be updated.
examples:
- name: Update the tags for a custom resource provider.
text: |-
az custom-providers resource-provider update -g MyRG -n MyRP --tags a=b
"""

helps['custom-providers resource-provider delete'] = """
type: command
short-summary: Delete the custom resource provider.
examples:
- name: Delete a custom resource provider.
text: |-
az custom-providers resource-provider delete -g MyRG -n MyRP
"""

helps['custom-providers resource-provider show'] = """
type: command
short-summary: Get the properties for the custom resource provider.
examples:
- name: Get a custom resource provider.
text: |-
az custom-providers resource-provider show -g MyRG -n MyRP
"""

helps['custom-providers resource-provider list'] = """
type: command
short-summary: Get all the custom resource providers within a resource group or in the current subscription.
examples:
- name: List all custom resource providers in the resource group.
text: |-
az custom-providers resource-provider list -g MyRG
- name: List all custom resource providers in the current subscription.
text: |-
az custom-providers resource-provider list
"""
23 changes: 23 additions & 0 deletions src/custom-providers/azext_custom_providers/_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.commands.parameters import (
tags_type,
get_location_type,
name_type)
from azure.cli.core.commands.validators import get_default_location_from_resource_group
from .actions import (ActionAddAction, ResourceTypeAddAction, ValidationAddAction)


def load_arguments(self, _):
with self.argument_context('custom-providers resource-provider') as c:
c.argument('resource_provider_name', arg_type=name_type, help='The name of the resource provider.')
c.argument('location',
arg_type=get_location_type(self.cli_ctx),
validator=get_default_location_from_resource_group)
c.argument('tags', tags_type)
c.argument('actions', options_list=['--action', '-a'], action=ActionAddAction, nargs='+')
c.argument('resource_types', options_list=['--resource-type', '-r'], action=ResourceTypeAddAction, nargs='+')
c.argument('validations', options_list=['--validation', '-v'], action=ValidationAddAction, nargs='+')
44 changes: 44 additions & 0 deletions src/custom-providers/azext_custom_providers/actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=protected-access
# pylint: disable=line-too-long
# pylint: disable=too-few-public-methods
import argparse
from knack.util import CLIError


class ActionAddAction(argparse._AppendAction):

def __call__(self, parser, namespace, values, option_string=None):
from azext_custom_providers.vendored_sdks.customproviders.models import CustomRPActionRouteDefinition as model
action = get_object(values, option_string, model)
super(ActionAddAction, self).__call__(parser, namespace, action, option_string)


class ResourceTypeAddAction(argparse._AppendAction):

def __call__(self, parser, namespace, values, option_string=None):
from azext_custom_providers.vendored_sdks.customproviders.models import CustomRPResourceTypeRouteDefinition as model
resource_type = get_object(values, option_string, model)
super(ResourceTypeAddAction, self).__call__(parser, namespace, resource_type, option_string)


class ValidationAddAction(argparse._AppendAction):

def __call__(self, parser, namespace, values, option_string=None):
from azext_custom_providers.vendored_sdks.customproviders.models import CustomRPValidations as model
validation = get_object(values, option_string, model)
super(ValidationAddAction, self).__call__(parser, namespace, validation, option_string)


def get_object(values, option_string, model):
kwargs = {}
for item in values:
try:
key, value = item.split('=', 1)
kwargs[key] = value
except ValueError:
raise CLIError('usage error: {} KEY=VALUE [KEY=VALUE ...]'.format(option_string))
jsntcy marked this conversation as resolved.
Show resolved Hide resolved
return model(**kwargs)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"azext.isExperimental": true,
"azext.minCliCoreVersion": "2.3.1"
}
24 changes: 24 additions & 0 deletions src/custom-providers/azext_custom_providers/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=line-too-long
# pylint: disable=too-many-lines
# pylint: disable=too-many-statements
# pylint: disable=too-many-locals
from azure.cli.core.commands import CliCommandType


def load_command_table(self, _):

from ._client_factory import cf_custom_resource_provider
custom_providers_custom_resource_provider = CliCommandType(
operations_tmpl='azext_custom_providers.vendored_sdks.customproviders.operations._custom_resource_provider_operations#CustomResourceProviderOperations.{}',
client_factory=cf_custom_resource_provider)
with self.command_group('custom-providers resource-provider', custom_providers_custom_resource_provider, client_factory=cf_custom_resource_provider, is_experimental=True) as g:
g.custom_command('create', 'create_custom_providers_custom_resource_provider', supports_no_wait=True)
g.custom_command('update', 'update_custom_providers_custom_resource_provider')
g.custom_command('delete', 'delete_custom_providers_custom_resource_provider', supports_no_wait=True, confirmation=True)
g.custom_show_command('show', 'get_custom_providers_custom_resource_provider')
g.custom_command('list', 'list_custom_providers_custom_resource_provider')
52 changes: 52 additions & 0 deletions src/custom-providers/azext_custom_providers/custom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long
# pylint: disable=too-many-statements
# pylint: disable=too-many-lines
# pylint: disable=too-many-locals
# pylint: disable=unused-argument
from azure.cli.core.util import sdk_no_wait


def create_custom_providers_custom_resource_provider(client,
resource_group_name,
resource_provider_name,
location=None,
tags=None,
actions=None,
resource_types=None,
validations=None,
no_wait=False):
body = {'location': location, 'tags': tags,
'actions': actions, 'resource_types': resource_types,
'validations': validations}
return sdk_no_wait(no_wait, client.create_or_update, resource_group_name=resource_group_name, resource_provider_name=resource_provider_name, resource_provider=body)
Copy link
Contributor

Choose a reason for hiding this comment

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

example



def update_custom_providers_custom_resource_provider(client,
jsntcy marked this conversation as resolved.
Show resolved Hide resolved
resource_group_name,
resource_provider_name,
tags=None):
return client.update(resource_group_name=resource_group_name, resource_provider_name=resource_provider_name, tags=tags)


def delete_custom_providers_custom_resource_provider(client,
resource_group_name,
resource_provider_name,
no_wait=False):
return sdk_no_wait(no_wait, client.delete, resource_group_name=resource_group_name, resource_provider_name=resource_provider_name)


def get_custom_providers_custom_resource_provider(client,
resource_group_name,
resource_provider_name):
return client.get(resource_group_name=resource_group_name, resource_provider_name=resource_provider_name)


def list_custom_providers_custom_resource_provider(client,
resource_group_name=None):
if resource_group_name:
return client.list_by_resource_group(resource_group_name=resource_group_name)
return client.list_by_subscription()
Loading