Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
418b2a1
Introduce LocationBasedServices command_module
jp94 Feb 23, 2018
8bbcd51
Introduce test cases for LocationBasedServices command_module
jp94 Feb 23, 2018
18d9384
[Refactor] Renamed lbs to locationbasedservices
jp94 Feb 24, 2018
cb738db
[Refactor] Renamed lbs to locationbasedservices
jp94 Feb 24, 2018
b74cb79
[Legal] Add the Preview Terms agreement requirement
jp94 Feb 24, 2018
409b03b
[Test] Add more strict assertion rule for key validation.
jp94 Feb 26, 2018
ed3ca01
[Test] Add test for tags parameter
jp94 Feb 26, 2018
81e4fb5
[Test] Added an additional resource group.
jp94 Feb 26, 2018
0d11a6d
[Test] Init recordings
jp94 Feb 26, 2018
87accc7
Merge remote-tracking branch 'upstream/dev' into dev
jp94 Feb 26, 2018
9e5051f
[Pylint] Specify string format arguments as logging function parameters
jp94 Feb 26, 2018
77a9f22
[Refactor] Update description in _help to match the general template
jp94 Feb 27, 2018
98d973e
[Refactor] General template mismatch fix for 'key'
jp94 Feb 27, 2018
5853331
[Feature] Introduce search by ids
jp94 Feb 28, 2018
4d930f8
[Temporary] Throw an exception on 'account show' command, when nonexist
jp94 Feb 28, 2018
d36abf9
[Test] 'account show' on non-existent account should not return empty.
jp94 Feb 28, 2018
b79cb10
[Feature] Introduce update command
jp94 Mar 1, 2018
75795e6
[Test] Add test for update and search by id
jp94 Mar 1, 2018
100df29
Merge remote-tracking branch 'upstream/dev' into dev
jp94 Mar 20, 2018
1fd7bef
[Refactor] Rename generic client (sync with updated Swagger)
jp94 Mar 21, 2018
1aee6b2
[Refactor] Use default SDK's function
jp94 Mar 21, 2018
35976e7
[Refactor] Remove Preview Terms & docs in custom.py
jp94 Mar 21, 2018
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
Next Next commit
Introduce LocationBasedServices command_module
  • Loading branch information
jp94 committed Feb 23, 2018
commit 418b2a188a156df8eaed4a0133ce7e56d4131507
8 changes: 8 additions & 0 deletions src/command_modules/azure-cli-lbs/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. :changelog:

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

0.1.0
+++++
* Initial release
1 change: 1 addition & 0 deletions src/command_modules/azure-cli-lbs/MANIFEST.in
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-lbs/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Microsoft Azure CLI 'location based services' Command Module
====================================================

This package is for the 'location based services' module.
i.e. 'az lbs'


4 changes: 4 additions & 0 deletions src/command_modules/azure-cli-lbs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
6 changes: 6 additions & 0 deletions src/command_modules/azure-cli-lbs/azure/__init__.py
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 src/command_modules/azure-cli-lbs/azure/cli/__init__.py
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,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

import azure.cli.command_modules.lbs._help # pylint: disable=unused-import
from azure.cli.command_modules.lbs._client_factory import cf_accounts


class LocationBasedServicesCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
custom_type = CliCommandType(
operations_tmpl='azure.cli.command_modules.lbs.custom#{}',
client_factory=cf_accounts)
super(LocationBasedServicesCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=custom_type)

def load_command_table(self, args):
from azure.cli.command_modules.lbs.commands import load_command_table
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azure.cli.command_modules.lbs._params import load_arguments
load_arguments(self, command)


