Example #1
0
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
Example #2
0
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)
Example #3
0
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