コード例 #1
0
    def __questions_kobo_postgres(self):
        """
        KoBoToolbox's credentials
        """
        # kobo_db_server
        self.__dict['kobo_db_server'] = CLI.colored_input(
            'KoBoToolbox PostgreSQL server?', CLI.COLOR_QUESTION,
            self.__dict['kobo_db_server'])

        # kobo_db_name - Kobo Form
        CLI.colored_print('KoBoToolbox\'s KoboFORM PostgreSQL database name?',
                          CLI.COLOR_QUESTION)
        self.__dict['kobo_db_name'] = CLI.get_response(
            r'~^\w+$', self.__dict['kobo_db_name'], to_lower=False)

        # kobo_cat_db_name - Kobo Form
        CLI.colored_print('KoBoToolbox\'s KoboCAT PostgreSQL database name?',
                          CLI.COLOR_QUESTION)
        self.__dict['kobo_cat_db_name'] = CLI.get_response(
            r'~^\w+$', self.__dict['kobo_cat_db_name'], to_lower=False)

        # kobo_db_port
        self.__dict['kobo_db_port'] = CLI.colored_input(
            'KoBoToolbox PostgreSQL Port?', CLI.COLOR_QUESTION,
            self.__dict['kobo_db_port'])
        # kobo_db_user
        self.__dict['kobo_db_user'] = CLI.colored_input(
            'KoBoToolbox PostgreSQL User?', CLI.COLOR_QUESTION,
            self.__dict['kobo_db_user'])

        # kobo_db_password
        self.__dict['kobo_db_password'] = CLI.colored_input(
            'KoBoToolbox PostgreSQL Password?', CLI.COLOR_QUESTION,
            self.__dict['kobo_db_password'])
コード例 #2
0
    def __questions_aws_configuration(self):

        if self.__dict['use_aws']:
            self.__dict['aws_access_key'] = CLI.colored_input(
                'AWS Access Key', CLI.COLOR_QUESTION,
                self.__dict['aws_access_key'])
            self.__dict['aws_secret_key'] = CLI.colored_input(
                'AWS Secret Key', CLI.COLOR_QUESTION,
                self.__dict['aws_secret_key'])
        else:
            self.__dict['aws_access_key'] = ''
            self.__dict['aws_secret_key'] = ''
コード例 #3
0
    def __create_directory(self):
        """
        Create repository directory if it doesn't exist.
        """
        CLI.colored_print('Where do you want to install?', CLI.COLOR_QUESTION)
        while True:
            support_api_path = CLI.colored_input(
                '', CLI.COLOR_QUESTION, self.__dict['support_api_path'])

            if support_api_path.startswith('.'):
                base_dir = os.path.dirname(
                    os.path.dirname(os.path.realpath(__file__)))
                support_api_path = os.path.normpath(
                    os.path.join(base_dir, support_api_path))

            question = 'Please confirm path [{}]'.format(support_api_path)
            response = CLI.yes_no_question(question)
            if response is True:
                if os.path.isdir(support_api_path):
                    break
                else:
                    try:
                        os.makedirs(support_api_path)
                        break
                    except OSError:
                        CLI.colored_print(
                            'Could not create directory {}!'.format(
                                support_api_path), CLI.COLOR_ERROR)
                        CLI.colored_print(
                            'Please make sure you have permissions '
                            'and path is correct', CLI.COLOR_ERROR)

        self.__dict['support_api_path'] = support_api_path
        self.write_unique_id()
        self.__validate_installation()
コード例 #4
0
 def __questions_api_port(self):
     """
     Customize API port
     """
     self.__dict['support_api_port'] = CLI.colored_input(
         'Support API Port?', CLI.COLOR_QUESTION,
         self.__dict['support_api_port'])
コード例 #5
0
 def __questions_kobo_api(self):
     """
     KoBoToolbox's API
     """
     # kobo_api_uri
     self.__dict['kobo_api_uri'] = CLI.colored_input(
         'KoBoToolbox KPI Uri?', CLI.COLOR_QUESTION,
         self.__dict['kobo_api_uri'])
コード例 #6
0
    def __questions_aws_backup_settings(self):

        self.__dict['aws_backup_bucket_name'] = CLI.colored_input(
            'AWS Backups bucket name', CLI.COLOR_QUESTION,
            self.__dict['aws_backup_bucket_name'])

        if self.__dict['aws_backup_bucket_name'] != '':

            backup_from_primary = self.__dict['backup_from_primary']

            CLI.colored_print('How many yearly backups to keep?',
                              CLI.COLOR_QUESTION)
            self.__dict['aws_backup_yearly_retention'] = CLI.get_response(
                r'~^\d+$', self.__dict['aws_backup_yearly_retention'])

            CLI.colored_print('How many monthly backups to keep?',
                              CLI.COLOR_QUESTION)
            self.__dict['aws_backup_monthly_retention'] = CLI.get_response(
                r'~^\d+$', self.__dict['aws_backup_monthly_retention'])

            CLI.colored_print('How many weekly backups to keep?',
                              CLI.COLOR_QUESTION)
            self.__dict['aws_backup_weekly_retention'] = CLI.get_response(
                r'~^\d+$', self.__dict['aws_backup_weekly_retention'])

            CLI.colored_print('How many daily backups to keep?',
                              CLI.COLOR_QUESTION)
            self.__dict['aws_backup_daily_retention'] = CLI.get_response(
                r'~^\d+$', self.__dict['aws_backup_daily_retention'])

            # if (not self.multi_servers or
            #         (self.primary_backend and backup_from_primary) or
            #         (self.secondary_backend and not backup_from_primary)):
            #     CLI.colored_print('PostgresSQL backup minimum size (in MB)?',
            #   CLI.COLOR_QUESTION)
            CLI.colored_print(
                'Files below this size will be ignored when '
                'rotating backups.', CLI.COLOR_INFO)
            self.__dict['aws_postgres_backup_minimum_size'] = CLI.get_response(
                r'~^\d+$', self.__dict['aws_postgres_backup_minimum_size'])

            CLI.colored_print('Chunk size of multipart uploads (in MB)?',
                              CLI.COLOR_QUESTION)
            self.__dict['aws_backup_upload_chunk_size'] = CLI.get_response(
                r'~^\d+$', self.__dict['aws_backup_upload_chunk_size'])

            response = CLI.yes_no_question(
                'Use AWS LifeCycle deletion rule?',
                default=self.__dict['aws_backup_bucket_deletion_rule_enabled'])
            self.__dict['aws_backup_bucket_deletion_rule_enabled'] = response
コード例 #7
0
    def __questions_dashboards(self):
        """
        Dashboards questions
        """
        # dashboards_port
        self.__dict['dashboards_port'] = CLI.colored_input(
            'Dashboards Port?', CLI.COLOR_QUESTION,
            self.__dict['dashboards_port'])

        # dashboards_kobo_token
        self.__dict['dashboards_kobo_token'] = CLI.colored_input(
            'KoBoToolbox Access Token', CLI.COLOR_QUESTION,
            self.__dict['dashboards_kobo_token'])

        schedule_regex_pattern = (
            r'^((((\d+(,\d+)*)|(\d+-\d+)|(\*(\/\d+)?)))'
            r'(\s+(((\d+(,\d+)*)|(\d+\-\d+)|(\*(\/\d+)?)))){4})$')

        CLI.colored_print('Dashboards Github Poll cron expression?',
                          CLI.COLOR_QUESTION)
        self.__dict['dashboards_cron_schedule'] = CLI.get_response(
            '~{}'.format(schedule_regex_pattern),
            self.__dict['dashboards_cron_schedule'])
コード例 #8
0
    def __questions_postgres(self):
        """
        PostgreSQL credentials to be confirmed
        """
        #support_db_user = self.__dict['support_db_user']
        #'support_db_server'

        CLI.colored_print('Support PostgreSQL database name?',
                          CLI.COLOR_QUESTION)
        support_db_name = CLI.get_response(r'~^\w+$',
                                           self.__dict['support_db_name'],
                                           to_lower=False)

        CLI.colored_print("PostgreSQL user's password?", CLI.COLOR_QUESTION)
        self.__dict['support_db_password'] = CLI.get_response(
            r'~^.{8,}$',
            self.__dict['support_db_password'],
            to_lower=False,
            error_msg='Too short. 8 characters minimum.')

        self.__dict['support_db_port'] = CLI.colored_input(
            'Support PostgreSQL db Port?', CLI.COLOR_QUESTION,
            self.__dict['support_db_port'])
