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] Add custom domain and custom certificate support #23410

Merged
merged 9 commits into from
Aug 4, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ def cf_private_link_resources(cli_ctx, *_):

def cf_usage(cli_ctx, *_):
return _signalr_client_factory(cli_ctx).usages


def cf_custom_domains(cli_ctx, *_):
return _signalr_client_factory(cli_ctx).signal_rcustom_domains


def cf_custom_certificates(cli_ctx, *_):
return _signalr_client_factory(cli_ctx).signal_rcustom_certificates
67 changes: 65 additions & 2 deletions src/azure-cli/azure/cli/command_modules/signalr/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
short-summary: Manage managed identity settings.
"""

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

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

helps['signalr cors add'] = """
type: command
short-summary: Add allowed origins to a SignalR Service
Expand Down Expand Up @@ -68,9 +78,12 @@
type: command
short-summary: Creates a SignalR Service.
examples:
- name: Create a SignalR Service with the Standard SKU and serverless mode and enable messaging logs.
- name: Create a SignalR Service with the Premium SKU and default mode
text: >
az signalr create -n MySignalR -g MyResourceGroup --sku Premium_P1
- name: Create a SignalR Service with the Premium SKU and serverless mode and enable messaging logs.
text: >
az signalr create -n MySignalR -g MyResourceGroup --sku Standard_S1 --unit-count 1 --service-mode Serverless --enable-message-logs True
az signalr create -n MySignalR -g MyResourceGroup --sku Premium_P1 --unit-count 1 --service-mode Serverless --enable-message-logs True
"""

helps['signalr delete'] = """
Expand Down Expand Up @@ -213,3 +226,53 @@
type: command
short-summary: Show managed identity for SignalR Service.
"""

helps['signalr custom-domain create'] = """
type: command
short-summary: Create a custom domain of SignalR Service.
"""

helps['signalr custom-domain delete'] = """
type: command
short-summary: Delete a custom domain of SignalR Service.
"""

helps['signalr custom-domain update'] = """
type: command
short-summary: Update a custom domain of SignalR Service.
"""

helps['signalr custom-domain list'] = """
type: command
short-summary: List custom domains of SignalR Service.
"""

helps['signalr custom-domain show'] = """
type: command
short-summary: Show the detail of a custom domain of SignalR Service.
"""

helps['signalr custom-certificate create'] = """
type: command
short-summary: Create a custom certificate of SignalR Service.
"""

helps['signalr custom-certificate delete'] = """
type: command
short-summary: Delete a custom certificate of SignalR Service.
"""

helps['signalr custom-certificate update'] = """
type: command
short-summary: Update a custom certificate of SignalR Service.
"""

helps['signalr custom-certificate list'] = """
type: command
short-summary: List custom certificate of SignalR Service.
"""

helps['signalr custom-certificate show'] = """
type: command
short-summary: Show the detail of a custom certificate of SignalR Service.
"""
38 changes: 37 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 @@ -3,6 +3,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=too-many-statements


from knack.arguments import CLIArgumentType
Expand Down Expand Up @@ -32,6 +33,8 @@

def load_arguments(self, _):
signalr_name_type = CLIArgumentType(options_list='--signalr-name', help='Name of the SignalR.', id_part='name')
signalr_custom_domain_name_type = CLIArgumentType(help='Name of the custom domain.', id_part='child_name_1')
signalr_custom_certificate_name_type = CLIArgumentType(help='Name of the custom certificate.', id_part='child_name_2')

with self.argument_context('signalr') as c:
c.argument('resource_group_name', arg_type=resource_group_name_type)
Expand All @@ -44,7 +47,7 @@ def load_arguments(self, _):
c.argument('tags', arg_type=tags_type)

with self.argument_context('signalr create') as c:
c.argument('sku', help='The sku name of the signalr service. E.g. Standard_S1')
c.argument('sku', help='The sku name of the signalr service. Allowed values: Premium_P1, Standard_S1, Free_F1')
c.argument('unit_count', help='The number of signalr service unit count', type=int)
c.argument('service_mode', help='The service mode which signalr service will be working on', choices=SIGNALR_SERVICE_MODE_TYPE)
c.argument('enable_message_logs', help='The switch for messaging logs which signalr service will generate or not', arg_type=get_three_state_flag())
Expand Down Expand Up @@ -99,3 +102,36 @@ def load_arguments(self, _):
# 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.")

# Custom Domain
for scope in ['signalr custom-domain update',
'signalr custom-domain create',
'signalr custom-domain show',
'signalr custom-domain delete',
'signalr custom-domain list']:
with self.argument_context(scope) as c:
c.argument('signalr_name', signalr_name_type, id_part=None)
c.argument('name', signalr_custom_domain_name_type)

for scope in ['signalr custom-domain update',
'signalr custom-domain create']:
with self.argument_context(scope) as c:
c.argument('domain_name', help="Custom domain name. For example, `contoso.com`.")
c.argument('certificate_resource_id', help="ResourceId of a previously created custom certificate.")

# Custom Certificate
for scope in ['signalr custom-certificate update',
'signalr custom-certificate create',
'signalr custom-certificate show',
'signalr custom-certificate delete',
'signalr custom-certificate list']:
with self.argument_context(scope) as c:
c.argument('signalr_name', signalr_name_type, id_part=None)
c.argument('name', signalr_custom_certificate_name_type)

for scope in ['signalr custom-certificate update',
'signalr custom-certificate create']:
with self.argument_context(scope) as c:
c.argument('keyvault_base_uri', help="Key vault base URI. For example, `https://contoso.vault.azure.net`.")
c.argument('keyvault_secret_name', help="Key vault secret name where certificate is stored.")
c.argument('keyvault_secret_version', help="Key vault secret version where certificate is stored. If empty, will use latest version.")
28 changes: 27 additions & 1 deletion src/azure-cli/azure/cli/command_modules/signalr/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from azure.cli.core.util import empty_on_404

from ._client_factory import (
cf_signalr)
cf_signalr,
cf_custom_domains,
cf_custom_certificates)


def load_command_table(self, _):
Expand Down Expand Up @@ -43,6 +45,16 @@ def load_command_table(self, _):
client_factory=cf_signalr
)

signalr_custom_domain_utils = CliCommandType(
operations_tmpl='azure.cli.command_modules.signalr.customdomain#{}',
client_factory=cf_custom_domains
)

signalr_custom_certificate_utils = CliCommandType(
operations_tmpl='azure.cli.command_modules.signalr.customcertificate#{}',
client_factory=cf_custom_certificates
)

with self.command_group('signalr', signalr_custom_utils) as g:
g.command('create', 'signalr_create')
g.command('delete', 'signalr_delete')
Expand Down Expand Up @@ -76,3 +88,17 @@ def load_command_table(self, _):
g.command('assign', 'signalr_msi_assign')
g.command('remove', 'signalr_msi_remove')
g.show_command('show', 'signalr_msi_show')

with self.command_group('signalr custom-domain', signalr_custom_domain_utils) as g:
g.show_command('show', 'custom_domain_show', exception_handler=empty_on_404)
g.command('create', 'custom_domain_create')
g.command('delete', 'custom_domain_delete')
g.generic_update_command('update', getter_name='get_custom_domain', setter_name='set_custom_domain', custom_func_name='update', custom_func_type=signalr_custom_domain_utils)
g.command('list', 'custom_domain_list')

with self.command_group('signalr custom-certificate', signalr_custom_certificate_utils) as g:
g.show_command('show', 'custom_certificate_show', exception_handler=empty_on_404)
g.command('create', 'custom_certificate_create')
g.command('delete', 'custom_certificate_delete')
g.generic_update_command('update', getter_name='get_custom_certificate', setter_name='set_custom_certificate', custom_func_name='update', custom_func_type=signalr_custom_certificate_utils)
g.command('list', 'custom_certificate_list')
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# --------------------------------------------------------------------------------------------
# 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 (
CustomCertificate
)

from azure.mgmt.signalr._signal_rmanagement_client import (
SignalRCustomCertificatesOperations
)


def custom_certificate_create(client: SignalRCustomCertificatesOperations, resource_group_name, signalr_name, name, keyvault_base_uri, keyvault_secret_name, keyvault_secret_version=None):
custom_certificate = CustomCertificate(key_vault_base_uri=keyvault_base_uri, key_vault_secret_name=keyvault_secret_name, keyvault_secret_version=keyvault_secret_version)

return client.begin_create_or_update(resource_group_name, signalr_name, name, custom_certificate)


def custom_certificate_delete(client: SignalRCustomCertificatesOperations, resource_group_name, signalr_name, name):
return client.delete(resource_group_name, signalr_name, name)


def custom_certificate_show(client: SignalRCustomCertificatesOperations, resource_group_name, signalr_name, name):
return client.get(resource_group_name, signalr_name, name)


def custom_certificate_list(client: SignalRCustomCertificatesOperations, resource_group_name, signalr_name):
return client.list(resource_group_name, signalr_name)


def get_custom_certificate(client: SignalRCustomCertificatesOperations, resource_group_name, signalr_name, name):
return client.get(resource_group_name, signalr_name, name)


def set_custom_certificate(client: SignalRCustomCertificatesOperations, resource_group_name, signalr_name, name, parameters):
return client.begin_create_or_update(resource_group_name, signalr_name, name, parameters)


def update(instance: CustomCertificate, keyvault_base_uri=None, keyvault_secret_name=None, keyvault_secret_version=None):
if keyvault_base_uri is not None:
instance.key_vault_base_uri = keyvault_base_uri
if keyvault_secret_name is not None:
instance.key_vault_secret_name = keyvault_secret_name
if keyvault_secret_version is not None:
instance.key_vault_secret_version = keyvault_secret_version
return instance
50 changes: 50 additions & 0 deletions src/azure-cli/azure/cli/command_modules/signalr/customdomain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# --------------------------------------------------------------------------------------------
# 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 (
CustomDomain,
ResourceReference
)

from azure.mgmt.signalr._signal_rmanagement_client import (
SignalRCustomDomainsOperations
)


def custom_domain_create(client: SignalRCustomDomainsOperations, resource_group_name, signalr_name, name, domain_name, certificate_resource_id):
resource_reference = ResourceReference(id=certificate_resource_id)
custom_domain = CustomDomain(domain_name=domain_name, custom_certificate=resource_reference)

return client.begin_create_or_update(resource_group_name, signalr_name, name, custom_domain)


def custom_domain_delete(client: SignalRCustomDomainsOperations, resource_group_name, signalr_name, name):
return client.begin_delete(resource_group_name, signalr_name, name)


def custom_domain_show(client: SignalRCustomDomainsOperations, resource_group_name, signalr_name, name):
return client.get(resource_group_name, signalr_name, name)


def custom_domain_list(client: SignalRCustomDomainsOperations, resource_group_name, signalr_name):
return client.list(resource_group_name, signalr_name)


def get_custom_domain(client: SignalRCustomDomainsOperations, resource_group_name, signalr_name, name):
return client.get(resource_group_name, signalr_name, name)


def set_custom_domain(client: SignalRCustomDomainsOperations, resource_group_name, signalr_name, name, parameters):
return client.begin_create_or_update(resource_group_name, signalr_name, name, parameters)


def update(instance: CustomDomain, domain_name=None, certificate_resource_id=None):
if domain_name is not None:
instance.domain_name = domain_name
if certificate_resource_id is not None:
instance.custom_certificate = ResourceReference(id=certificate_resource_id)
return instance
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
signalr custom-certificate create:
parameters:
keyvault_secret_version:
rule_exclusions:
- option_length_too_long
signalr custom-certificate update:
parameters:
keyvault_secret_version:
rule_exclusions:
- option_length_too_long
signalr custom-domain create:
parameters:
certificate_resource_id:
rule_exclusions:
- option_length_too_long
signalr custom-domain update:
parameters:
certificate_resource_id:
rule_exclusions:
- option_length_too_long
...
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/signalr/msi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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)
identity = ManagedIdentity(type=msiType, user_assigned_identities={user_identity: {}} if user_identity else None)
parameter = SignalRResource(identity=identity)
return client.begin_update(resource_group_name, signalr_name, parameter)

Expand Down
Loading