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

[signalr] az signalr identity: Add managed identity related command, az signalr cors update: Add update for CORS #18309

Merged
merged 6 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 0 additions & 4 deletions src/azure-cli/azure/cli/command_modules/signalr/_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@
# pylint: disable=protected-access, too-few-public-methods
class UpstreamTemplateAddAction(argparse._AppendAction):
def __call__(self, parser, namespace, values, option_string=None):
# logger.warning(self.dest)
# logger.warning(namespace)
# logger.warning(values)
kwargs = {}
for item in values:
try:
key, value = item.split('=', 1)
kwargs[key.replace('-', '_')] = value
except ValueError:
raise CLIError('usage error: {} KEY=VALUE [KEY=VALUE ...]'.format(option_string))
# logger.warning(kwargs)
value = UpstreamTemplate(**kwargs)
super().__call__(parser, namespace, value, option_string)
36 changes: 36 additions & 0 deletions src/azure-cli/azure/cli/command_modules/signalr/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
short-summary: Manage upstream settings.
"""

helps['signalr identity'] = """
type: group
short-summary: Manage managed identity settings.
"""

helps['signalr cors add'] = """
type: command
short-summary: Add allowed origins to a SignalR Service
Expand All @@ -50,6 +55,15 @@
az signalr cors remove -n MySignalR -g MyResourceGroup --allowed-origins "http://example1.com" "https://example2.com"
"""

helps['signalr cors update'] = """
type: command
short-summary: Update allowed origins to a SignalR Service
examples:
- name: Update a list of allowed origins to a SignalR Service
text: >
az signalr cors update -n MySignalR -g MyResourceGroup --allowed-origins "http://example1.com" "https://example2.com"
"""

helps['signalr create'] = """
type: command
short-summary: Creates a SignalR Service.
Expand Down Expand Up @@ -177,3 +191,25 @@
text: >
az signalr network-rule update --public-network --connection-name MyPrivateEndpointConnection1 MyPrivateEndpointConnection2 -n MySignalR -g MyResourceGroup --deny ClientConnection
"""

helps['signalr identity assign'] = """
type: command
short-summary: Assign managed identity for SignalR Service.
examples:
- name: Assign system assigned identity.
text: >
az signalr identity assign --identity [system] -n MySignalR -g MyResourceGroup
- name: Assign user assigned identity.
text: >
az signalr identity assign --identity MyManagedIdentityId -n MySignalR -g MyResourceGroup
"""

helps['signalr identity remove'] = """
type: command
short-summary: Remove managed identity for SignalR Service.
"""

helps['signalr identity show'] = """
type: command
short-summary: Show managed identity for SignalR Service.
"""
12 changes: 11 additions & 1 deletion src/azure-cli/azure/cli/command_modules/signalr/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# --------------------------------------------------------------------------------------------


from knack.arguments import CLIArgumentType
from knack.log import get_logger
from azure.mgmt.signalr.models import SignalRRequestType
from azure.cli.core.commands.validators import get_default_location_from_resource_group
Expand All @@ -30,12 +31,14 @@


def load_arguments(self, _):
signalr_name_type = CLIArgumentType(options_list='--signalr-name', help='Name of the SignalR.', id_part='name')

with self.argument_context('signalr') as c:
c.argument('resource_group_name', arg_type=resource_group_name_type)
c.argument('location',
arg_type=get_location_type(self.cli_ctx),
validator=get_default_location_from_resource_group)
c.argument('signalr_name', options_list=['--name', '-n'],
c.argument('signalr_name', signalr_name_type, options_list=['--name', '-n'],
completer=get_resource_name_completion_list(SIGNALR_RESOURCE_TYPE),
help='Name of signalr service.')
c.argument('tags', arg_type=tags_type)
Expand Down Expand Up @@ -67,6 +70,9 @@ def load_arguments(self, _):
with self.argument_context('signalr cors remove') as c:
c.argument('allowed_origins', options_list=['--allowed-origins', '-a'], nargs='*', help='space separated origins that should be allowed to make cross-origin calls (for example: http://example.com:12345). To allow all, use "*"')

with self.argument_context('signalr cors update') as c:
c.argument('allowed_origins', options_list=['--allowed-origins', '-a'], nargs='*', help='space separated origins that should be allowed to make cross-origin calls (for example: http://example.com:12345). To allow all, use "*"')

# Network Rule
zackliu marked this conversation as resolved.
Show resolved Hide resolved
with self.argument_context('signalr network-rule update') as c:
c.argument('connection_name', nargs='*', help='Space-separeted list of private endpoint connection name.', required=False, arg_group='Private Endpoint Connection')
Expand All @@ -77,3 +83,7 @@ def load_arguments(self, _):
# Upstream Settings
with self.argument_context('signalr upstream update') as c:
c.argument('template', action=UpstreamTemplateAddAction, nargs='+', help='Template item for upstream settings. Use key=value pattern to set properties. Supported keys are "url-template", "hub-pattern", "event-pattern", "category-pattern".')

# Managed Identity
with self.argument_context('signalr identity assign') as c:
c.argument('identity', help="Assigns managed identities to the service. Use '[system]' to refer to the system-assigned identity or a resource ID to refer to a user-assigned identity. You can only assign either on of them.")
11 changes: 11 additions & 0 deletions src/azure-cli/azure/cli/command_modules/signalr/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def load_command_table(self, _):
client_factory=cf_signalr
)

signalr_msi_utils = CliCommandType(
operations_tmpl='azure.cli.command_modules.signalr.msi#{}',
client_factory=cf_signalr
)

with self.command_group('signalr', signalr_custom_utils) as g:
g.command('create', 'signalr_create')
g.command('delete', 'signalr_delete')
Expand All @@ -56,6 +61,7 @@ def load_command_table(self, _):
g.command('add', 'signalr_cors_add')
g.command('remove', 'signalr_cors_remove')
g.command('list', 'signalr_cors_list')
g.command('update', 'signalr_cors_update')

with self.command_group('signalr network-rule', signalr_network_utils) as g:
g.command('list', 'list_network_rules')
Expand All @@ -65,3 +71,8 @@ def load_command_table(self, _):
g.command('list', 'signalr_upstream_list')
g.command('update', 'signalr_upstream_update')
g.command('clear', 'signalr_upstream_clear')

with self.command_group('signalr identity', signalr_msi_utils) as g:
g.command('assign', 'signalr_msi_assign')
g.command('remove', 'signalr_msi_remove')
g.show_command('show', 'signalr_msi_show')
10 changes: 8 additions & 2 deletions src/azure-cli/azure/cli/command_modules/signalr/cors.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def signalr_cors_add(client, resource_group_name, signalr_name, allowed_origins)
cors.allowed_origins = cors.allowed_origins + allowed_origins
parameters = SignalRResource(cors=cors)

return client.update(resource_group_name, signalr_name, parameters)
return client.begin_update(resource_group_name, signalr_name, parameters)


def signalr_cors_remove(client, resource_group_name, signalr_name, allowed_origins):
Expand All @@ -32,7 +32,13 @@ def signalr_cors_remove(client, resource_group_name, signalr_name, allowed_origi
cors.allowed_origins = ['*']
parameters = SignalRResource(cors=cors)

return client.update(resource_group_name, signalr_name, parameters)
return client.begin_update(resource_group_name, signalr_name, parameters)


def signalr_cors_update(client, resource_group_name, signalr_name, allowed_origins):
cors = SignalRCorsSettings(allowed_origins=allowed_origins)
parameters = SignalRResource(cors=cors)
return client.begin_update(resource_group_name, signalr_name, parameters)


def _get_cors_details(client, resource_group_name, signalr_name):
Expand Down
8 changes: 4 additions & 4 deletions src/azure-cli/azure/cli/command_modules/signalr/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def signalr_create(client, signalr_name, resource_group_name,
location=location,
network_ac_ls=SignalRNetworkACLs(default_action=default_action))

return client.create_or_update(resource_group_name, signalr_name, parameter)
return client.begin_create_or_update(resource_group_name, signalr_name, parameter)


def signalr_delete(client, signalr_name, resource_group_name):
return client.delete(resource_group_name, signalr_name)
return client.begin_delete(resource_group_name, signalr_name)


def signalr_list(client, resource_group_name=None):
Expand All @@ -45,15 +45,15 @@ def signalr_show(client, signalr_name, resource_group_name):


def signalr_restart(client, signalr_name, resource_group_name):
return client.restart(resource_group_name, signalr_name)
return client.begin_restart(resource_group_name, signalr_name)


def signalr_update_get():
return SignalRResource()


def signalr_update_set(client, signalr_name, resource_group_name, parameters):
return client.update(resource_group_name, signalr_name, parameters)
return client.begin_update(resource_group_name, signalr_name, parameters)


def signalr_update_custom(instance, sku=None, unit_count=1, tags=None, service_mode=None, allowed_origins=None, default_action=None, enable_message_logs=None):
Expand Down
9 changes: 3 additions & 6 deletions src/azure-cli/azure/cli/command_modules/signalr/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long


from azure.mgmt.signalr.models import KeyType
from azure.mgmt.signalr.models import RegenerateKeyParameters


def signalr_key_list(client, resource_group_name, signalr_name):
return client.list_keys(resource_group_name, signalr_name)


def signalr_key_renew(client, resource_group_name, signalr_name, key_type):
if key_type == 'primary':
key_type = KeyType.primary
else:
key_type = KeyType.secondary
return client.regenerate_key(resource_group_name, signalr_name, key_type, polling=False)
return client.begin_regenerate_key(resource_group_name, signalr_name, RegenerateKeyParameters(key_type=key_type), polling=False)
36 changes: 36 additions & 0 deletions src/azure-cli/azure/cli/command_modules/signalr/msi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# --------------------------------------------------------------------------------------------
# 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.signalr.models import (
ManagedIdentity,
SignalRResource)

SYSTEM_ASSIGNED_IDENTITY_ALIAS = '[system]'


def signalr_msi_assign(client, resource_group_name, signalr_name, identity):
msiType, user_identity = _analyze_identity(identity)

identity = ManagedIdentity(type=msiType, userAssignedidentity={user_identity, None} if user_identity else None)
parameter = SignalRResource(identity=identity)
return client.begin_update(resource_group_name, signalr_name, parameter)


def signalr_msi_remove(client, resource_group_name, signalr_name):
identity = ManagedIdentity(type="None")
parameter = SignalRResource(identity=identity)
return client.begin_update(resource_group_name, signalr_name, parameter)


def signalr_msi_show(client, resource_group_name, signalr_name):
res = client.get(resource_group_name, signalr_name)
return res.identity


def _analyze_identity(identity):
if identity == SYSTEM_ASSIGNED_IDENTITY_ALIAS:
return "SystemAssigned", None
return "UserAssigned", identity
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/signalr/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def update_network_rules(client, signalr_name, resource_group_name, public_netwo
x.allow = allow
x.deny = deny

return client.update(resource_group_name, signalr_name, SignalRResource(network_ac_ls=network_acl))
return client.begin_update(resource_group_name, signalr_name, SignalRResource(network_ac_ls=network_acl))


def list_network_rules(client, signalr_name, resource_group_name):
Expand Down
Loading