-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[Breadth Coverage] Onboard Custom Providers Commands #1627
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2f81b69
[Breadth Coverage] Support custom providers in Azure CLI (draft)
jsntcy 829503d
[Breadth Coverage] Support customproviders (draft)
jsntcy 4439b97
[Breadth Coverage]: Support custom providers
jsntcy 635e564
add code owner for custom-providers extension
jsntcy ed025bf
refine the format for help and readme
jsntcy 1f65869
add multiple actions in test for create command
jsntcy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| .. :changelog: | ||
|
|
||
| Release History | ||
| =============== | ||
|
|
||
| 0.1.0 | ||
| ++++++ | ||
| * Initial release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
14
src/custom-providers/azext_custom_providers/_client_factory.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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='+') |
18 changes: 18 additions & 0 deletions
18
src/custom-providers/azext_custom_providers/_validators.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def example_name_or_id_validator(cmd, namespace): | ||
| from azure.cli.core.commands.client_factory import get_subscription_id | ||
| from msrestazure.tools import is_valid_resource_id, resource_id | ||
| if namespace.storage_account: | ||
| if not is_valid_resource_id(namespace.RESOURCE): | ||
| namespace.storage_account = resource_id( | ||
| subscription=get_subscription_id(cmd.cli_ctx), | ||
| resource_group=namespace.resource_group_name, | ||
| namespace='Microsoft.Storage', | ||
| type='storageAccounts', | ||
| name=namespace.storage_account | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
|
||
| return model(**kwargs) | ||
4 changes: 4 additions & 0 deletions
4
src/custom-providers/azext_custom_providers/azext_metadata.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "azext.isExperimental": true, | ||
| "azext.minCliCoreVersion": "2.3.1" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
|
||
| 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() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.