diff --git a/src/botservice/azext_bot/_help.py b/src/botservice/azext_bot/_help.py index b39685f5338..0f3caba089b 100644 --- a/src/botservice/azext_bot/_help.py +++ b/src/botservice/azext_bot/_help.py @@ -119,6 +119,43 @@ type: command short-summary: Create Slack Channel on a Bot. """ +helps['bot connection'] = """ + type: group + short-summary: Manage OAuth Connection Settings on a Bot. +""" +helps['bot connection create'] = """ + type: command + short-summary: Create an OAuth Connection Setting on a Bot. + examples: + - name: Create a new OAuth Connection Setting on a Bot. + text: |- + az bot connection create -g MyResourceGroup -n botName -c myConnectionName + --client-id clientId --client-secret secret scopes "scope1 scope2" --service google + --parameters id=myid +""" +helps['bot connection show'] = """ + type: command + short-summary: Show details of an OAuth Connection Setting on a Bot. +""" +helps['bot connection list'] = """ + type: command + short-summary: Show all OAuth Connection Settings on a Bot. +""" +helps['bot connection delete'] = """ + type: command + short-summary: Delete an OAuth Connection Setting on a Bot. +""" +helps['bot connection list-providers'] = """ + type: command + short-summary: List Details of All service Providers available for creating OAuth Connection Settings. + examples: + - name: list all service providers. + text: |- + az bot connection list-providers + - name: Filter by a particular type of service provider. + text: |- + az bot connection list-providers --provider-name google +""" for channel in ['facebook', 'email', 'msteams', 'skype', 'kik', 'webchat', 'directline', 'telegram', 'sms', 'slack']: channelTitle = channel[:1].upper() + channel[1:] diff --git a/src/botservice/azext_bot/_params.py b/src/botservice/azext_bot/_params.py index 79731e803fc..e7dfd3b5328 100644 --- a/src/botservice/azext_bot/_params.py +++ b/src/botservice/azext_bot/_params.py @@ -108,3 +108,17 @@ def load_arguments(self, _): c.argument('client_id', help='The client id from slack') c.argument('verification_token', help='The verification token from slack') c.argument('landing_page_url', help='The landing page url to redirect to after login') + + with self.argument_context('bot connection') as c: + c.argument('connection_name', options_list=['--connection-name', '-c'], help='name of the oauth connection setting') + + with self.argument_context('bot connection create') as c: + c.argument('client_id', help='client id associated with the service provider setting') + c.argument('client_secret', help='client secret associated with the service provider setting') + c.argument('scopes', help='scopes associated with the service provider setting.The format depends on the service provider.') + c.argument('service_provider_name', options_list=['--service'], help='name of the service provider. For a list of all service providers, use az bot connection listserviceproviders') + c.argument('parameters', help='parameter values for Service Provider Parameters. Usage: --parameters key=value key1=value1', nargs='+') + + with self.argument_context('bot connection list-providers') as c: + c.argument('as_raw_settings', options_list=['--as-raw'], help='Output the raw json for each service provider', arg_type=get_three_state_flag()) + c.argument('name', options_list=['--provider-name'], help='service provider name for which to fetch details') diff --git a/src/botservice/azext_bot/botservice/__init__.py b/src/botservice/azext_bot/botservice/__init__.py index 2d20da87551..62afd7a253a 100644 --- a/src/botservice/azext_bot/botservice/__init__.py +++ b/src/botservice/azext_bot/botservice/__init__.py @@ -15,3 +15,4 @@ __all__ = ['AzureBotService'] __version__ = VERSION + diff --git a/src/botservice/azext_bot/botservice/azure_bot_service.py b/src/botservice/azext_bot/botservice/azure_bot_service.py index 3b955a8470e..723f6199f3b 100644 --- a/src/botservice/azext_bot/botservice/azure_bot_service.py +++ b/src/botservice/azext_bot/botservice/azure_bot_service.py @@ -16,6 +16,7 @@ from .operations.bots_operations import BotsOperations from .operations.channels_operations import ChannelsOperations from .operations.operations import Operations +from .operations.bot_connection_operations import BotConnectionOperations from . import models @@ -63,6 +64,8 @@ class AzureBotService(object): :vartype channels: azure.mgmt.botservice.operations.ChannelsOperations :ivar operations: Operations operations :vartype operations: azure.mgmt.botservice.operations.Operations + :ivar bot_connection: BotConnection operations + :vartype bot_connection: azure.mgmt.botservice.operations.BotConnectionOperations :param credentials: Credentials needed for the client to connect to Azure. :type credentials: :mod:`A msrestazure Credentials @@ -89,3 +92,5 @@ def __init__( self._client, self.config, self._serialize, self._deserialize) self.operations = Operations( self._client, self.config, self._serialize, self._deserialize) + self.bot_connection = BotConnectionOperations( + self._client, self.config, self._serialize, self._deserialize) diff --git a/src/botservice/azext_bot/botservice/models/__init__.py b/src/botservice/azext_bot/botservice/models/__init__.py index 52017029217..1fec61eea2d 100644 --- a/src/botservice/azext_bot/botservice/models/__init__.py +++ b/src/botservice/azext_bot/botservice/models/__init__.py @@ -38,6 +38,14 @@ from .sms_channel import SmsChannel from .slack_channel_properties import SlackChannelProperties from .slack_channel import SlackChannel +from .connection_item_name import ConnectionItemName +from .connection_setting_parameter import ConnectionSettingParameter +from .connection_setting_properties import ConnectionSettingProperties +from .connection_setting import ConnectionSetting +from .service_provider_parameter import ServiceProviderParameter +from .service_provider_properties import ServiceProviderProperties +from .service_provider import ServiceProvider +from .service_provider_response_list import ServiceProviderResponseList from .error_body import ErrorBody from .error import Error, ErrorException from .operation_display_info import OperationDisplayInfo @@ -47,6 +55,7 @@ from .bot_paged import BotPaged from .bot_channel_paged import BotChannelPaged from .operation_entity_paged import OperationEntityPaged +from .connection_setting_paged import ConnectionSettingPaged from .azure_bot_service_enums import ( SkuName, SkuTier, @@ -84,6 +93,14 @@ 'SmsChannel', 'SlackChannelProperties', 'SlackChannel', + 'ConnectionItemName', + 'ConnectionSettingParameter', + 'ConnectionSettingProperties', + 'ConnectionSetting', + 'ServiceProviderParameter', + 'ServiceProviderProperties', + 'ServiceProvider', + 'ServiceProviderResponseList', 'ErrorBody', 'Error', 'ErrorException', 'OperationDisplayInfo', @@ -93,6 +110,7 @@ 'BotPaged', 'BotChannelPaged', 'OperationEntityPaged', + 'ConnectionSettingPaged', 'SkuName', 'SkuTier', 'Kind', diff --git a/src/botservice/azext_bot/botservice/models/connection_item_name.py b/src/botservice/azext_bot/botservice/models/connection_item_name.py new file mode 100644 index 00000000000..803f033c31f --- /dev/null +++ b/src/botservice/azext_bot/botservice/models/connection_item_name.py @@ -0,0 +1,34 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class ConnectionItemName(Model): + """The display name of a connection Item Setting registered with the Bot. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar name: Connection Item name that has been added in the API + :vartype name: str + """ + + _validation = { + 'name': {'readonly': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + } + + def __init__(self): + self.name = None diff --git a/src/botservice/azext_bot/botservice/models/connection_setting.py b/src/botservice/azext_bot/botservice/models/connection_setting.py new file mode 100644 index 00000000000..708356434b4 --- /dev/null +++ b/src/botservice/azext_bot/botservice/models/connection_setting.py @@ -0,0 +1,63 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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. +# -------------------------------------------------------------------------- + +from .resource import Resource + + +class ConnectionSetting(Resource): + """Bot channel resource definition. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar id: Specifies the resource ID. + :vartype id: str + :ivar name: Specifies the name of the resource. + :vartype name: str + :param location: Specifies the location of the resource. + :type location: str + :ivar type: Specifies the type of the resource. + :vartype type: str + :param tags: Contains resource tags defined as key/value pairs. + :type tags: dict[str, str] + :param sku: Gets or sets the SKU of the resource. + :type sku: ~azure.mgmt.botservice.models.Sku + :param kind: Required. Gets or sets the Kind of the resource. Possible + values include: 'sdk', 'designer', 'bot', 'function' + :type kind: str or ~azure.mgmt.botservice.models.Kind + :param etag: Entity Tag + :type etag: str + :param properties: The set of properties specific to bot channel resource + :type properties: + ~azure.mgmt.botservice.models.ConnectionSettingProperties + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'location': {'key': 'location', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'sku': {'key': 'sku', 'type': 'Sku'}, + 'kind': {'key': 'kind', 'type': 'str'}, + 'etag': {'key': 'etag', 'type': 'str'}, + 'properties': {'key': 'properties', 'type': 'ConnectionSettingProperties'}, + } + + def __init__(self, location=None, tags=None, sku=None, kind=None, etag=None, properties=None): + super(ConnectionSetting, self).__init__(location=location, tags=tags, sku=sku, kind=kind, etag=etag) + self.properties = properties diff --git a/src/botservice/azext_bot/botservice/models/connection_setting_paged.py b/src/botservice/azext_bot/botservice/models/connection_setting_paged.py new file mode 100644 index 00000000000..5708e4ee7ee --- /dev/null +++ b/src/botservice/azext_bot/botservice/models/connection_setting_paged.py @@ -0,0 +1,27 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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. +# -------------------------------------------------------------------------- + +from msrest.paging import Paged + + +class ConnectionSettingPaged(Paged): + """ + A paging container for iterating over a list of :class:`ConnectionSetting ` object + """ + + _attribute_map = { + 'next_link': {'key': 'nextLink', 'type': 'str'}, + 'current_page': {'key': 'value', 'type': '[ConnectionSetting]'} + } + + def __init__(self, *args, **kwargs): + + super(ConnectionSettingPaged, self).__init__(*args, **kwargs) diff --git a/src/botservice/azext_bot/botservice/models/connection_setting_parameter.py b/src/botservice/azext_bot/botservice/models/connection_setting_parameter.py new file mode 100644 index 00000000000..1185e763020 --- /dev/null +++ b/src/botservice/azext_bot/botservice/models/connection_setting_parameter.py @@ -0,0 +1,32 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class ConnectionSettingParameter(Model): + """Extra Parameter in a Connection Setting Properties to indicate service + provider specific properties. + + :param key: Key for the Connection Setting Parameter. + :type key: str + :param value: Value associated with the Connection Setting Parameter. + :type value: str + """ + + _attribute_map = { + 'key': {'key': 'key', 'type': 'str'}, + 'value': {'key': 'value', 'type': 'str'}, + } + + def __init__(self, key=None, value=None): + self.key = key + self.value = value diff --git a/src/botservice/azext_bot/botservice/models/connection_setting_properties.py b/src/botservice/azext_bot/botservice/models/connection_setting_properties.py new file mode 100644 index 00000000000..505a98492a1 --- /dev/null +++ b/src/botservice/azext_bot/botservice/models/connection_setting_properties.py @@ -0,0 +1,63 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class ConnectionSettingProperties(Model): + """Properties for a Connection Setting Item. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :param client_id: Client Id associated with the Connection Setting. + :type client_id: str + :ivar setting_id: Setting Id set by the service for the Connection + Setting. + :vartype setting_id: str + :param client_secret: Client Secret associated with the Connection Setting + :type client_secret: str + :param scopes: Scopes associated with the Connection Setting + :type scopes: str + :param service_provider_id: Service Provider Id associated with the + Connection Setting + :type service_provider_id: str + :param service_provider_display_name: Service Provider Display Name + associated with the Connection Setting + :type service_provider_display_name: str + :param parameters: Service Provider Parameters associated with the + Connection Setting + :type parameters: + list[~azure.mgmt.botservice.models.ConnectionSettingParameter] + """ + + _validation = { + 'setting_id': {'readonly': True}, + } + + _attribute_map = { + 'client_id': {'key': 'clientId', 'type': 'str'}, + 'setting_id': {'key': 'settingId', 'type': 'str'}, + 'client_secret': {'key': 'clientSecret', 'type': 'str'}, + 'scopes': {'key': 'scopes', 'type': 'str'}, + 'service_provider_id': {'key': 'serviceProviderId', 'type': 'str'}, + 'service_provider_display_name': {'key': 'serviceProviderDisplayName', 'type': 'str'}, + 'parameters': {'key': 'parameters', 'type': '[ConnectionSettingParameter]'}, + } + + def __init__(self, client_id=None, client_secret=None, scopes=None, service_provider_id=None, service_provider_display_name=None, parameters=None): + self.client_id = client_id + self.setting_id = None + self.client_secret = client_secret + self.scopes = scopes + self.service_provider_id = service_provider_id + self.service_provider_display_name = service_provider_display_name + self.parameters = parameters diff --git a/src/botservice/azext_bot/botservice/models/service_provider.py b/src/botservice/azext_bot/botservice/models/service_provider.py new file mode 100644 index 00000000000..7849723e8ee --- /dev/null +++ b/src/botservice/azext_bot/botservice/models/service_provider.py @@ -0,0 +1,27 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class ServiceProvider(Model): + """Service Provider Definition. + + :param properties: The Properties of a Service Provider Object + :type properties: ~azure.mgmt.botservice.models.ServiceProviderProperties + """ + + _attribute_map = { + 'properties': {'key': 'properties', 'type': 'ServiceProviderProperties'}, + } + + def __init__(self, properties=None): + self.properties = properties diff --git a/src/botservice/azext_bot/botservice/models/service_provider_parameter.py b/src/botservice/azext_bot/botservice/models/service_provider_parameter.py new file mode 100644 index 00000000000..d168ca32fa1 --- /dev/null +++ b/src/botservice/azext_bot/botservice/models/service_provider_parameter.py @@ -0,0 +1,59 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class ServiceProviderParameter(Model): + """Extra Parameters specific to each Service Provider. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar name: Name of the Service Provider + :vartype name: str + :ivar type: Type of the Service Provider + :vartype type: str + :ivar display_name: Display Name of the Service Provider + :vartype display_name: str + :ivar description: Description of the Service Provider + :vartype description: str + :ivar help_url: Help Url for the Service Provider + :vartype help_url: str + :ivar default: Default Name for the Service Provider + :vartype default: str + """ + + _validation = { + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'display_name': {'readonly': True}, + 'description': {'readonly': True}, + 'help_url': {'readonly': True}, + 'default': {'readonly': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'display_name': {'key': 'displayName', 'type': 'str'}, + 'description': {'key': 'description', 'type': 'str'}, + 'help_url': {'key': 'helpUrl', 'type': 'str'}, + 'default': {'key': 'default', 'type': 'str'}, + } + + def __init__(self): + self.name = None + self.type = None + self.display_name = None + self.description = None + self.help_url = None + self.default = None diff --git a/src/botservice/azext_bot/botservice/models/service_provider_properties.py b/src/botservice/azext_bot/botservice/models/service_provider_properties.py new file mode 100644 index 00000000000..20b40176836 --- /dev/null +++ b/src/botservice/azext_bot/botservice/models/service_provider_properties.py @@ -0,0 +1,59 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class ServiceProviderProperties(Model): + """The Object used to describe a Service Provider supported by Bot Service. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar id: Id for Service Provider + :vartype id: str + :ivar display_name: Diplay Name of the Service Provider + :vartype display_name: str + :ivar service_provider_name: Diplay Name of the Service Provider + :vartype service_provider_name: str + :ivar dev_portal_url: Diplay Name of the Service Provider + :vartype dev_portal_url: str + :ivar icon_url: Diplay Name of the Service Provider + :vartype icon_url: str + :param parameters: The list of parameters for the Service Provider + :type parameters: + list[~azure.mgmt.botservice.models.ServiceProviderParameter] + """ + + _validation = { + 'id': {'readonly': True}, + 'display_name': {'readonly': True}, + 'service_provider_name': {'readonly': True}, + 'dev_portal_url': {'readonly': True}, + 'icon_url': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'display_name': {'key': 'displayName', 'type': 'str'}, + 'service_provider_name': {'key': 'serviceProviderName', 'type': 'str'}, + 'dev_portal_url': {'key': 'devPortalUrl', 'type': 'str'}, + 'icon_url': {'key': 'iconUrl', 'type': 'str'}, + 'parameters': {'key': 'parameters', 'type': '[ServiceProviderParameter]'}, + } + + def __init__(self, parameters=None): + self.id = None + self.display_name = None + self.service_provider_name = None + self.dev_portal_url = None + self.icon_url = None + self.parameters = parameters diff --git a/src/botservice/azext_bot/botservice/models/service_provider_response_list.py b/src/botservice/azext_bot/botservice/models/service_provider_response_list.py new file mode 100644 index 00000000000..269485a7d38 --- /dev/null +++ b/src/botservice/azext_bot/botservice/models/service_provider_response_list.py @@ -0,0 +1,40 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class ServiceProviderResponseList(Model): + """The list of bot service service providers response. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :param next_link: The link used to get the next page of bot service + service providers. + :type next_link: str + :ivar value: Gets the list of bot service service providers and their + properties. + :vartype value: list[~azure.mgmt.botservice.models.ServiceProvider] + """ + + _validation = { + 'value': {'readonly': True}, + } + + _attribute_map = { + 'next_link': {'key': 'nextLink', 'type': 'str'}, + 'value': {'key': 'value', 'type': '[ServiceProvider]'}, + } + + def __init__(self, next_link=None): + self.next_link = next_link + self.value = None diff --git a/src/botservice/azext_bot/botservice/operations/__init__.py b/src/botservice/azext_bot/botservice/operations/__init__.py index a587b5bcc9f..c52c36afa15 100644 --- a/src/botservice/azext_bot/botservice/operations/__init__.py +++ b/src/botservice/azext_bot/botservice/operations/__init__.py @@ -12,9 +12,11 @@ from .bots_operations import BotsOperations from .channels_operations import ChannelsOperations from .operations import Operations +from .bot_connection_operations import BotConnectionOperations __all__ = [ 'BotsOperations', 'ChannelsOperations', 'Operations', + 'BotConnectionOperations', ] diff --git a/src/botservice/azext_bot/botservice/operations/bot_connection_operations.py b/src/botservice/azext_bot/botservice/operations/bot_connection_operations.py new file mode 100644 index 00000000000..4803a84e8a5 --- /dev/null +++ b/src/botservice/azext_bot/botservice/operations/bot_connection_operations.py @@ -0,0 +1,501 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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. +# -------------------------------------------------------------------------- + +import uuid +from msrest.pipeline import ClientRawResponse + +from .. import models + + +class BotConnectionOperations(object): + """BotConnectionOperations operations. + + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An objec model deserializer. + :ivar api_version: Version of the API to be used with the client request. Current version is 2017-12-01. Constant value: "2017-12-01". + """ + + models = models + + def __init__(self, client, config, serializer, deserializer): + + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self.api_version = "2017-12-01" + + self.config = config + + def list_service_providers( + self, resource_group_name, custom_headers=None, raw=False, **operation_config): + """Lists the available Service Providers for creating Connection Settings. + + :param resource_group_name: The name of the Bot resource group in the + user subscription. + :type resource_group_name: 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 operation_config: :ref:`Operation configuration + overrides`. + :return: ServiceProviderResponseList or ClientRawResponse if raw=true + :rtype: ~azure.mgmt.botservice.models.ServiceProviderResponseList or + ~msrest.pipeline.ClientRawResponse + :raises: + :class:`ErrorException` + """ + # Construct URL + url = '/subscriptions/{subscriptionId}/providers/Microsoft.BotService/listAuthServiceProviders' + path_format_arguments = { + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.post(url, query_parameters) + response = self._client.send(request, header_parameters, **operation_config) + + if response.status_code not in [200]: + raise models.ErrorException(self._deserialize, response) + + deserialized = None + + if response.status_code == 200: + deserialized = self._deserialize('ServiceProviderResponseList', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + + def list_with_secrets( + self, resource_group_name, resource_name, connection_name, custom_headers=None, raw=False, **operation_config): + """Get a Connection Setting registration for a Bot Service. + + :param resource_group_name: The name of the Bot resource group in the + user subscription. + :type resource_group_name: str + :param resource_name: The name of the Bot resource. + :type resource_name: str + :param connection_name: The name of the Bot Service Connection Setting + resource + :type connection_name: 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 operation_config: :ref:`Operation configuration + overrides`. + :return: ConnectionSetting or ClientRawResponse if raw=true + :rtype: ~azure.mgmt.botservice.models.ConnectionSetting or + ~msrest.pipeline.ClientRawResponse + :raises: + :class:`ErrorException` + """ + # Construct URL + url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.BotService/botServices/{resourceName}/Connections/{connectionName}/listWithSecrets' + path_format_arguments = { + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), + 'resourceName': self._serialize.url("resource_name", resource_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), + 'connectionName': self._serialize.url("connection_name", connection_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.post(url, query_parameters) + response = self._client.send(request, header_parameters, **operation_config) + + if response.status_code not in [200]: + raise models.ErrorException(self._deserialize, response) + + deserialized = None + + if response.status_code == 200: + deserialized = self._deserialize('ConnectionSetting', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + + def create( + self, resource_group_name, resource_name, connection_name, parameters, custom_headers=None, raw=False, **operation_config): + """Register a new Auth Connection for a Bot Service. + + :param resource_group_name: The name of the Bot resource group in the + user subscription. + :type resource_group_name: str + :param resource_name: The name of the Bot resource. + :type resource_name: str + :param connection_name: The name of the Bot Service Connection Setting + resource + :type connection_name: str + :param parameters: The parameters to provide for creating the + Connection Setting. + :type parameters: ~azure.mgmt.botservice.models.ConnectionSetting + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :return: ConnectionSetting or ClientRawResponse if raw=true + :rtype: ~azure.mgmt.botservice.models.ConnectionSetting or + ~msrest.pipeline.ClientRawResponse + :raises: + :class:`ErrorException` + """ + # Construct URL + url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.BotService/botServices/{resourceName}/Connections/{connectionName}' + path_format_arguments = { + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), + 'resourceName': self._serialize.url("resource_name", resource_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), + 'connectionName': self._serialize.url("connection_name", connection_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct body + body_content = self._serialize.body(parameters, 'ConnectionSetting') + + # Construct and send request + request = self._client.put(url, query_parameters) + response = self._client.send( + request, header_parameters, body_content, **operation_config) + + if response.status_code not in [200, 201]: + raise models.ErrorException(self._deserialize, response) + + deserialized = None + + if response.status_code == 200: + deserialized = self._deserialize('ConnectionSetting', response) + if response.status_code == 201: + deserialized = self._deserialize('ConnectionSetting', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + + def update( + self, resource_group_name, resource_name, connection_name, parameters, custom_headers=None, raw=False, **operation_config): + """Updates a Connection Setting registration for a Bot Service. + + :param resource_group_name: The name of the Bot resource group in the + user subscription. + :type resource_group_name: str + :param resource_name: The name of the Bot resource. + :type resource_name: str + :param connection_name: The name of the Bot Service Connection Setting + resource + :type connection_name: str + :param parameters: The parameters to provide for updating the + Connection Setting. + :type parameters: ~azure.mgmt.botservice.models.ConnectionSetting + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :return: ConnectionSetting or ClientRawResponse if raw=true + :rtype: ~azure.mgmt.botservice.models.ConnectionSetting or + ~msrest.pipeline.ClientRawResponse + :raises: + :class:`ErrorException` + """ + # Construct URL + url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.BotService/botServices/{resourceName}/Connections/{connectionName}' + path_format_arguments = { + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), + 'resourceName': self._serialize.url("resource_name", resource_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), + 'connectionName': self._serialize.url("connection_name", connection_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct body + body_content = self._serialize.body(parameters, 'ConnectionSetting') + + # Construct and send request + request = self._client.patch(url, query_parameters) + response = self._client.send( + request, header_parameters, body_content, **operation_config) + + if response.status_code not in [200, 201]: + raise models.ErrorException(self._deserialize, response) + + deserialized = None + + if response.status_code == 200: + deserialized = self._deserialize('ConnectionSetting', response) + if response.status_code == 201: + deserialized = self._deserialize('ConnectionSetting', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + + def get( + self, resource_group_name, resource_name, connection_name, custom_headers=None, raw=False, **operation_config): + """Get a Connection Setting registration for a Bot Service. + + :param resource_group_name: The name of the Bot resource group in the + user subscription. + :type resource_group_name: str + :param resource_name: The name of the Bot resource. + :type resource_name: str + :param connection_name: The name of the Bot Service Connection Setting + resource + :type connection_name: 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 operation_config: :ref:`Operation configuration + overrides`. + :return: ConnectionSetting or ClientRawResponse if raw=true + :rtype: ~azure.mgmt.botservice.models.ConnectionSetting or + ~msrest.pipeline.ClientRawResponse + :raises: + :class:`ErrorException` + """ + # Construct URL + url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.BotService/botServices/{resourceName}/Connections/{connectionName}' + path_format_arguments = { + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), + 'resourceName': self._serialize.url("resource_name", resource_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), + 'connectionName': self._serialize.url("connection_name", connection_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.get(url, query_parameters) + response = self._client.send(request, header_parameters, **operation_config) + + if response.status_code not in [200]: + raise models.ErrorException(self._deserialize, response) + + deserialized = None + + if response.status_code == 200: + deserialized = self._deserialize('ConnectionSetting', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + + def delete( + self, resource_group_name, resource_name, connection_name, custom_headers=None, raw=False, **operation_config): + """Deletes a Connection Setting registration for a Bot Service. + + :param resource_group_name: The name of the Bot resource group in the + user subscription. + :type resource_group_name: str + :param resource_name: The name of the Bot resource. + :type resource_name: str + :param connection_name: The name of the Bot Service Connection Setting + resource + :type connection_name: 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 operation_config: :ref:`Operation configuration + overrides`. + :return: None or ClientRawResponse if raw=true + :rtype: None or ~msrest.pipeline.ClientRawResponse + :raises: + :class:`ErrorException` + """ + # Construct URL + url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.BotService/botServices/{resourceName}/Connections/{connectionName}' + path_format_arguments = { + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), + 'resourceName': self._serialize.url("resource_name", resource_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), + 'connectionName': self._serialize.url("connection_name", connection_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.delete(url, query_parameters) + response = self._client.send(request, header_parameters, **operation_config) + + if response.status_code not in [200, 204]: + raise models.ErrorException(self._deserialize, response) + + if raw: + client_raw_response = ClientRawResponse(None, response) + return client_raw_response + + def list_by_bot_service( + self, resource_group_name, resource_name, custom_headers=None, raw=False, **operation_config): + """Returns all the Connection Settings registered to a particular + BotService resource. + + :param resource_group_name: The name of the Bot resource group in the + user subscription. + :type resource_group_name: str + :param resource_name: The name of the Bot resource. + :type resource_name: 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 operation_config: :ref:`Operation configuration + overrides`. + :return: An iterator like instance of ConnectionSetting + :rtype: + ~azure.mgmt.botservice.models.ConnectionSettingPaged[~azure.mgmt.botservice.models.ConnectionSetting] + :raises: + :class:`ErrorException` + """ + def internal_paging(next_link=None, raw=False): + + if not next_link: + # Construct URL + url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.BotService/botServices/{resourceName}/connections' + path_format_arguments = { + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), + 'resourceName': self._serialize.url("resource_name", resource_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + else: + url = next_link + query_parameters = {} + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.get(url, query_parameters) + response = self._client.send( + request, header_parameters, **operation_config) + + if response.status_code not in [200]: + raise models.ErrorException(self._deserialize, response) + + return response + + # Deserialize response + deserialized = models.ConnectionSettingPaged(internal_paging, self._deserialize.dependencies) + + if raw: + header_dict = {} + client_raw_response = models.ConnectionSettingPaged(internal_paging, self._deserialize.dependencies, header_dict) + return client_raw_response + + return deserialized diff --git a/src/botservice/azext_bot/botservice/operations/bots_operations.py b/src/botservice/azext_bot/botservice/operations/bots_operations.py index 6c198db96d6..ed14d253da5 100644 --- a/src/botservice/azext_bot/botservice/operations/bots_operations.py +++ b/src/botservice/azext_bot/botservice/operations/bots_operations.py @@ -41,8 +41,8 @@ def create( """Creates a Bot Service. Bot Service is a resource group wide resource type. - :param resource_group_name: The name of the resource group within the - user's subscription. + :param resource_group_name: The name of the Bot resource group in the + user subscription. :type resource_group_name: str :param resource_name: The name of the Bot resource. :type resource_name: str @@ -62,7 +62,7 @@ def create( # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.BotService/botServices/{resourceName}' path_format_arguments = { - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'resourceName': self._serialize.url("resource_name", resource_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') } @@ -110,8 +110,8 @@ def update( self, resource_group_name, resource_name, location=None, tags=None, sku=None, kind=None, etag=None, properties=None, custom_headers=None, raw=False, **operation_config): """Updates a Bot Service. - :param resource_group_name: The name of the resource group within the - user's subscription. + :param resource_group_name: The name of the Bot resource group in the + user subscription. :type resource_group_name: str :param resource_name: The name of the Bot resource. :type resource_name: str @@ -144,7 +144,7 @@ def update( # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.BotService/botServices/{resourceName}' path_format_arguments = { - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'resourceName': self._serialize.url("resource_name", resource_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') } @@ -192,8 +192,8 @@ def delete( self, resource_group_name, resource_name, custom_headers=None, raw=False, **operation_config): """Deletes a Bot Service from the resource group. . - :param resource_group_name: The name of the resource group within the - user's subscription. + :param resource_group_name: The name of the Bot resource group in the + user subscription. :type resource_group_name: str :param resource_name: The name of the Bot resource. :type resource_name: str @@ -210,7 +210,7 @@ def delete( # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.BotService/botServices/{resourceName}' path_format_arguments = { - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'resourceName': self._serialize.url("resource_name", resource_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') } @@ -245,8 +245,8 @@ def get( self, resource_group_name, resource_name, custom_headers=None, raw=False, **operation_config): """Returns a BotService specified by the parameters. - :param resource_group_name: The name of the resource group within the - user's subscription. + :param resource_group_name: The name of the Bot resource group in the + user subscription. :type resource_group_name: str :param resource_name: The name of the Bot resource. :type resource_name: str @@ -264,7 +264,7 @@ def get( # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.BotService/botServices/{resourceName}' path_format_arguments = { - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'resourceName': self._serialize.url("resource_name", resource_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') } @@ -307,8 +307,8 @@ def list_by_resource_group( """Returns all the resources of a particular type belonging to a resource group. - :param resource_group_name: The name of the resource group within the - user's subscription. + :param resource_group_name: The name of the Bot resource group in the + user subscription. :type resource_group_name: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the @@ -327,7 +327,7 @@ def internal_paging(next_link=None, raw=False): # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.BotService/botServices' path_format_arguments = { - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') } url = self._client.format_url(url, **path_format_arguments) diff --git a/src/botservice/azext_bot/botservice/operations/channels_operations.py b/src/botservice/azext_bot/botservice/operations/channels_operations.py index eada70665df..63a291a2c50 100644 --- a/src/botservice/azext_bot/botservice/operations/channels_operations.py +++ b/src/botservice/azext_bot/botservice/operations/channels_operations.py @@ -40,8 +40,8 @@ def create( self, resource_group_name, resource_name, channel_name, parameters, custom_headers=None, raw=False, **operation_config): """Creates a Channel registration for a Bot Service. - :param resource_group_name: The name of the resource group within the - user's subscription. + :param resource_group_name: The name of the Bot resource group in the + user subscription. :type resource_group_name: str :param resource_name: The name of the Bot resource. :type resource_name: str @@ -66,7 +66,7 @@ def create( # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.BotService/botServices/{resourceName}/channels/{channelName}' path_format_arguments = { - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'resourceName': self._serialize.url("resource_name", resource_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'channelName': self._serialize.url("channel_name", channel_name, 'ChannelName'), 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') @@ -115,8 +115,8 @@ def update( self, resource_group_name, resource_name, channel_name, location=None, tags=None, sku=None, kind=None, etag=None, properties=None, custom_headers=None, raw=False, **operation_config): """Updates a Channel registration for a Bot Service. - :param resource_group_name: The name of the resource group within the - user's subscription. + :param resource_group_name: The name of the Bot resource group in the + user subscription. :type resource_group_name: str :param resource_name: The name of the Bot resource. :type resource_name: str @@ -155,7 +155,7 @@ def update( # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.BotService/botServices/{resourceName}/channels/{channelName}' path_format_arguments = { - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'resourceName': self._serialize.url("resource_name", resource_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'channelName': self._serialize.url("channel_name", channel_name, 'ChannelName'), 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') @@ -204,8 +204,8 @@ def delete( self, resource_group_name, resource_name, channel_name, custom_headers=None, raw=False, **operation_config): """Deletes a Channel registration from a Bot Service. - :param resource_group_name: The name of the resource group within the - user's subscription. + :param resource_group_name: The name of the Bot resource group in the + user subscription. :type resource_group_name: str :param resource_name: The name of the Bot resource. :type resource_name: str @@ -224,7 +224,7 @@ def delete( # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.BotService/botServices/{resourceName}/channels/{channelName}' path_format_arguments = { - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'resourceName': self._serialize.url("resource_name", resource_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'channelName': self._serialize.url("channel_name", channel_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') @@ -260,8 +260,8 @@ def get( self, resource_group_name, resource_name, channel_name, custom_headers=None, raw=False, **operation_config): """Returns a BotService Channel registration specified by the parameters. - :param resource_group_name: The name of the resource group within the - user's subscription. + :param resource_group_name: The name of the Bot resource group in the + user subscription. :type resource_group_name: str :param resource_name: The name of the Bot resource. :type resource_name: str @@ -281,7 +281,7 @@ def get( # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.BotService/botServices/{resourceName}/channels/{channelName}' path_format_arguments = { - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'resourceName': self._serialize.url("resource_name", resource_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'channelName': self._serialize.url("channel_name", channel_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') @@ -324,8 +324,8 @@ def list_with_keys( self, resource_group_name, resource_name, channel_name, custom_headers=None, raw=False, **operation_config): """Lists a Channel registration for a Bot Service including secrets. - :param resource_group_name: The name of the resource group within the - user's subscription. + :param resource_group_name: The name of the Bot resource group in the + user subscription. :type resource_group_name: str :param resource_name: The name of the Bot resource. :type resource_name: str @@ -348,7 +348,7 @@ def list_with_keys( # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.BotService/botServices/{resourceName}/channels/{channelName}/listChannelWithKeys' path_format_arguments = { - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'resourceName': self._serialize.url("resource_name", resource_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'channelName': self._serialize.url("channel_name", channel_name, 'ChannelName'), 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') @@ -392,8 +392,8 @@ def list_by_resource_group( """Returns all the Channel registrations of a particular BotService resource. - :param resource_group_name: The name of the resource group within the - user's subscription. + :param resource_group_name: The name of the Bot resource group in the + user subscription. :type resource_group_name: str :param resource_name: The name of the Bot resource. :type resource_name: str @@ -414,7 +414,7 @@ def internal_paging(next_link=None, raw=False): # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.BotService/botServices/{resourceName}/channels' path_format_arguments = { - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'resourceName': self._serialize.url("resource_name", resource_name, 'str', max_length=64, min_length=2, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_.-]*$'), 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') } diff --git a/src/botservice/azext_bot/botservice/version.py b/src/botservice/azext_bot/botservice/version.py index fb0159ed93d..e0ec669828c 100644 --- a/src/botservice/azext_bot/botservice/version.py +++ b/src/botservice/azext_bot/botservice/version.py @@ -10,3 +10,4 @@ # -------------------------------------------------------------------------- VERSION = "0.1.0" + diff --git a/src/botservice/azext_bot/commands.py b/src/botservice/azext_bot/commands.py index f0c1689c8f2..5717f5e4bb1 100644 --- a/src/botservice/azext_bot/commands.py +++ b/src/botservice/azext_bot/commands.py @@ -37,6 +37,13 @@ def load_command_table(self, _): g.custom_command('delete', 'delete_bot') g.generic_update_command('update', setter_name='update', setter_type=updateBotService_commandType) + with self.command_group('bot connection', botOperations_commandType) as g: + g.custom_command('list', 'get_connections') + g.custom_command('show', 'get_connection') + g.custom_command('create', 'create_connection') + g.custom_command('delete', 'delete_connection') + g.custom_command('list-providers', 'get_service_providers') + for channel in ['facebook', 'email', 'msteams', 'skype', 'kik', 'webchat', 'directline', 'telegram', 'sms', 'slack']: with self.command_group('bot {}'.format(channel), channelOperations_commandType) as g: diff --git a/src/botservice/azext_bot/custom.py b/src/botservice/azext_bot/custom.py index d0a93050f51..7361f27494f 100644 --- a/src/botservice/azext_bot/custom.py +++ b/src/botservice/azext_bot/custom.py @@ -167,6 +167,55 @@ def get_bot(cmd, client, resource_group_name, resource_name, bot_json=None): return raw_bot_properties +def get_connections(client, resource_group_name, resource_name): + return client.bot_connection.list_by_bot_service(resource_group_name, resource_name) + + +def get_connection(client, resource_group_name, resource_name, connection_name): + return client.bot_connection.get(resource_group_name, resource_name, connection_name) + + +def create_connection(client, resource_group_name, resource_name, connection_name, client_id, + client_secret, scopes, service_provider_name, parameters=None): + from azext_bot.botservice.models import ConnectionSetting, ConnectionSettingProperties, ConnectionSettingParameter + service_provider = get_service_providers(client, name=service_provider_name) + if not service_provider: + raise CLIError('Invalid Service Provider Name passed. Use listprovider command to see all available providers') + connection_parameters = [] + if parameters: + for parameter in parameters: + pair = parameter.split('=', 1) + if len(pair) == 1: + raise CLIError('usage error: --parameters STRING=STRING STRING=STRING') + connection_parameters.append(ConnectionSettingParameter(key=pair[0], value=pair[1])) + setting = ConnectionSetting( + location='global', + properties=ConnectionSettingProperties( + client_id=client_id, + client_secret=client_secret, + scopes=scopes, + service_provider_id=service_provider.properties.id, + parameters=connection_parameters + ) + ) + return client.bot_connection.create(resource_group_name, resource_name, connection_name, setting) + + +def delete_connection(client, resource_group_name, resource_name, connection_name): + return client.bot_connection.delete(resource_group_name, resource_name, connection_name) + + +def get_service_providers(client, name=None): + service_provider_response = client.bot_connection.list_service_providers() + name = name and name.lower() + if name: + try: + return next((item for item in service_provider_response.value if item.properties.service_provider_name.lower() == name.lower())) # pylint: disable=line-too-long + except StopIteration: + raise CLIError('A service provider with the name {0} was not found'.format(name)) + return service_provider_response + + def create_app(cmd, client, resource_group_name, resource_name, description, kind, appid, password, storageAccountName, # pylint: disable=inconsistent-return-statements location, sku_name, appInsightsLocation, bot_json, language): if kind == 'function': diff --git a/src/botservice/setup.py b/src/botservice/setup.py index 8421539b277..1c6e81fb4c0 100644 --- a/src/botservice/setup.py +++ b/src/botservice/setup.py @@ -13,7 +13,7 @@ logger.warn("Wheel is not available, disabling bdist_wheel hook") cmdclass = {} -VERSION = "0.0.3" +VERSION = "0.0.4" # The full list of classifiers is available at # https://pypi.python.org/pypi?%3Aaction=list_classifiers CLASSIFIERS = [