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
Prev Previous commit
Next Next commit
[Legal] Add the Preview Terms agreement requirement
- Add the Preview Terms agreement requirement
- Remove location, custom_header, and raw parameters for account operations.
  • Loading branch information
jp94 committed Feb 24, 2018
commit b74cb79aa6c72b4409941f6115af9ad854d7675b
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def load_arguments(self, _):
required=False)
c.argument('tags',
arg_type=tags_type)
c.argument('agree',
options_list=['--agree-to-the-preview-terms'],
help='You agree to the Preview Terms. Ignore prompt for confirmation.',
action='store_true')

with self.argument_context('locationbasedservices account key regenerate') as c:
c.argument('key_type',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.log import get_logger
from knack.prompting import prompt_y_n
from knack.util import CLIError

from azure.mgmt.locationbasedservices.models import LocationBasedServicesAccountCreateParameters, Sku

logger = get_logger(__name__)


# pylint: disable=line-too-long
def create(client, resource_group_name, account_name, sku_name='S0', tags=None, custom_headers=None,
raw=False):
def create(client, resource_group_name, account_name, sku_name='S0', tags=None, agree=None):
"""Create a Location Based Services Account. A Location Based
Services Account holds the keys which allow access to the Location
Based Services REST APIs.
Expand All @@ -25,23 +30,33 @@ def create(client, resource_group_name, account_name, sku_name='S0', tags=None,
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
:param agree: If true, user agrees to the Preview Terms. Ignore prompt
for confirmation. False otherwise.
:type agree: bool
: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>`
"""
# Prompt for the Preview Terms agreement.
logger.warning(
'By creating a Location Based Services account, you agree to the Microsoft Azure Preview Terms.' +
'\nThe Preview Terms can be found at: ' +
'\nhttps://azure.microsoft.com/en-us/support/legal/preview-supplemental-terms/')
if not agree: # ... in order to pass tests
response = prompt_y_n('I confirm that I have read and agree to the Microsoft Azure Preview Terms.')
if not response:
raise CLIError('You must agree to the Microsoft Azure Preview Terms to create an account.')
Copy link
Member

Choose a reason for hiding this comment

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

This is generally not used anywhere else for create commands. Is there a particular reason LBS would be different?


# Proceed if user has agreed to the Preview Terms.
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)
return client.create_or_update(resource_group_name, account_name, lbs_account_create_params)


def list_accounts(client, resource_group_name=None, custom_headers=None, raw=False):
def list_accounts(client, resource_group_name=None):
"""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.
Expand All @@ -58,5 +73,5 @@ def list_accounts(client, resource_group_name=None, custom_headers=None, raw=Fal
: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)
return client.list_by_subscription()
return client.list_by_resource_group(resource_group_name)
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@ class LocationBasedServicesScenarioTests(ScenarioTest):
@ResourceGroupPreparer()
def test_create_locationbasedservices_account(self, resource_group):
self.kwargs.update({
'name': self.create_random_name(prefix='cli-locationbasedservices', length=20),
'name1': self.create_random_name(prefix='cli-locationbasedservices', length=20),
'name2': self.create_random_name(prefix='cli-locationbasedservices', length=20),
'name': self.create_random_name(prefix='cli-', length=20),
'name1': self.create_random_name(prefix='cli-', length=20),
'name2': self.create_random_name(prefix='cli-', length=20),
'sku': 'S0',
'loc': 'global',
'key_type_primary': KeyType.primary.value,
'key_type_secondary': KeyType.secondary.value
})

# Test 'az locationbasedservices account create'
# Test to create an LocationBasedServices account
account = self.cmd('az locationbasedservices account create -n {name} -g {rg} --sku {sku} -l {loc}', checks=[
self.check('location', '{loc}'),
self.check('name', '{name}'),
self.check('resourceGroup', '{rg}'),
self.check('sku.name', '{sku}')
]).get_output_in_json()
account = self.cmd('az locationbasedservices account create -n {name} -g {rg} --sku {sku} ' +
'--agree-to-the-preview-terms',
checks=[
self.check('name', '{name}'),
self.check('resourceGroup', '{rg}'),
self.check('sku.name', '{sku}')
]).get_output_in_json()

# Call create again, expect to get the same account
account_duplicated = self.cmd(
'az locationbasedservices account create -n {name} -g {rg} --sku {sku} -l {loc}').get_output_in_json()
'az locationbasedservices account create -n {name} -g {rg} --sku {sku} ' +
'--agree-to-the-preview-terms').get_output_in_json()
self.assertEqual(account, account_duplicated)

# Test 'az locationbasedservices account show'
# Test to get information on LocationBasedServices account
self.cmd('az locationbasedservices account show -n {name} -g {rg}', checks=[
self.check('id', account['id']),
self.check('location', '{loc}'),
self.check('name', '{name}'),
self.check('resourceGroup', '{rg}'),
self.check('sku.name', '{sku}')
Expand All @@ -51,16 +51,17 @@ def test_create_locationbasedservices_account(self, resource_group):
self.check('length(@)', 1),
self.check('type(@)', 'array'),
self.check('[0].id', account['id']),
self.check('[0].location', '{loc}'),
self.check('[0].name', '{name}'),
self.check('[0].resourceGroup', '{rg}'),
self.check('[0].sku.name', '{sku}'),
self.check('[0].tags', None)
])

# Create two new accounts
self.cmd('az locationbasedservices account create -n {name1} -g {rg} --sku {sku} -l {loc}')
self.cmd('az locationbasedservices account create -n {name2} -g {rg} --sku {sku} -l {loc}')
self.cmd('az locationbasedservices account create -n {name1} -g {rg} --sku {sku} ' +
'--agree-to-the-preview-terms')
self.cmd('az locationbasedservices account create -n {name2} -g {rg} --sku {sku} ' +
'--agree-to-the-preview-terms')
# Check that list command now shows three accounts.
self.cmd('az locationbasedservices account list -g {rg}', checks=[
self.check('length(@)', 3),
Expand Down Expand Up @@ -99,7 +100,8 @@ def test_create_locationbasedservices_account(self, resource_group):
# Save the new primary key, and regenerate the secondary key.
primary_key_old = key_regenerated['primaryKey']
key_regenerated = self.cmd(
'az locationbasedservices account key regenerate -n {name} -g {rg} -t {key_type_secondary}').get_output_in_json()
'az locationbasedservices account key regenerate -n {name} -g {rg} -t {key_type_secondary}') \
.get_output_in_json()
self.assertEqual(primary_key_old, key_regenerated['primaryKey'])
self.assertNotEqual(secondary_key_old, key_regenerated['secondaryKey'])

Expand Down