Skip to content
Open
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 @@ -18,3 +18,23 @@ def cf_communication_cl(cli_ctx, *_):

def cf_communication_service(cli_ctx, *_):
return cf_communication_cl(cli_ctx).communication_service


def cf_communication_sms(cli_ctx, *_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azext_communication.vendored_sdks.sms import SmsClient
return get_mgmt_service_client(cli_ctx, SmsClient)


def cf_communication_identity(cli_ctx, *_):

from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azext_communication.vendored_sdks.identity import CommunicationIdentityClient
return get_mgmt_service_client(cli_ctx, CommunicationIdentityClient)


def cf_communication_phonenumbers(cli_ctx, *_):

from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azext_communication.vendored_sdks.phonenumbers import PhoneNumbersClient
return get_mgmt_service_client(cli_ctx, PhoneNumbersClient)
46 changes: 46 additions & 0 deletions src/communication/azext_communication/generated/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,49 @@
text: |-
az communication wait --name "MyCommunicationResource" --resource-group "MyResourceGroup" --deleted
"""

helps['communication send-sms'] = """
type: command
short-summary: "Sends SMS to phone numbers."
examples:
- name: send sms
text: |-
az communication send-sms --connection-string \
"Endpoint=sb://MyNamespace.servicebus.windows.net/;SharedAccessKey=abcd1234" \
--sender "+155555555555" --recipient "+155555555666" --message "This is an SMS"
"""


helps['communication create-useraccesstoken'] = """
type: command
short-summary: "Creates user access token"
examples:
- name: create user access token
text: |-
az communication create-useraccesstoken --connection-string \
"Endpoint=sb://MyNamespace.servicebus.windows.net/;SharedAccessKey=abcd1234" \
--scope "Scope for access token. Ex: voip"
"""


helps['communication list-phonenumbers'] = """
type: command
short-summary: "Lists communication phone numbers"
examples:
- name: list phone numbers
text: |-
az communication list-phonenumbers --connection-string \
"Endpoint=sb://MyNamespace.servicebus.windows.net/;SharedAccessKey=abcd1234"
"""


helps['communication show-phonenumber-info'] = """
type: command
short-summary: "Shows communication phonenumber information"
examples:
- name: show phonenumber info
text: |-
az communication show-phonenumber-info --connection-string \
"Endpoint=sb://MyNamespace.servicebus.windows.net/;SharedAccessKey=abcd1234" \
--phone-number "+155555555555"
"""
22 changes: 22 additions & 0 deletions src/communication/azext_communication/generated/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
get_location_type
)
from azure.cli.core.commands.validators import get_default_location_from_resource_group
from knack.arguments import CLIArgumentType


def load_arguments(self, _):

country_code_type = CLIArgumentType(
options_list='--country-code-name',
help='Name of the Communicationphonenumbers.',
id_part='name')

with self.argument_context('communication list') as c:
c.argument('resource_group_name', resource_group_name_type)

Expand Down Expand Up @@ -77,3 +83,19 @@ def load_arguments(self, _):
c.argument('resource_group_name', resource_group_name_type)
c.argument('name', options_list=['--name', '-n'], type=str, help='The name of the CommunicationService '
'resource.', id_part='name')

with self.argument_context('communication send-sms') as c:
c.argument('connection-string', type=str, help='connection string')
c.argument('sender', type=str, help='The sender of the SMS')
c.argument('recipient', type=str, help='The recipient of the SMS')
c.argument('message', type=str, help='The message in the SMS')

with self.argument_context('communication create-useraccesstoken') as c:
c.argument('connection-string', type=str, help = 'connection string')
c.argument('scope', type=str, help = 'scope for an access token chat/voip')

with self.argument_context('communication list-phonenumbers') as c:
c.argument('country_code', country_code_type, id_part=None)

with self.argument_context('communication show-phonenumber-info') as c:
c.argument('country_code', country_code_type, id_part=None)
40 changes: 40 additions & 0 deletions src/communication/azext_communication/generated/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,43 @@ def load_command_table(self, _):
g.custom_command('list-key', 'communication_list_key')
g.custom_command('regenerate-key', 'communication_regenerate_key')
g.custom_wait_command('wait', 'communication_show')


from azext_communication.generated._client_factory import cf_communication_sms
communication_sms_sdk = CliCommandType(
operations_tmpl='azext_communication.vendored_sdks.sms._generated.operations._sms_operations#SmsOperations.{}',
client_factory=cf_communication_sms)

with self.command_group(
'communication',
communication_sms_sdk,
client_factory=cf_communication_sms,
is_preview=True) as g:
g.custom_command('send-sms', 'communication_send_sms')


from azext_communication.generated._client_factory import cf_communication_identity
communication_identity_sdk = CliCommandType(
operations_tmpl='azext_communication.vendored_sdks.identity._generated.operations.'
'_communication_identity_operations#CommunicationIdentityOperations.{}',
client_factory=cf_communication_identity)

with self.command_group(
'communication',
communication_identity_sdk,
client_factory=cf_communication_identity) as g:
g.custom_command('create-useraccesstoken', 'communication_create_useraccesstoken')


from azext_communication.generated._client_factory import cf_communication_phonenumbers
communication_phonenumbers_sdk = CliCommandType(
operations_tmpl='azext_communication.vendored_sdks.phonenumbers._generated.operations'
'#PhoneNumbersOperations.{}',
client_factory=cf_communication_phonenumbers)

with self.command_group(
'communication',
communication_phonenumbers_sdk,
client_factory=cf_communication_phonenumbers) as g:
g.custom_command('list-phonenumbers', 'communication_list_phonenumbers')
g.custom_show_command('show-phonenumber-info', 'communication_show_phonenumber_info')
30 changes: 30 additions & 0 deletions src/communication/azext_communication/generated/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# pylint: disable=too-many-lines

from azure.cli.core.util import sdk_no_wait
from knack.util import CLIError
from azext_communication.vendored_sdks.identity._generated.models import CommunicationTokenScope


def communication_list(client,
Expand Down Expand Up @@ -98,3 +100,31 @@ def communication_regenerate_key(client,
return client.regenerate_key(resource_group_name=resource_group_name,
communication_service_name=name,
parameters=parameters)


def communication_send_sms(client, connection_string, sender, recipient, message):
sms_client=client.from_connection_string(connection_string)
return sms_client.send(from_=sender, to=recipient, message=message)


def communication_create_useraccesstoken(client, connection_string, scope):
communication_client = client.from_connection_string(conn_str=connection_string)
if scope == CommunicationTokenScope.CHAT:
scopes = [CommunicationTokenScope.CHAT]
elif scope == CommunicationTokenScope.VOIP:
scopes = [CommunicationTokenScope.VOIP]
else:
raise CLIError('select scope as chat/voip')

user = communication_client.create_user()
return communication_client.get_token(user, scopes)


def communication_list_phonenumbers(client, connection_string):
phone_client = client.from_connection_string(connection_string)
return phone_client.list_purchased_phone_numbers()


def communication_show_phonenumber_info(client, connection_string, phone_number):
phone_client = client.from_connection_string(connection_string)
return phone_client.get_purchased_phone_number(phone_number)
46 changes: 46 additions & 0 deletions src/communication/azext_communication/manual/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,49 @@
text: |-
az communication wait --name "MyCommunicationResource" --resource-group "MyResourceGroup" --deleted
"""

helps['communication send-sms'] = """
type: command
short-summary: "Sends SMS to phone numbers."
examples:
- name: send sms
text: |-
az communication send-sms --connection-string \
"Endpoint=sb://MyNamespace.servicebus.windows.net/;SharedAccessKey=abcd1234" \
--sender "+155555555555" --recipient "+155555555666" --message "This is an SMS"
"""


helps['communication create-useraccesstoken'] = """
type: command
short-summary: "Creates user access token"
examples:
- name: create user access token
text: |-
az communication create-useraccesstoken --connection-string \
"Endpoint=sb://MyNamespace.servicebus.windows.net/;SharedAccessKey=abcd1234" \
--scope "Scope for access token. Ex: voip"
"""


helps['communication list-phonenumbers'] = """
type: command
short-summary: "Lists communication phone numbers"
examples:
- name: list phone numbers
text: |-
az communication list-phonenumbers --connection-string \
"Endpoint=sb://MyNamespace.servicebus.windows.net/;SharedAccessKey=abcd1234"
"""


helps['communication show-phonenumber-info'] = """
type: command
short-summary: "Shows communication phonenumber information"
examples:
- name: show phonenumber info
text: |-
az communication show-phonenumber-info --connection-string \
"Endpoint=sb://MyNamespace.servicebus.windows.net/;SharedAccessKey=abcd1234" \
--phone-number "+155555555555"
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

from ._communication_identity_client import CommunicationIdentityClient

from ._generated.models import (
CommunicationTokenScope
)

from ._shared.models import (
CommunicationIdentifier,
CommunicationIdentifierKind,
CommunicationUserIdentifier,
CommunicationUserProperties
)

__all__ = [
'CommunicationIdentityClient',

# from _identity
'CommunicationTokenScope',

# from _shared
'CommunicationIdentifier',
'CommunicationIdentifierKind',
'CommunicationUserIdentifier',
'CommunicationUserProperties'
]
Loading