Skip to content
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
32 changes: 32 additions & 0 deletions azure-cli.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,29 @@
<Compile Include="command_modules\azure-cli-cloud\azure\cli\command_modules\cloud\_params.py" />
<Compile Include="command_modules\azure-cli-cloud\azure\cli\command_modules\cloud\__init__.py" />
<Compile Include="command_modules\azure-cli-cloud\setup.py" />
<Compile Include="command_modules\azure-cli-cognitiveservices\azure\cli\command_modules\cognitiveservices\commands.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-cognitiveservices\azure\cli\command_modules\cognitiveservices\custom.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-cognitiveservices\azure\cli\command_modules\cognitiveservices\_client_factory.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-cognitiveservices\azure\cli\command_modules\cognitiveservices\_help.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-cognitiveservices\azure\cli\command_modules\cognitiveservices\_params.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-cognitiveservices\azure\cli\command_modules\cognitiveservices\__init__.py" />
<Compile Include="command_modules\azure-cli-cognitiveservices\azure\cli\command_modules\__init__.py" />
<Compile Include="command_modules\azure-cli-cognitiveservices\azure\cli\__init__.py" />
<Compile Include="command_modules\azure-cli-cognitiveservices\azure\__init__.py" />
<Compile Include="command_modules\azure-cli-cognitiveservices\setup.py" />
<Compile Include="command_modules\azure-cli-cognitiveservices\tests\test_cognitiveservices_command.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-component\azure\cli\command_modules\component\_help.py">
<SubType>Code</SubType>
</Compile>
Expand Down Expand Up @@ -635,6 +658,12 @@
<Folder Include="command_modules\azure-cli-cloud\azure\cli\" />
<Folder Include="command_modules\azure-cli-cloud\azure\cli\command_modules\" />
<Folder Include="command_modules\azure-cli-cloud\azure\cli\command_modules\cloud\" />
<Folder Include="command_modules\azure-cli-cognitiveservices\" />
<Folder Include="command_modules\azure-cli-cognitiveservices\azure\" />
<Folder Include="command_modules\azure-cli-cognitiveservices\azure\cli\" />
<Folder Include="command_modules\azure-cli-cognitiveservices\azure\cli\command_modules\" />
<Folder Include="command_modules\azure-cli-cognitiveservices\azure\cli\command_modules\cognitiveservices\" />
<Folder Include="command_modules\azure-cli-cognitiveservices\tests\" />
<Folder Include="command_modules\azure-cli-component\" />
<Folder Include="command_modules\azure-cli-component\azure\" />
<Folder Include="command_modules\azure-cli-component\azure\cli\" />
Expand Down Expand Up @@ -814,6 +843,9 @@
<Content Include="command_modules\azure-cli-batch\tests\data\batchUpdatePool.json" />
<Content Include="command_modules\azure-cli-batch\tests\README.md" />
<Content Include="command_modules\azure-cli-cloud\HISTORY.rst" />
<Content Include="command_modules\azure-cli-cognitiveservices\HISTORY.rst" />
<Content Include="command_modules\azure-cli-cognitiveservices\MANIFEST.in" />
<Content Include="command_modules\azure-cli-cognitiveservices\README.rst" />
<Content Include="command_modules\azure-cli-component\HISTORY.rst" />
<Content Include="command_modules\azure-cli-configure\HISTORY.rst" />
<Content Include="command_modules\azure-cli-container\HISTORY.rst" />
Expand Down
9 changes: 9 additions & 0 deletions src/command_modules/azure-cli-cognitiveservices/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.. :changelog:

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

Unreleased
--------------------------
* inital cognitive services CLI

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include *.rst
7 changes: 7 additions & 0 deletions src/command_modules/azure-cli-cognitiveservices/README.rst
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'


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__)
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__)
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__)
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
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
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.
"""
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')
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)
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)
61 changes: 61 additions & 0 deletions src/command_modules/azure-cli-cognitiveservices/setup.py
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

Copy link
Member

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:

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 = {}

Also, it should have cmdclass=cmdclass in setup(...). See other modules for examples.

cc: @johanste

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

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
)
Loading