-
Notifications
You must be signed in to change notification settings - Fork 3.3k
azure cognitive service CLI initial version #3060
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 all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1e026ee
initial update
b5b14bf
update
kostenray 1a77bb5
add the CLI for 2017-04-18 swagger file
kostenray 96f6eb0
cognitive service cli - inital version'
kostenray 7806815
rollback debug code change
kostenray a0763a6
style refactoring update
kostenray fc47810
update
kostenray d26c098
change the term text to yellow highlighted
kostenray 1b9e313
code comment fix - update #1
kostenray b6c6643
fix code comments - update #2
kostenray 25adc16
1.fix flake 8 styling error
kostenray 17db72d
fix an change in our service legal terms.
kostenray 25dd3ea
fix a help.py styling issue
kostenray 410e490
update the setup.py
kostenray 9065ccc
update description of setup.py
kostenray 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,9 @@ | ||
| .. :changelog: | ||
|
|
||
| Release History | ||
| =============== | ||
|
|
||
| Unreleased | ||
| -------------------------- | ||
| * inital cognitive services CLI | ||
|
|
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 @@ | ||
| include *.rst |
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,7 @@ | ||
| Microsoft Azure CLI 'cognitive services' Command Module | ||
| ============================================= | ||
|
|
||
| This package is for the 'cognitive services' module. | ||
| i.e. 'az cognitiveservices' | ||
|
|
||
|
|
6 changes: 6 additions & 0 deletions
6
src/command_modules/azure-cli-cognitiveservices/azure/__init__.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,6 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
| import pkg_resources | ||
| pkg_resources.declare_namespace(__name__) |
6 changes: 6 additions & 0 deletions
6
src/command_modules/azure-cli-cognitiveservices/azure/cli/__init__.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,6 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
| import pkg_resources | ||
| pkg_resources.declare_namespace(__name__) |
6 changes: 6 additions & 0 deletions
6
src/command_modules/azure-cli-cognitiveservices/azure/cli/command_modules/__init__.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,6 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
| import pkg_resources | ||
| pkg_resources.declare_namespace(__name__) |
13 changes: 13 additions & 0 deletions
13
...dules/azure-cli-cognitiveservices/azure/cli/command_modules/cognitiveservices/__init__.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,13 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
| import azure.cli.command_modules.cognitiveservices._help # pylint: disable=unused-import | ||
|
|
||
|
|
||
| def load_params(_): | ||
| import azure.cli.command_modules.cognitiveservices._params # pylint: disable=redefined-outer-name | ||
|
|
||
|
|
||
| def load_commands(): | ||
| import azure.cli.command_modules.cognitiveservices.commands # pylint: disable=redefined-outer-name |
19 changes: 19 additions & 0 deletions
19
...zure-cli-cognitiveservices/azure/cli/command_modules/cognitiveservices/_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,19 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
| # management client factories | ||
|
|
||
|
|
||
| def get_cognitiveservices_management_client(_): | ||
| from azure.cli.core.commands.client_factory import get_mgmt_service_client | ||
| from azure.mgmt.cognitiveservices import CognitiveServicesManagementClient | ||
| return get_mgmt_service_client(CognitiveServicesManagementClient, location='notused') | ||
|
|
||
|
|
||
| def get_cognitiveservices_account_operations(kwargs): | ||
| return get_cognitiveservices_management_client(kwargs).cognitive_services_accounts | ||
|
|
||
|
|
||
| def get_cognitiveservices_operations(kwargs): | ||
| return get_cognitiveservices_management_client(kwargs).accounts |
63 changes: 63 additions & 0 deletions
63
..._modules/azure-cli-cognitiveservices/azure/cli/command_modules/cognitiveservices/_help.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,63 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # 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.help_files import helps | ||
|
|
||
| helps['cognitiveservices list'] = """ | ||
| type: command | ||
| short-summary: list all the existing cognitive services accounts under a resource group or current azure subscription | ||
| examples: | ||
| - name: list all the cognitive services accounts in a resource group | ||
| text: az cognitiveservices list -g MyResourceGroup | ||
| """ | ||
|
|
||
| helps['cognitiveservices account'] = """ | ||
| type: group | ||
| short-summary: Manage and update cognitive services accounts | ||
| """ | ||
|
|
||
| helps['cognitiveservices account delete'] = """ | ||
| type: command | ||
| short-summary: Remove a cognitive services account. | ||
| """ | ||
|
|
||
| helps['cognitiveservices account create'] = """ | ||
| type: command | ||
| short-summary: Create a cognitive services account. | ||
| examples: | ||
| - name: create a S0 face Api cognitive services account in West Europe without confirmation required | ||
| text: az cognitiveservices create -n myresource -g myResourceGroup --kind Face --sku S0 -l WestEurope --yes | ||
| """ | ||
|
|
||
| helps['cognitiveservices account show'] = """ | ||
| type: command | ||
| short-summary: Get the details of a cognitive services account. | ||
| """ | ||
|
|
||
| helps['cognitiveservices account update'] = """ | ||
| type: command | ||
| short-summary: Update the properties of a cognitive services account. | ||
| """ | ||
|
|
||
| helps['cognitiveservices account list-skus'] = """ | ||
| type: command | ||
| short-summary: List the avaiable skus of a cognitive services account. | ||
| """ | ||
|
|
||
|
|
||
| helps['cognitiveservices account keys'] = """ | ||
| type: group | ||
| short-summary: Manage the keys of a cognitive services account. | ||
| """ | ||
|
|
||
| helps['cognitiveservices account keys regenerate'] = """ | ||
| type: command | ||
| short-summary: Regenerate the keys of a cognitive services account. | ||
| """ | ||
|
|
||
| helps['cognitiveservices account keys list'] = """ | ||
| type: command | ||
| short-summary: List the keys of a cognitive services account. | ||
| """ |
28 changes: 28 additions & 0 deletions
28
...odules/azure-cli-cognitiveservices/azure/cli/command_modules/cognitiveservices/_params.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,28 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # 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 import register_cli_argument, CliArgumentType | ||
|
|
||
| from azure.cli.core.commands.parameters import ( | ||
| tags_type, | ||
| resource_group_name_type, | ||
| get_resource_name_completion_list) | ||
|
|
||
| name_arg_type = CliArgumentType(options_list=('--name', '-n'), metavar='NAME') | ||
|
|
||
| register_cli_argument('cognitiveservices', 'account_name', | ||
| arg_type=name_arg_type, help='cognitive service account name', | ||
| completer=get_resource_name_completion_list( | ||
| 'Microsoft.CognitiveServices/accounts')) | ||
| register_cli_argument('cognitiveservices', 'resource_group_name', | ||
| arg_type=resource_group_name_type) | ||
| register_cli_argument('cognitiveservices', 'sku_name', options_list=('--sku',), | ||
| help='the Sku of cognitive services account') | ||
| register_cli_argument('cognitiveservices', 'kind', | ||
| help='the API name of cognitive services account') | ||
| register_cli_argument('cognitiveservices', 'tags', tags_type) | ||
| register_cli_argument('cognitiveservices', 'key_name', required=True, | ||
| help='Key name to generate', choices=['key1', 'key2']) | ||
| register_cli_argument('cognitiveservices account create', 'yes', action='store_true', | ||
| help='Do not prompt for terms confirmation') |
30 changes: 30 additions & 0 deletions
30
...dules/azure-cli-cognitiveservices/azure/cli/command_modules/cognitiveservices/commands.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,30 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # 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 import cli_command | ||
| from azure.cli.command_modules.cognitiveservices._client_factory import ( | ||
| get_cognitiveservices_account_operations, | ||
| get_cognitiveservices_operations) | ||
|
|
||
| mgmt_path = 'azure.mgmt.cognitiveservices.operations.cognitive_services_accounts_operations#'\ | ||
| 'CognitiveServicesAccountsOperations.{}' | ||
| custom_path = 'azure.cli.command_modules.cognitiveservices.custom#{}' | ||
|
|
||
| cli_command(__name__, 'cognitiveservices account create', custom_path.format('create'), | ||
| get_cognitiveservices_account_operations) | ||
| cli_command(__name__, 'cognitiveservices account delete', mgmt_path.format('delete'), | ||
| get_cognitiveservices_account_operations) | ||
| cli_command(__name__, 'cognitiveservices account show', mgmt_path.format('get_properties'), | ||
| get_cognitiveservices_account_operations) | ||
| cli_command(__name__, 'cognitiveservices list', custom_path.format('listresources'), | ||
| get_cognitiveservices_operations) | ||
| cli_command(__name__, 'cognitiveservices account update', custom_path.format('update'), | ||
| get_cognitiveservices_account_operations) | ||
| cli_command(__name__, 'cognitiveservices account keys regenerate', | ||
| mgmt_path.format('regenerate_key'), | ||
| get_cognitiveservices_account_operations) | ||
| cli_command(__name__, 'cognitiveservices account keys list', mgmt_path.format('list_keys'), | ||
| get_cognitiveservices_account_operations) | ||
| cli_command(__name__, 'cognitiveservices account list-skus', mgmt_path.format('list_skus'), | ||
| get_cognitiveservices_account_operations) |
52 changes: 52 additions & 0 deletions
52
...modules/azure-cli-cognitiveservices/azure/cli/command_modules/cognitiveservices/custom.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,52 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
| from azure.mgmt.cognitiveservices.models import CognitiveServicesAccountCreateParameters, Sku | ||
| from azure.cli.core.prompting import prompt_y_n | ||
| from azure.cli.core.util import CLIError | ||
|
|
||
| import azure.cli.core.azlogging as azlogging | ||
| logger = azlogging.get_az_logger(__name__) | ||
|
|
||
|
|
||
| def listresources(client, resource_group_name=None): | ||
| if resource_group_name: | ||
| return client.list_by_resource_group(resource_group_name) | ||
| else: | ||
| return client.list() | ||
|
|
||
|
|
||
| # pylint: disable=too-many-arguments | ||
| def create( | ||
| client, resource_group_name, account_name, sku_name, kind, location, tags=None, yes=None): | ||
|
|
||
| terms = 'Notice\nMicrosoft will use data you send to the Cognitive'\ | ||
| 'Services to improve Microsoft products and services.'\ | ||
| 'For example we may use content that you provide to the Cognitive'\ | ||
| 'Services to improve our underlying algorithms and models over time.'\ | ||
| 'Where you send personal data to the Cognitive Services, you are responsible'\ | ||
| 'for obtaining sufficient consent from the data subjects.'\ | ||
| 'The General Privacy and Security Terms in the Online Services Terms '\ | ||
| '(https://www.microsoft.com/en-us/Licensing/product-licensing/products.aspx) '\ | ||
| 'do not apply to the Cognitive Services.'\ | ||
| 'You must comply with use and display requirements for the Bing Search APIs.'\ | ||
| '\n\nPlease refer to the Microsoft Cognitive Services section in the Online '\ | ||
| 'Services Terms for details.' | ||
| hint = '\nPlease select' | ||
| if yes: | ||
| logger.warning(terms) | ||
| else: | ||
| logger.warning(terms) | ||
| option = prompt_y_n(hint) | ||
| if not option: | ||
| raise CLIError('Operation cancelled.') | ||
| sku = Sku(sku_name) | ||
| properties = {} | ||
| params = CognitiveServicesAccountCreateParameters(sku, kind, location, properties, tags) | ||
| return client.create(resource_group_name, account_name, params) | ||
|
|
||
|
|
||
| def update(client, resource_group_name, account_name, sku_name=None, tags=None): | ||
| sku = Sku(sku_name) | ||
| return client.update(resource_group_name, account_name, sku, tags) |
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,61 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| from codecs import open | ||
| from setuptools import setup | ||
|
|
||
| try: | ||
| from azure_bdist_wheel import cmdclass | ||
| except ImportError: | ||
| from distutils import log as logger | ||
| logger.warn("Wheel is not available, disabling bdist_wheel hook") | ||
| cmdclass = {} | ||
|
|
||
| VERSION = '0.1.0+dev' | ||
|
|
||
| # The full list of classifiers is available at | ||
| # https://pypi.python.org/pypi?%3Aaction=list_classifiers | ||
| CLASSIFIERS = [ | ||
| 'Development Status :: 4 - Beta', | ||
| 'Intended Audience :: Developers', | ||
| 'Intended Audience :: System Administrators', | ||
| 'Programming Language :: Python', | ||
| 'Programming Language :: Python :: 2', | ||
| 'Programming Language :: Python :: 2.7', | ||
| 'Programming Language :: Python :: 3', | ||
| 'Programming Language :: Python :: 3.4', | ||
| 'Programming Language :: Python :: 3.5', | ||
| 'Programming Language :: Python :: 3.6', | ||
| ] | ||
|
|
||
| DEPENDENCIES = [ | ||
| 'azure-mgmt-cognitiveservices==1.0.0', | ||
| 'azure-cli-core', | ||
| ] | ||
|
|
||
| with open('README.rst', 'r', encoding='utf-8') as f: | ||
| README = f.read() | ||
| with open('HISTORY.rst', 'r', encoding='utf-8') as f: | ||
| HISTORY = f.read() | ||
|
|
||
| setup( | ||
| name='azure-cli-cognitiveservices', | ||
| version=VERSION, | ||
| description='Microsoft Azure Command-Line Tools Cognitive Services Command Module', | ||
| long_description=README + '\n\n' + HISTORY, | ||
| license='MIT', | ||
| author='Microsoft Corporation', | ||
| author_email='[email protected]', | ||
| url='https://github.com/azure/azure-cli', | ||
| classifiers=CLASSIFIERS, | ||
| packages=[ | ||
| 'azure', | ||
| 'azure.cli', | ||
| 'azure.cli.command_modules', | ||
| 'azure.cli.command_modules.cognitiveservices', | ||
| ], | ||
| install_requires=DEPENDENCIES, | ||
| cmdclass=cmdclass | ||
| ) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setup.py should have the following:
Also, it should have
cmdclass=cmdclassin setup(...). See other modules for examples.cc: @johanste
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed