Exemplo n.º 1
0
    def __initialize(self):
        """Generates necessary data for performing calls to Kudu based off of data passed in on initialization.

        :return: None
        """
        user_name, password = WebAppOperations.get_site_credential(
            self.__cmd.cli_ctx, self.__resource_group_name, self.bot_site_name,
            None)

        # Store the password for download_bot_zip:
        self.__password = password
        self.__scm_url = WebAppOperations.get_scm_url(
            self.__cmd, self.__resource_group_name, self.bot_site_name, None)

        self.__auth_headers = urllib3.util.make_headers(
            basic_auth='{0}:{1}'.format(user_name, password))
        self.__initialized = True
Exemplo n.º 2
0
    def __initialize(self):
        """Generates necessary data for performing calls to Kudu based off of data passed in on initialization.

        :return: None
        """
        user_name, password = WebAppOperations.get_site_credential(self.__cmd.cli_ctx,
                                                                   self.__resource_group_name,
                                                                   self.bot_site_name,
                                                                   None)

        # Store the password for download_bot_zip:
        self.__password = password
        self.__scm_url = WebAppOperations.get_scm_url(self.__cmd,
                                                      self.__resource_group_name,
                                                      self.bot_site_name,
                                                      None)

        self.__auth_headers = urllib3.util.make_headers(basic_auth='{0}:{1}'.format(user_name, password))
        self.__initialized = True
Exemplo n.º 3
0
    def create_bot_json(
            cmd,
            client,
            resource_group_name,
            resource_name,
            logger,
            app_password=None,  # pylint:disable=too-many-locals
            raw_bot_properties=None,
            password_only=True):
        """

        :param cmd:
        :param client:
        :param resource_group_name:
        :param resource_name:
        :param logger:
        :param app_password:
        :param raw_bot_properties:
        :return: Dictionary
        """
        if not raw_bot_properties:
            raw_bot_properties = client.bots.get(
                resource_group_name=resource_group_name,
                resource_name=resource_name)

        # Initialize names bot_file and secret to capture botFilePath and botFileSecret values from the application's
        # settings.
        bot_file = None
        bot_file_secret = None
        profile = Profile(cli_ctx=cmd.cli_ctx)
        if not app_password:
            site_name = WebAppOperations.get_bot_site_name(
                raw_bot_properties.properties.endpoint)
            app_settings = WebAppOperations.get_app_settings(
                cmd=cmd,
                resource_group_name=resource_group_name,
                name=site_name)

            app_password_values = [
                item['value'] for item in app_settings
                if item['name'] == 'MicrosoftAppPassword'
            ]
            app_password = app_password_values[
                0] if app_password_values else None
            if not app_password:
                bot_file_values = [
                    item['value'] for item in app_settings
                    if item['name'] == 'botFilePath'
                ]
                bot_file = bot_file_values[0] if bot_file_values else None
                bot_file_secret_values = [
                    item['value'] for item in app_settings
                    if item['name'] == 'botFileSecret'
                ]
                bot_file_secret = bot_file_secret_values[
                    0] if bot_file_secret_values else None

        if not bot_file and not app_password:
            bot_site_name = WebAppOperations.get_bot_site_name(
                raw_bot_properties.properties.endpoint)
            scm_url = WebAppOperations.get_scm_url(cmd, resource_group_name,
                                                   bot_site_name, None)

            # TODO: Reevaluate "Public-or-Gov" Azure logic.
            is_public_azure = (
                'azurewebsites.net' in raw_bot_properties.properties.endpoint
                or '.net' in raw_bot_properties.properties.endpoint
                or '.com' in raw_bot_properties.properties.endpoint)
            host = 'https://portal.azure.com/' if is_public_azure else 'https://portal.azure.us/'
            subscription_id = get_subscription_id(cmd.cli_ctx)
            tenant_id = profile.get_subscription(
                subscription=client.config.subscription_id)['tenantId']
            settings_url = host + '#@{}/resource/subscriptions/{}/resourceGroups/{}/providers/Microsoft.BotService/botServices/{}/app_settings'.format(tenant_id, subscription_id, resource_group_name, resource_name)  # pylint: disable=line-too-long

            logger.warning(
                '"MicrosoftAppPassword" and "botFilePath" not found in application settings'
            )
            logger.warning(
                'To see your bot\'s application settings, visit %s' %
                settings_url)
            logger.warning(
                'To visit your deployed bot\'s code on Azure, visit Kudu for your bot at %s'
                % scm_url)

        elif not app_password and bot_file:
            # We have the information we need to obtain the MSA App app password via bot file data from Kudu.
            kudu_client = KuduClient(cmd, resource_group_name, resource_name,
                                     raw_bot_properties, logger)
            bot_file_data = kudu_client.get_bot_file(bot_file)
            app_password = BotJsonFormatter.__decrypt_bot_file(
                bot_file_data, bot_file_secret, logger, password_only)

        return {
            'type':
            'abs',
            'id':
            raw_bot_properties.name,
            'name':
            raw_bot_properties.properties.display_name,
            'appId':
            raw_bot_properties.properties.msa_app_id,
            'appPassword':
            app_password,
            'endpoint':
            raw_bot_properties.properties.endpoint,
            'resourceGroup':
            str(resource_group_name),
            'tenantId':
            profile.get_subscription(
                subscription=client.config.subscription_id)['tenantId'],
            'subscriptionId':
            client.config.subscription_id,
            'serviceName':
            resource_name
        }
Exemplo n.º 4
0
    def create_bot_json(cmd, client, resource_group_name, resource_name, logger, app_password=None,  # pylint:disable=too-many-locals
                        raw_bot_properties=None, password_only=True):
        """

        :param cmd:
        :param client:
        :param resource_group_name:
        :param resource_name:
        :param logger:
        :param app_password:
        :param raw_bot_properties:
        :return: Dictionary
        """
        if not raw_bot_properties:
            raw_bot_properties = client.bots.get(
                resource_group_name=resource_group_name,
                resource_name=resource_name
            )

        # Initialize names bot_file and secret to capture botFilePath and botFileSecret values from the application's
        # settings.
        bot_file = None
        bot_file_secret = None
        profile = Profile(cli_ctx=cmd.cli_ctx)
        if not app_password:
            site_name = WebAppOperations.get_bot_site_name(raw_bot_properties.properties.endpoint)
            app_settings = WebAppOperations.get_app_settings(
                cmd=cmd,
                resource_group_name=resource_group_name,
                name=site_name
            )

            app_password_values = [item['value'] for item in app_settings if item['name'] == 'MicrosoftAppPassword']
            app_password = app_password_values[0] if app_password_values else None
            if not app_password:
                bot_file_values = [item['value'] for item in app_settings if item['name'] == 'botFilePath']
                bot_file = bot_file_values[0] if bot_file_values else None
                bot_file_secret_values = [item['value'] for item in app_settings if item['name'] == 'botFileSecret']
                bot_file_secret = bot_file_secret_values[0] if bot_file_secret_values else None

        if not bot_file and not app_password:
            bot_site_name = WebAppOperations.get_bot_site_name(raw_bot_properties.properties.endpoint)
            scm_url = WebAppOperations.get_scm_url(cmd,
                                                   resource_group_name,
                                                   bot_site_name,
                                                   None)

            # TODO: Reevaluate "Public-or-Gov" Azure logic.
            is_public_azure = ('azurewebsites.net' in raw_bot_properties.properties.endpoint or
                               '.net' in raw_bot_properties.properties.endpoint or
                               '.com' in raw_bot_properties.properties.endpoint)
            host = 'https://portal.azure.com/' if is_public_azure else 'https://portal.azure.us/'
            subscription_id = get_subscription_id(cmd.cli_ctx)
            tenant_id = profile.get_subscription(subscription=client.config.subscription_id)['tenantId']
            settings_url = host + '#@{}/resource/subscriptions/{}/resourceGroups/{}/providers/Microsoft.BotService/botServices/{}/app_settings'.format(tenant_id, subscription_id, resource_group_name, resource_name)  # pylint: disable=line-too-long

            logger.warning('"MicrosoftAppPassword" and "botFilePath" not found in application settings')
            logger.warning('To see your bot\'s application settings, visit %s' % settings_url)
            logger.warning('To visit your deployed bot\'s code on Azure, visit Kudu for your bot at %s' % scm_url)

        elif not app_password and bot_file:
            # We have the information we need to obtain the MSA App app password via bot file data from Kudu.
            kudu_client = KuduClient(cmd, resource_group_name, resource_name, raw_bot_properties, logger)
            bot_file_data = kudu_client.get_bot_file(bot_file)
            app_password = BotJsonFormatter.__decrypt_bot_file(bot_file_data, bot_file_secret, logger, password_only)

        return {
            'type': 'abs',
            'id': raw_bot_properties.name,
            'name': raw_bot_properties.properties.display_name,
            'appId': raw_bot_properties.properties.msa_app_id,
            'appPassword': app_password,
            'endpoint': raw_bot_properties.properties.endpoint,
            'resourceGroup': str(resource_group_name),
            'tenantId': profile.get_subscription(subscription=client.config.subscription_id)['tenantId'],
            'subscriptionId': client.config.subscription_id,
            'serviceName': resource_name
        }