COMMAND_LOADER_CLS = LocationBasedServicesCommandsLoader
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_lbs(cli_ctx, *_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.mgmt.locationbasedservices import Client
return get_mgmt_service_client(cli_ctx, Client)


def cf_accounts(cli_ctx, *_):
return cf_lbs(cli_ctx).accounts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.help_files import helps

helps['lbs'] = """
type: group
short-summary: Manage Azure Location Based Services accounts.
"""

helps['lbs account'] = """
type: group
short-summary: Commands to manage Azure Location Based Services accounts.
"""

helps['lbs account key'] = """
type: group
short-summary: Commands to manage Azure Location Based Services account keys.
"""

helps['lbs account show'] = """
type: command
short-summary: Show a Location Based Services account.
"""

helps['lbs account list'] = """
type: command
short-summary: Show all Location Based Services accounts in a Subscription or in a Resource Group.
"""

helps['lbs account create'] = """
type: command
short-summary: Create a Location Based Services account.
long-summary: |
Create a Location Based Services account. A Location Based Services account holds the keys which allow access to the Location Based Services REST APIs.
"""

helps['lbs account delete'] = """
type: command
short-summary: Delete a Location Based Services account.
"""

helps['lbs account key list'] = """
type: command
short-summary: List the keys to use with the Location Based Services APIs.
long-summary: |
List the keys to use with the Location Based Services APIs. A key is used to authenticate and authorize access to the Location Based Services REST APIs. Only one key is needed at a time; two are given to provide seamless key regeneration.
"""

helps['lbs account key regenerate'] = """
type: command
short-summary: Regenerate either the primary or secondary key for use with the Location Based Services APIs.
long-summary: |
Regenerate either the primary or secondary key for use with the Location Based Services APIs. The old key will stop working immediately.
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.arguments import CLIArgumentType

from azure.cli.core.commands.parameters import (
get_enum_type,
get_resource_name_completion_list,
resource_group_name_type,
tags_type)

from azure.cli.command_modules.lbs.validators import validate_account_name
from azure.mgmt.locationbasedservices.models.client_enums import KeyType


def load_arguments(self, _):
# Argument Definition
lbs_name_type = CLIArgumentType(options_list=['--account-name', '-n'],
completer=get_resource_name_completion_list(
'Microsoft.LocationBasedServices/accounts'),
help='The name of the Location Based Services Account',
validator=validate_account_name)

# Parameter Registration
with self.argument_context('lbs') as c:
c.argument('resource_group_name',
arg_type=resource_group_name_type,
help='Resource group name')
c.argument('account_name',
arg_type=lbs_name_type)

with self.argument_context('lbs account create') as c:
c.argument('sku_name',
options_list=['--sku', '-s'],
help='The name of the SKU, in standard format (such as S0).',
arg_type=get_enum_type(['S0']),
required=False)
c.argument('tags',
arg_type=tags_type)

with self.argument_context('lbs account key regenerate') as c:
c.argument('key_type',
options_list=['--type', '-t'],
arg_type=get_enum_type(KeyType))
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 import CliCommandType
from azure.cli.command_modules.lbs._client_factory import cf_accounts


def load_command_table(self, _):
mgmt_type = CliCommandType(
operations_tmpl='azure.mgmt.locationbasedservices.operations.accounts_operations#AccountsOperations.{}',
client_factory=cf_accounts)

with self.command_group('lbs account', mgmt_type) as g:
g.command('show', 'get')
g.custom_command('list', 'list_accounts')
g.custom_command('create', 'create')
g.command('delete', 'delete')

with self.command_group('lbs account key', mgmt_type) as g:
g.command('regenerate', 'regenerate_keys')
g.command('list', 'list_keys')
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# --------------------------------------------------------------------------------------------
# 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.locationbasedservices.models import LocationBasedServicesAccountCreateParameters, Sku


# pylint: disable=line-too-long
def create(client, resource_group_name, account_name, sku_name='S0', tags=None, custom_headers=None,
raw=False):
"""Create a Location Based Services Account. A Location Based
Services Account holds the keys which allow access to the Location
Based Services REST APIs.

:param resource_group_name: The name of the Azure Resource Group.
:type resource_group_name: str
:param account_name: The name of the Location Based Services Account.
:type account_name: str
:param sku_name: The name of the SKU, in standard format (such as S0).
:type sku_name: str
:param tags: Gets or sets a list of key value pairs that describe the
resource. These tags can be used in viewing and grouping this resource
(across resource groups). A maximum of 15 tags can be provided for a
resource. Each tag must have a key no greater than 128 characters and
value no greater than 256 characters.
:type tags: dict[str, str]
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
:return: LocationBasedServicesAccount or ClientRawResponse if raw=true
:rtype:
~azure.mgmt.locationbasedservices.models.LocationBasedServicesAccount
or ~msrest.pipeline.ClientRawResponse
:raises:
:class:`ErrorException<azure.mgmt.locationbasedservices.models.ErrorException>`
"""

sku = Sku(sku_name)
lbs_account_create_params = LocationBasedServicesAccountCreateParameters('global', sku, tags)
return client.create_or_update(resource_group_name, account_name, lbs_account_create_params, custom_headers, raw)


def list_accounts(client, resource_group_name=None, custom_headers=None, raw=False):
"""Get all Location Based Services Accounts in a Resource Group OR in a Subscription.

:param resource_group_name: The name of the Azure Resource Group.
:type resource_group_name: str
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
:param operation_config: :ref:`Operation configuration
overrides<msrest:optionsforoperations>`.
:return: An iterator like instance of LocationBasedServicesAccount
:rtype:
~azure.mgmt.locationbasedservices.models.LocationBasedServicesAccountPaged[~azure.mgmt.locationbasedservices.models.LocationBasedServicesAccount]
:raises:
:class:`ErrorException<azure.mgmt.locationbasedservices.models.ErrorException>`
"""
if resource_group_name is None:
return client.list_by_subscription(custom_headers, raw)
return client.list_by_resource_group(resource_group_name, custom_headers, raw)
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,26 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import re

from knack.util import CLIError

ACCOUNT_NAME_MIN_LENGTH = 2
ACCOUNT_NAME_MAX_LENGTH = 64
ACCOUNT_NAME_REGEX = re.compile("^[a-zA-Z0-9][a-zA-Z0-9_.-]*$")


def validate_account_name(namespace):
""" Validates account name."""
account_name = namespace.account_name
char_len = len(account_name)

if not ACCOUNT_NAME_MIN_LENGTH <= char_len <= ACCOUNT_NAME_MAX_LENGTH:
raise CLIError("Input account-name is invalid. Account name character length must be between 2 and 64.")
if not re.match(ACCOUNT_NAME_REGEX, account_name):
raise CLIError("Input account-name is invalid. Allowed regex: " + ACCOUNT_NAME_REGEX.pattern +
"\nFirst character must be alphanumeric." +
"\nSubsequent character(s) must be any combination of alphanumeric, underscore (_), " +
"period (.), or hyphen (-).")
Loading