def createBot(self): location = 'global' sku_name = 'Free' kind = 'Bot' display_name = "this is a test bot" description = "this is a description for a test bot" endpoint = "https://bing.com/messages/" msa_app_id = "056d9ad9-17a9-4cc7-aebb-43bf6f293a08" developer_app_insight_key = '59513bad-10a7-4d41-b4d0-b1c34c6af511' developer_app_insights_api_key = 'w24iw5ocbhcig71su7ibaj63hey5ieaozeuwdv11' developer_app_insights_application_id = 'cf03484e-3fdb-4b5e-9ad7-94bde32e5a19' bot = self.client.bots.create( resource_group_name=self.resource_group_name, resource_name=self.resource_name, parameters=Bot( location=location, sku=sku.Sku(name=sku_name), kind=kind, properties=BotProperties( display_name=display_name, description=description, endpoint=endpoint, msa_app_id=msa_app_id, developer_app_insight_key=developer_app_insight_key, developer_app_insights_api_key= developer_app_insights_api_key, developer_app_insights_application_id= developer_app_insights_application_id, )))
def createBot(self): location = 'global' sku_name = 'Free' kind = 'Bot' display_name = "this is a test bot" description = "this is a description for a test bot" endpoint = "https://bing.com/messages/" msa_app_id = "" developer_app_insight_key = '' developer_app_insights_api_key = '' developer_app_insights_application_id = '' bot = self.client.bots.create( resource_group_name=self.resource_group_name, resource_name=self.resource_name, parameters=Bot( location=location, sku=sku.Sku(name=sku_name), kind=kind, properties=BotProperties( display_name=display_name, description=description, endpoint=endpoint, msa_app_id=msa_app_id, developer_app_insight_key=developer_app_insight_key, developer_app_insights_api_key= developer_app_insights_api_key, developer_app_insights_application_id= developer_app_insights_application_id, )))
def create(cmd, client, resource_group_name, resource_name, kind, description=None, display_name=None, endpoint=None, msa_app_id=None, password=None, tags=None, storageAccountName=None, location='Central US', sku_name='F0', appInsightsLocation='South Central US', language='Csharp', version='v3'): display_name = display_name or resource_name kind = kind.lower() if not msa_app_id: msa_app_id, password = provisionConvergedApp(resource_name) logger.warning( 'obtained msa app id and password. Provisioning bot now.') if kind == 'registration': kind = 'bot' if not endpoint or not msa_app_id: raise CLIError( 'Endpoint and msa app id are required for creating a registration bot' ) parameters = Bot(location='global', sku=Sku(name=sku_name), kind=kind, tags=tags, properties=BotProperties(display_name=display_name, description=description, endpoint=endpoint, msa_app_id=msa_app_id)) return client.bots.create(resource_group_name=resource_group_name, resource_name=resource_name, parameters=parameters) if kind in ('webapp', 'function'): return create_app(cmd, client, resource_group_name, resource_name, description, kind, msa_app_id, password, storageAccountName, location, sku_name, appInsightsLocation, language, version) else: raise CLIError('Invalid Bot Parameter : Kind')
def test_bot_operations(self, resource_group): self.resource_group_name = resource_group.name bot = self.client.bots.create( resource_group_name = self.resource_group_name, resource_name = self.resource_name, parameters = Bot( location= self.location, sku = sku.Sku(name=self.sku_name), kind= self.kind, properties= BotProperties( display_name = self.display_name, description= self.description, endpoint = self.endpoint, msa_app_id = self.msa_app_id, developer_app_insight_key = self.developer_app_insight_key, developer_app_insights_api_key = self.developer_app_insights_api_key, developer_app_insights_application_id = self.developer_app_insights_application_id, ) ) ) self.validate_bot_properties(bot) bot = self.client.bots.get( resource_group_name = self.resource_group_name, resource_name = self.resource_name, ) self.validate_bot_properties(bot) bot.properties.description = 'this is another description' self.description = bot.properties.description bot = self.client.bots.update( resource_group_name = self.resource_group_name, resource_name = self.resource_name, properties = bot.properties ) self.validate_bot_properties(bot) bot = self.client.bots.delete( resource_group_name = self.resource_group_name, resource_name = self.resource_name, ) #ensure that the bot was not found with a get with self.assertRaises(ErrorException): bot = self.client.bots.get( resource_group_name = self.resource_group_name, resource_name = self.resource_name )
def create( cmd, client, resource_group_name, resource_name, kind, msa_app_id, password, language=None, # pylint: disable=too-many-locals, too-many-statements description=None, display_name=None, endpoint=None, tags=None, storageAccountName=None, location='Central US', sku_name='F0', appInsightsLocation=None, version='v4', deploy_echo=None): # Kind parameter validation kind = kind.lower() registration_kind = 'registration' bot_kind = 'bot' webapp_kind = 'webapp' function_kind = 'function' if resource_name.find(".") > -1: logger.warning( '"." found in --name parameter ("%s"). "." is an invalid character for Azure Bot resource names ' 'and will been removed.', resource_name) # Remove or replace invalid "." character resource_name = resource_name.replace(".", "") try: app_id_uuid = UUID(msa_app_id, version=4).hex if not msa_app_id.replace('-', '') == app_id_uuid: raise ValueError('Invalid MSA App ID detected.') except Exception as e: logger.debug(e) raise CLIError( "--appid must be a valid GUID from a Microsoft Azure AD Application Registration. See " "https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app for " "more information on App Registrations. See 'az bot create --help' for more CLI information." ) if not password: raise CLIError( "--password cannot have a length of 0. This value is used to authorize calls to your bot. See " "'az bot create --help'.`") # If display name was not provided, just use the resource name display_name = display_name or resource_name # Mapping: registration is deprecated, we now use 'bot' kind for registration bots if kind == registration_kind: kind = bot_kind logger.info('Creating Azure Bot Service.') # Registration bots: simply call ARM and create the bot if kind == bot_kind: logger.info( 'Detected kind %s, validating parameters for the specified kind.', kind) # Registration bot specific validation if not endpoint: endpoint = '' parameters = Bot(location='global', sku=Sku(name=sku_name), kind=kind, tags=tags, properties=BotProperties(display_name=display_name, description=description, endpoint=endpoint, msa_app_id=msa_app_id)) logger.info('Bot parameters client side validation successful.') logger.info('Creating bot.') return client.bots.create(resource_group_name=resource_group_name, resource_name=resource_name, parameters=parameters) # Web app and function bots require deploying custom ARM templates, we do that in a separate method else: logger.info( 'Detected kind %s, validating parameters for the specified kind.', kind) if not language: raise CLIError( "You must pass in a language when creating a {0} or {1} bot. See 'az bot create --help'." .format(webapp_kind, function_kind)) bot_template_type = __bot_template_validator(version, deploy_echo) if version == 'v4': if storageAccountName: logger.warning( 'WARNING: `az bot create` for v4 bots no longer creates or uses a Storage Account. If ' 'you wish to create a Storage Account via Azure CLI, please use `az storage account` or ' 'an ARM template.') if appInsightsLocation: logger.warning( 'WARNING: `az bot create` for v4 bots no longer creates or uses Application Insights. If ' 'you wish to create Application Insights via Azure CLI, please use an ARM template.' ) storageAccountName = None appInsightsLocation = None if version == 'v3' and not appInsightsLocation: appInsightsLocation = 'South Central US' creation_results = BotTemplateDeployer.create_app( cmd, logger, client, resource_group_name, resource_name, description, kind, msa_app_id, password, storageAccountName, location, sku_name, appInsightsLocation, language, version, bot_template_type) subscription_id = get_subscription_id(cmd.cli_ctx) publish_cmd = "az bot publish --resource-group %s -n %s --subscription %s -v %s" % ( resource_group_name, resource_name, subscription_id, version) if language == 'Csharp': proj_file = '%s.csproj' % resource_name publish_cmd += " --proj-file-path %s" % proj_file creation_results['publishCommand'] = publish_cmd logger.info( 'To publish your local changes to Azure, use the following command from your code directory:\n %s', publish_cmd) return creation_results
def create(cmd, client, resource_group_name, resource_name, kind, description=None, display_name=None, endpoint=None, msa_app_id=None, password=None, tags=None, storageAccountName=None, location='Central US', sku_name='F0', appInsightsLocation='South Central US', language='Csharp', version='v3'): """Create a WebApp, Function, or Channels Registration Bot on Azure. This method is directly called via "bot create" :param cmd: :param client: :param resource_group_name: :param resource_name: :param kind: :param description: :param display_name: :param endpoint: :param msa_app_id: :param password: :param tags: :param storageAccountName: :param location: :param sku_name: :param appInsightsLocation: :param language: :param version: :return: """ # If display name was not provided, just use the resource name display_name = display_name or resource_name # Kind parameter validation kind = kind.lower() registration_kind = 'registration' bot_kind = 'bot' webapp_kind = 'webapp' function_kind = 'function' # Mapping: registration is deprecated, we now use 'bot' kind for registration bots if kind == registration_kind: kind = bot_kind if kind not in (bot_kind, webapp_kind, function_kind): raise CLIError('Invalid Bot Parameter : kind. Valid kinds are \'registration\' for registration bots, ' '\'webapp\' for webapp bots and \'function\' for function bots. Run \'az bot create -h\' ' 'for more information.') # If a Microsoft application id was not provided, provision one for the user if not msa_app_id: logger.info('Microsoft application id not passed as a parameter. Provisioning a new Microsoft application.') msa_app_id, password = ConvergedApp.provision(resource_name) logger.info('Microsoft application provisioning successful. Application Id: %s.', msa_app_id) logger.info('Creating Azure Bot Service.') # Registration bots: simply call ARM and create the bot if kind == bot_kind: logger.info('Detected kind %s, validating parameters for the specified kind.', kind) # Registration bot specific validation if not endpoint: raise CLIError('Endpoint is required for creating a registration bot.') if not msa_app_id: raise CLIError('Microsoft application id is required for creating a registration bot.') parameters = Bot( location='global', sku=Sku(name=sku_name), kind=kind, tags=tags, properties=BotProperties( display_name=display_name, description=description, endpoint=endpoint, msa_app_id=msa_app_id ) ) logger.info('Bot parameters client side validation successful.') logger.info('Creating bot.') return client.bots.create( resource_group_name=resource_group_name, resource_name=resource_name, parameters=parameters ) # Web app and function bots require deploying custom ARM templates, we do that in a separate method else: logger.info('Detected kind %s, validating parameters for the specified kind.', kind) return BotTemplateDeployer.create_app(cmd, logger, client, resource_group_name, resource_name, description, kind, msa_app_id, password, storageAccountName, location, sku_name, appInsightsLocation, language, version)
def create( cmd, client, resource_group_name, resource_name, kind, description=None, display_name=None, # pylint: disable=too-many-locals endpoint=None, msa_app_id=None, password=None, tags=None, storageAccountName=None, location='Central US', sku_name='F0', appInsightsLocation='South Central US', language='Csharp', version='v3'): """Create a WebApp, Function, or Channels Registration Bot on Azure. This method is directly called via "bot create" :param cmd: :param client: :param resource_group_name: :param resource_name: :param kind: :param description: :param display_name: :param endpoint: :param msa_app_id: :param password: :param tags: :param storageAccountName: :param location: :param sku_name: :param appInsightsLocation: :param language: :param version: :return: """ # Kind parameter validation kind = kind.lower() registration_kind = 'registration' bot_kind = 'bot' webapp_kind = 'webapp' function_kind = 'function' if resource_name.find(".") > -1: logger.warning( '"." found in --name parameter ("%s"). "." is an invalid character for Azure Bot resource names ' 'and will been removed.', resource_name) # Remove or replace invalid "." character resource_name = resource_name.replace(".", "") # If display name was not provided, just use the resource name display_name = display_name or resource_name # Mapping: registration is deprecated, we now use 'bot' kind for registration bots if kind == registration_kind: kind = bot_kind if kind not in (bot_kind, webapp_kind, function_kind): raise CLIError( 'Invalid Bot Parameter : kind. Valid kinds are \'registration\' for registration bots, ' '\'webapp\' for webapp bots and \'function\' for function bots. Run \'az bot create -h\' ' 'for more information.') # If a Microsoft application id was not provided, provision one for the user if not msa_app_id: logger.info( 'Microsoft application id not passed as a parameter. Provisioning a new Microsoft application.' ) msa_app_id, password = ConvergedApp.provision(resource_name) logger.info( 'Microsoft application provisioning successful. Application Id: %s.', msa_app_id) logger.info('Creating Azure Bot Service.') # Registration bots: simply call ARM and create the bot if kind == bot_kind: logger.info( 'Detected kind %s, validating parameters for the specified kind.', kind) # Registration bot specific validation if not endpoint: raise CLIError( 'Endpoint is required for creating a registration bot.') if not msa_app_id: raise CLIError( 'Microsoft application id is required for creating a registration bot.' ) parameters = Bot(location='global', sku=Sku(name=sku_name), kind=kind, tags=tags, properties=BotProperties(display_name=display_name, description=description, endpoint=endpoint, msa_app_id=msa_app_id)) logger.info('Bot parameters client side validation successful.') logger.info('Creating bot.') return client.bots.create(resource_group_name=resource_group_name, resource_name=resource_name, parameters=parameters) # Web app and function bots require deploying custom ARM templates, we do that in a separate method else: logger.info( 'Detected kind %s, validating parameters for the specified kind.', kind) creation_results = BotTemplateDeployer.create_app( cmd, logger, client, resource_group_name, resource_name, description, kind, msa_app_id, password, storageAccountName, location, sku_name, appInsightsLocation, language, version) subscription_id = get_subscription_id(cmd.cli_ctx) publish_cmd = "az bot publish --resource-group %s -n '%s' --subscription %s -v %s" % ( resource_group_name, resource_name, subscription_id, version) if language == 'Csharp': proj_file = '%s.csproj' % resource_name publish_cmd += " --proj-file-path '%s'" % proj_file creation_results['publishCommand'] = publish_cmd logger.info( 'To publish your local changes to Azure, use the following command from your code directory:\n %s', publish_cmd) return creation_results
def create( cmd, client, resource_group_name, resource_name, kind, msa_app_id, password=None, language=None, # pylint: disable=too-many-locals, too-many-statements, inconsistent-return-statements description=None, display_name=None, endpoint=None, tags=None, location='Central US', sku_name='F0', deploy_echo=None): # Kind parameter validation kind = kind.lower() registration_kind = 'registration' bot_kind = 'bot' webapp_kind = 'webapp' # Mapping: registration is deprecated, we now use 'bot' kind for registration bots if kind == registration_kind: kind = bot_kind # Check the resource name availability for the bot. name_response = NameAvailability.check_name_availability( client, resource_name, kind) if not name_response.valid: # If the name is unavailable, gracefully exit and log the reason for the user. raise CLIError( 'Unable to create a bot with a name of "{0}".\nReason: {1}'.format( resource_name, name_response.message)) if resource_name.find(".") > -1: logger.warning( '"." found in --name parameter ("%s"). "." is an invalid character for Azure Bot resource names ' 'and will been removed.', resource_name) # Remove or replace invalid "." character resource_name = resource_name.replace(".", "") try: app_id_uuid = UUID(msa_app_id, version=4).hex if not msa_app_id.replace('-', '') == app_id_uuid: raise ValueError('Invalid MSA App ID detected.') except Exception as e: logger.debug(e) raise CLIError( "--appid must be a valid GUID from a Microsoft Azure AD Application Registration. See " "https://docs.microsoft.com/azure/active-directory/develop/quickstart-register-app for " "more information on App Registrations. See 'az bot create --help' for more CLI information." ) # If display name was not provided, just use the resource name display_name = display_name or resource_name logger.info('Creating Azure Bot Service.') # Registration bots: simply call ARM and create the bot if kind == bot_kind: logger.info( 'Detected kind %s, validating parameters for the specified kind.', kind) # Registration bot specific validation if not endpoint: endpoint = '' parameters = Bot(location='global', sku=Sku(name=sku_name), kind=kind, tags=tags, properties=BotProperties(display_name=display_name, description=description, endpoint=endpoint, msa_app_id=msa_app_id)) logger.info('Bot parameters client side validation successful.') logger.info('Creating bot.') return client.bots.create(resource_group_name=resource_group_name, resource_name=resource_name, parameters=parameters) if not password: raise CLIError( "--password cannot have a length of 0 for Web App Bots. This value is used to authorize calls " "to your bot. See 'az bot create --help'.") # Web app bots require deploying custom ARM templates, we do that in a separate method logger.info( 'Detected kind %s, validating parameters for the specified kind.', kind) if not language: raise CLIError( "You must pass in a language when creating a {0} bot. See 'az bot create --help'." .format(webapp_kind)) language = language.lower() bot_template_type = __bot_template_validator(deploy_echo) creation_results = BotTemplateDeployer.create_app( cmd, logger, client, resource_group_name, resource_name, description, kind, msa_app_id, password, location, sku_name, language, bot_template_type) return creation_results