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, 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
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, 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