コード例 #9
0
    def update_hosts(cls, dict_):
        """

        Args:
            dict_ (dict): Dictionary provided by `Config.get_dict()`
        """
        if dict_['local_installation']:
            start_sentence = '### (BEGIN) KoBoToolbox local routes'
            end_sentence = '### (END) KoBoToolbox local routes'

            with open('/etc/hosts', 'r') as f:
                tmp_host = f.read()

            start_position = tmp_host.find(start_sentence)
            end_position = tmp_host.find(end_sentence)

            if start_position > -1:
                tmp_host = tmp_host[0: start_position] \
                           + tmp_host[end_position + len(end_sentence) + 1:]

            routes = '{ip_address}  ' \
                     '{kpi_subdomain}.{public_domain_name} ' \
                     '{kc_subdomain}.{public_domain_name} ' \
                     '{ee_subdomain}.{public_domain_name}'.format(
                        ip_address=dict_['local_interface_ip'],
                        public_domain_name=dict_['public_domain_name'],
                        kpi_subdomain=dict_['kpi_subdomain'],
                        kc_subdomain=dict_['kc_subdomain'],
                        ee_subdomain=dict_['ee_subdomain']
                     )

            tmp_host = ('{bof}'
                        '\n{start_sentence}'
                        '\n{routes}'
                        '\n{end_sentence}').format(
                            bof=tmp_host.strip(),
                            start_sentence=start_sentence,
                            routes=routes,
                            end_sentence=end_sentence)

            with open('/tmp/etchosts', 'w') as f:
                f.write(tmp_host)

            message = ('Privileges escalation is required to update '
                       'your `/etc/hosts`.')
            CLI.framed_print(message, color=CLI.COLOR_INFO)
            dict_['review_host'] = CLI.yes_no_question(
                'Do you want to review your /etc/hosts file '
                'before overwriting it?',
                default=dict_['review_host'])
            if dict_['review_host']:
                print(tmp_host)
                CLI.colored_input('Press any keys when ready')

            # Save 'review_host'
            config = Config()
            config.write_config()

            cmd = 'sudo mv /etc/hosts /etc/hosts.old ' \
                  '&& sudo mv /tmp/etchosts /etc/hosts'
            return_value = os.system(cmd)
            if return_value != 0:
                sys.exit(1)
コード例 #10
0
ファイル: setup.py プロジェクト: tomislavr/kobo-install
    def update_hosts(cls, config):

        if config.get("local_installation") == Config.TRUE:
            start_sentence = "### (BEGIN) KoBoToolbox local routes"
            end_sentence = "### (END) KoBoToolbox local routes"

            with open("/etc/hosts", "r") as f:
                tmp_host = f.read()

            start_position = tmp_host.find(start_sentence)
            end_position = tmp_host.find(end_sentence)

            if start_position > -1:
                tmp_host = tmp_host[0:start_position] + tmp_host[
                    end_position + len(end_sentence) + 1:]

            routes = "{ip_address}  " \
                     "{kpi_subdomain}.{public_domain_name} " \
                     "{kc_subdomain}.{public_domain_name} " \
                     "{ee_subdomain}.{public_domain_name}".format(
                        ip_address=config.get("local_interface_ip"),
                        public_domain_name=config.get("public_domain_name"),
                        kpi_subdomain=config.get("kpi_subdomain"),
                        kc_subdomain=config.get("kc_subdomain"),
                        ee_subdomain=config.get("ee_subdomain")
            )

            tmp_host = ("{bof}"
                        "\n{start_sentence}"
                        "\n{routes}"
                        "\n{end_sentence}").format(
                            bof=tmp_host.strip(),
                            start_sentence=start_sentence,
                            routes=routes,
                            end_sentence=end_sentence)

            with open("/tmp/etchosts", "w") as f:
                f.write(tmp_host)

            if config.get("review_host") != Config.FALSE:
                CLI.colored_print(
                    "╔═══════════════════════════════════════════════════════════════════╗",
                    CLI.COLOR_WARNING)
                CLI.colored_print(
                    "║ Administrative privileges are required to update your /etc/hosts. ║",
                    CLI.COLOR_WARNING)
                CLI.colored_print(
                    "╚═══════════════════════════════════════════════════════════════════╝",
                    CLI.COLOR_WARNING)
                CLI.colored_print(
                    "Do you want to review your /etc/hosts file before overwriting it?",
                    CLI.COLOR_SUCCESS)
                CLI.colored_print("\t1) Yes")
                CLI.colored_print("\t2) No")
                config["review_host"] = CLI.get_response(
                    [Config.TRUE, Config.FALSE],
                    config.get("review_host", Config.FALSE))
                if config["review_host"] == Config.TRUE:
                    print(tmp_host)
                    CLI.colored_input("Press any keys when ready")

                # Save 'review_host'
                config_ = Config()
                config_.write_config()

            return_value = os.system(
                "sudo mv /etc/hosts /etc/hosts.old && sudo mv /tmp/etchosts /etc/hosts"
            )
            if return_value != 0:
                sys.exit()