def create_connection(client, resource_group_name, resource_name, connection_name, client_id, client_secret, scopes, service_provider_name, parameters=None): from azure.mgmt.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 create_connection(client, resource_group_name, resource_name, connection_name, client_id, client_secret, scopes, service_provider_name, parameters=None): """Create a custom OAuth service provider. This method is directly called via "bot authsetting create" :param client: :param resource_group_name: :param resource_name: :param connection_name: :param client_id: :param client_secret: :param scopes: :param service_provider_name: :param parameters: :return: """ service_provider = get_service_providers(client, name=service_provider_name) if not service_provider: raise CLIError( 'Invalid Service Provider Name passed. Use "az bot authsetting list-providers" ' '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 test_bot_connection_operations(self, resource_group): self.resource_group_name = resource_group.name self.createBot() from azure.mgmt.botservice.models import ConnectionSetting, ConnectionSettingProperties, ConnectionSettingParameter connection_resource_name = self.get_resource_name('myconnection') # create a connection setting_payload = ConnectionSetting( location='global', properties=ConnectionSettingProperties( client_id='clientId', client_secret='clientSecret', scopes='read,write', service_provider_id='00ea67de-bfc6-4f45-9ede-083899596b7b', parameters=[ ConnectionSettingParameter(key='key1', value='value1') ])) setting = self.client.bot_connection.create( resource_group_name=resource_group.name, resource_name=self.resource_name, connection_name=connection_resource_name, parameters=setting_payload) self.assertIsNotNone(setting) self.assertEqual(setting.properties.client_id, 'clientId') # get a connection setting = self.client.bot_connection.get( resource_group_name=resource_group.name, resource_name=self.resource_name, connection_name=connection_resource_name) self.assertIsNotNone(setting) #list all connections settings = self.client.bot_connection.list_by_bot_service( resource_group_name=resource_group.name, resource_name=self.resource_name) self.assertIsNotNone(setting) self.assertTrue(len(list(settings)) == 1) # delete a connection setting = self.client.bot_connection.delete( resource_group_name=resource_group.name, resource_name=self.resource_name, connection_name=connection_resource_name) with self.assertRaises(ErrorException): setting = self.client.bot_connection.get( resource_group_name=resource_group.name, resource_name=self.resource_name, connection_name=connection_resource_name)