Skip to content
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

{Maps} Support managed maps creator operations #18450

Merged
merged 21 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from 15 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
12 changes: 10 additions & 2 deletions src/azure-cli/azure/cli/command_modules/maps/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@

def cf_maps(cli_ctx, *_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.mgmt.maps import MapsManagementClient
return get_mgmt_service_client(cli_ctx, MapsManagementClient)
from azure.mgmt.maps import AzureMapsManagementClient
return get_mgmt_service_client(cli_ctx, AzureMapsManagementClient)


def cf_accounts(cli_ctx, *_):
return cf_maps(cli_ctx).accounts


def cf_map(cli_ctx, *_):
return cf_maps(cli_ctx).maps


def cf_creator(cli_ctx, *_):
return cf_maps(cli_ctx).creators
185 changes: 164 additions & 21 deletions src/azure-cli/azure/cli/command_modules/maps/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,48 @@
"""

helps['maps account create'] = """
type: command
short-summary: Create a maps account.
parameters:
- name: --accept-tos
short-summary: Accept the Terms of Service, and do not prompt for confirmation.
long-summary: |
By creating an Azure Maps account, you agree that you have read and agree to the
License (https://azure.microsoft.com/support/legal/) and
Privacy Statement (https://privacy.microsoft.com/privacystatement).
type: command
short-summary: "Create a Maps Account. A Maps Account holds the keys which allow access to the Maps REST APIs."
parameters:
- name: --linked-resources
short-summary: "Sets the resources to be used for Managed Identities based operations for the Map account \
resource."
long-summary: |
Usage: --linked-resources unique-name=XX id=XX

examples:
- name: Create a maps account. (autogenerated)
text: az maps account create --name MyMapsAccount --resource-group MyResourceGroup --sku S0 --subscription MySubscription
crafted: true
unique-name: Required. A provided name which uniquely identifies the linked resource.
id: Required. ARM resource id in the form: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupNa\
me}/providers/Microsoft.Storage/accounts/{storageName}'.

Multiple actions can be specified by using more than one --linked-resources argument.
examples:
- name: Create Account with Managed Identities
text: |-
az maps account create --type "SystemAssigned, UserAssigned" --user-identities \
"{\\"/subscriptions/21a9967a-e8a9-4656-a70b-96ff1c4d05a0/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIden\
tity/userAssignedIdentities/identityName\\":{}}" --kind "Gen2" --disable-local-auth false \
--linked-resources id="/subscriptions/21a9967a-e8a9-4656-a70b-96ff1c4d05a0/resourceGroups/myResourceGroup/providers/Mic\
rosoft.Storage/accounts/mystorageacc" unique-name="myBatchStorageAccount" --linked-resources \
id="/subscriptions/21a9967a-e8a9-4656-a70b-96ff1c4d05a0/resourceGroups/myResourceGroup/providers/Microsoft.Storage/acco\
unts/mystorageacc" unique-name="myBlobDataSource" --name "G2" --tags test="true" --account-name "myMapsAccount" \
--resource-group "myResourceGroup" --sku "S0"
- name: Create Gen1 Account
text: |-
az maps account create --kind "Gen1" --disable-local-auth false --name "S0" --tags \
test="true" --account-name "myMapsAccount" --resource-group "myResourceGroup" --sku "S0"
- name: Create Gen2 Account
text: |-
az maps account create --kind "Gen2" --disable-local-auth true --name "G2" --tags \
test="true" --account-name "myMapsAccount" --resource-group "myResourceGroup" --sku "S0"
Jing-song marked this conversation as resolved.
Show resolved Hide resolved
"""

helps['maps account delete'] = """
type: command
short-summary: Delete a maps account.
examples:
- name: Delete a maps account. (autogenerated)
text: az maps account delete --name MyMapsAccount --resource-group MyResourceGroup
crafted: true
type: command
short-summary: "Delete a Maps Account."
examples:
- name: DeleteAccount
text: |-
az maps account delete --name "myMapsAccount" --resource-group "myResourceGroup"
"""

helps['maps account keys'] = """
Expand Down Expand Up @@ -81,6 +100,130 @@
"""

helps['maps account update'] = """
type: command
short-summary: Update the properties of a maps account.
type: command
short-summary: "Updates a Maps Account. Only a subset of the parameters may be updated after creation, such as \
Sku, Tags, Properties."
parameters:
- name: --linked-resources
short-summary: "Sets the resources to be used for Managed Identities based operations for the Map account \
resource."
long-summary: |
Usage: --linked-resources unique-name=XX id=XX

unique-name: Required. A provided name which uniquely identifies the linked resource.
id: Required. ARM resource id in the form: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupNa\
me}/providers/Microsoft.Storage/accounts/{storageName}'.

Multiple actions can be specified by using more than one --linked-resources argument.
examples:
- name: Update Account Managed Identities
text: |-
az maps account update --type "SystemAssigned, UserAssigned" --user-identities \
"{\\"/subscriptions/21a9967a-e8a9-4656-a70b-96ff1c4d05a0/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIden\
tity/userAssignedIdentities/identityName\\":{}}" --kind "Gen2" --linked-resources id="/subscriptions/{subscriptionId}/r\
esourceGroups/{resourceGroupName}/providers/Microsoft.Storage/accounts/{storageName}" unique-name="myBatchStorageAccoun\
t" --name "G2" --account-name "myMapsAccount" --resource-group "myResourceGroup" --sku "S1"
- name: Update Account Tags
text: |-
az maps account update --tags specialTag="true" --account-name "myMapsAccount" --resource-group \
"myResourceGroup" --sku "S0"
- name: Update to Gen1 Account
text: |-
az maps account update --kind "Gen1" --name "S1" --account-name "myMapsAccount" --resource-group \
"myResourceGroup" --sku "S0"
- name: Update to Gen2 Account
text: |-
az maps account update --kind "Gen2" --name "G2" --account-name "myMapsAccount" --resource-group \
"myResourceGroup" --sku "S0"
"""

helps['maps account keys list'] = """
type: command
short-summary: "Get the keys to use with the Maps APIs. A key is used to authenticate and authorize access to the \
Maps REST APIs. Only one key is needed at a time; two are given to provide seamless key regeneration."
examples:
- name: List Keys
text: |-
az maps account keys list --name "myMapsAccount" --resource-group "myResourceGroup"
"""

helps['maps account keys renew'] = """
type: command
short-summary: "Regenerate either the primary or secondary key for use with the Maps APIs. The old key will stop \
working immediately."
examples:
- name: Renew
text: |-
az maps account keys renew --name "myMapsAccount" --key "primary" --resource-group \
"myResourceGroup"
"""

helps['maps map'] = """
type: group
short-summary: Manage map with maps
"""

helps['maps map list-operation'] = """
type: command
short-summary: "List operations available for the Maps Resource Provider."
examples:
- name: Get Operations
text: |-
az maps map list-operation
"""

helps['maps creator'] = """
type: group
short-summary: Manage creator with maps
"""

helps['maps creator list'] = """
type: command
short-summary: "Get all Creator instances for an Azure Maps Account."
examples:
- name: List Creator Resources By Account
text: |-
az maps creator list --account-name "myMapsAccount" --resource-group "myResourceGroup"
"""

helps['maps creator show'] = """
type: command
short-summary: "Get a Maps Creator resource."
examples:
- name: Get Creator Resource
text: |-
az maps creator show --account-name "myMapsAccount" --creator-name "myCreator" --resource-group \
"myResourceGroup"
"""

helps['maps creator create'] = """
type: command
short-summary: "Create a Maps Creator resource. Creator resource will manage Azure resources required to populate \
a custom set of mapping data. It requires an account to exist before it can be created."
examples:
- name: Create Creator Resource
text: |-
az maps creator create --location "eastus2" --storage-units 5 --tags test="true" --account-name \
"myMapsAccount" --creator-name "myCreator" --resource-group "myResourceGroup"
"""

helps['maps creator update'] = """
type: command
short-summary: "Updates the Maps Creator resource. Only a subset of the parameters may be updated after creation, \
such as Tags."
examples:
- name: Update Creator Resource
text: |-
az maps creator update --storage-units 10 --tags specialTag="true" --account-name "myMapsAccount" \
--creator-name "myCreator" --resource-group "myResourceGroup"
"""

helps['maps creator delete'] = """
type: command
short-summary: "Delete a Maps Creator resource."
examples:
- name: Delete Creator Resource
text: |-
az maps creator delete --account-name "myMapsAccount" --creator-name "myCreator" --resource-group \
"myResourceGroup"
"""
101 changes: 89 additions & 12 deletions src/azure-cli/azure/cli/command_modules/maps/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@
get_enum_type,
get_resource_name_completion_list,
resource_group_name_type,
tags_type)
tags_type,
get_location_type,
get_three_state_flag)
from azure.cli.core.commands.validators import (
get_default_location_from_resource_group,
validate_file_or_dict
)

from azure.mgmt.maps.models import KeyType
from azure.cli.command_modules.maps.action import AddLinkedResources


def load_arguments(self, _):
# Argument Definition
maps_name_type = CLIArgumentType(options_list=['--name', '-n'],
maps_name_type = CLIArgumentType(options_list=['--name', '--account-name', '-n'],
completer=get_resource_name_completion_list('Microsoft.Maps/accounts'),
help='The name of the maps account')

Expand All @@ -31,17 +38,52 @@ def load_arguments(self, _):
arg_type=maps_name_type)

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

with self.argument_context('maps account create') as c:
c.argument('force',
options_list=['--accept-tos'],
action='store_true')
c.argument('kind', options_list=['--kind'], arg_type=get_enum_type(['Gen1', 'Gen2']),
help='Get or Set Kind property.')
c.argument('disable_local_auth', options_list=['--disable-local-auth'], arg_type=get_three_state_flag(),
help='Allows toggle functionality on Azure '
'Policy to disable Azure Maps local authentication support. This will disable Shared Keys '
'authentication from any usage.')
c.argument('linked_resources', options_list=['--linked-resources'], action=AddLinkedResources, nargs='+',
help='Sets the resources to be used for '
'Managed Identities based operations for the Map account resource.')
c.argument('type_', options_list=['--type'], arg_type=get_enum_type(['SystemAssigned', 'UserAssigned',
'SystemAssigned, UserAssigned', 'None']),
help='The identity type.', arg_group='Identity')
c.argument('user_assigned_identities', options_list=['--user-identities'], type=validate_file_or_dict,
help='The list of user identities associated with the resource. '
'The user identity dictionary key references will be ARM resource ids '
'in the form: \'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microso'
'ft.ManagedIdentity/userAssignedIdentities/{identityName}\'. Expected value: '
'json-string/@json-file.', arg_group='Identity')
c.argument('force', options_list=['--accept-tos'], action='store_true',
help='You must agree to the License and Privacy Statement to create an account.')

with self.argument_context('maps account update') as c:
c.argument('kind', options_list=['--kind'], arg_type=get_enum_type(['Gen1', 'Gen2']),
help='Get or Set Kind property.')
c.argument('disable_local_auth', options_list=['--disable-local-auth'], arg_type=get_three_state_flag(),
help='Allows toggle functionality on Azure '
'Policy to disable Azure Maps local authentication support. This will disable Shared Keys '
'authentication from any usage.')
c.argument('linked_resources', options_list=['--linked-resources'], action=AddLinkedResources, nargs='+',
help='Sets the resources to be used for '
'Managed Identities based operations for the Map account resource.')
c.argument('type_', options_list=['--type'], arg_type=get_enum_type(['SystemAssigned', 'UserAssigned',
'SystemAssigned, UserAssigned', 'None']),
help='The identity type.', arg_group='Identity')
c.argument('user_assigned_identities', options_list=['--user-identities'], type=validate_file_or_dict,
help='The list of user identities associated with the resource. '
'The user identity dictionary key references will be ARM resource ids '
'in the form: \'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microso'
'ft.ManagedIdentity/userAssignedIdentities/{identityName}\'. Expected value: '
'json-string/@json-file.', arg_group='Identity')

# Prevent --ids argument in keys with id_part=None
with self.argument_context('maps account keys') as c:
Expand All @@ -52,4 +94,39 @@ def load_arguments(self, _):
with self.argument_context('maps account keys renew') as c:
c.argument('key_type',
options_list=['--key'],
arg_type=get_enum_type(KeyType))
arg_type=get_enum_type(KeyType),
help='Whether the operation refers to the primary or secondary key')

with self.argument_context('maps creator') as c:
c.argument('tags', arg_type=tags_type)

with self.argument_context('maps creator create') as c:
c.argument('creator_name', options_list=['--creator-name'], type=str, help='The name of the '
'Maps Creator instance.')
c.argument('location', options_list=['--location', '-l'], arg_type=get_location_type(self.cli_ctx),
required=False, validator=get_default_location_from_resource_group)
c.argument('storage_units', options_list=['--storage-units'], type=int,
help='The storage units to be allocated. Integer values from 1 to 100, inclusive.')

with self.argument_context('maps creator update') as c:
c.argument('creator_name', options_list=['--creator-name'], type=str, help='The name of the '
'Maps Creator instance.', id_part='child_name_1')
c.argument('storage_units', options_list=['--storage-units'], type=int,
help='The storage units to be allocated. Integer values from 1 to 100, inclusive.')

with self.argument_context('maps creator delete') as c:
c.argument('creator_name', options_list=['--creator-name'], type=str, help='The name of the '
'Maps Creator instance.', id_part='child_name_1')

with self.argument_context('maps creator show') as c:
c.argument('creator_name', options_list=['--creator-name'], type=str, help='The name of the '
'Maps Creator instance.', id_part='child_name_1')

with self.argument_context('maps creator list') as c:
c.argument('resource_group_name',
arg_type=resource_group_name_type,
id_part=None,
help='Resource group name')
c.argument('account_name',
id_part=None,
arg_type=maps_name_type)
41 changes: 41 additions & 0 deletions src/azure-cli/azure/cli/command_modules/maps/action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access

import argparse
from collections import defaultdict
from knack.util import CLIError


class AddLinkedResources(argparse._AppendAction):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
super(AddLinkedResources, self).__call__(parser, namespace, action, option_string)

def get_action(self, values, option_string): # pylint: disable=no-self-use
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
properties[k].append(v)
properties = dict(properties)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'unique-name':
d['unique_name'] = v[0]
elif kl == 'id':
d['id'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter linked_resources. All possible keys are: '
'unique-name, id'.format(k))
return d
Loading