Example #1
0
def gen_default_config(config_path):
    config_path = utils.absolute_path(config_path)
    utils.file_copy(utils.TEMPLATE_SERVER_CONFIG, config_path)

    configs = utils.just_read_config(config_path, raw=True)

    workspaces = utils.join_path(utils.get_parent(utils.DEAFULT_CONFIG_PATH),
                                 'workspaces')
    plugins_path = utils.join_path(utils.ROOT_PATH, 'plugins')
    go_path = utils.join_path(utils.ROOT_PATH, 'plugins/go')
    data_path = utils.join_path(utils.ROOT_PATH, 'data')
    alias_path = utils.join_path(utils.ROOT_PATH, 'lib/alias')

    # set some path
    configs.set('Enviroments', 'workspaces', workspaces)
    configs.set('Enviroments', 'plugins_path', plugins_path)
    configs.set('Enviroments', 'data_path', data_path)
    configs.set('Enviroments', 'alias_path', alias_path)
    configs.set('Enviroments', 'go_path', go_path)

    # set some tokens
    github_api_key = utils.get_enviroment("GITHUB_API_KEY")
    slack_bot_token = utils.get_enviroment("SLACK_BOT_TOKEN")
    log_channel = utils.get_enviroment("LOG_CHANNEL")
    status_channel = utils.get_enviroment("STATUS_CHANNEL")
    report_channel = utils.get_enviroment("REPORT_CHANNEL")
    stds_channel = utils.get_enviroment("STDS_CHANNEL")
    verbose_report_channel = utils.get_enviroment("VERBOSE_REPORT_CHANNEL")
    configs.set('Enviroments', 'github_api_key', github_api_key)
    configs.set('Slack', 'slack_bot_token', slack_bot_token)
    configs.set('Slack', 'log_channel', log_channel)
    configs.set('Slack', 'status_channel', status_channel)
    configs.set('Slack', 'report_channel', report_channel)
    configs.set('Slack', 'stds_channel', stds_channel)
    configs.set('Slack', 'verbose_report_channel', verbose_report_channel)

    # write it again
    with open(config_path, 'w+') as configfile:
        configs.write(configfile)

    # read it again and return
    options = utils.just_read_config(config_path)
    return options
Example #2
0
 def gen_output_path(self):
     outdir = utils.get_parent(self.options.get('output'))
     basename = utils.get_filename(self.options.get('output'))
     self.options['repo_output'] = utils.join_path(outdir, f'repo-{basename}')
     self.options['user_output'] = utils.join_path(outdir, f'user-{basename}')
     self.options['org_output'] = utils.join_path(outdir, f'org-{basename}')
Example #3
0
def gen_default_config(config_path):
    config_path = utils.absolute_path(config_path)
    utils.file_copy(utils.TEMPLATE_SERVER_CONFIG, config_path)

    configs = utils.just_read_config(config_path, raw=True)

    workspaces = utils.join_path(utils.get_parent(
        utils.DEAFULT_CONFIG_PATH), 'workspaces')
    plugins_path = utils.join_path(utils.ROOT_PATH, 'plugins')
    go_path = utils.join_path(utils.ROOT_PATH, 'plugins/go')
    data_path = utils.join_path(utils.ROOT_PATH, 'data')
    alias_path = utils.join_path(utils.ROOT_PATH, 'lib/alias')

    # set some path
    configs.set('Enviroments', 'workspaces', workspaces)
    configs.set('Enviroments', 'plugins_path', plugins_path)
    configs.set('Enviroments', 'data_path', data_path)
    configs.set('Enviroments', 'alias_path', alias_path)
    configs.set('Enviroments', 'go_path', go_path)

    # set some tokens
    github_api_key = utils.get_enviroment("GITHUB_API_KEY")
    slack_bot_token = utils.get_enviroment("SLACK_BOT_TOKEN")
    log_channel = utils.get_enviroment("LOG_CHANNEL")
    status_channel = utils.get_enviroment("STATUS_CHANNEL")
    report_channel = utils.get_enviroment("REPORT_CHANNEL")
    stds_channel = utils.get_enviroment("STDS_CHANNEL")
    verbose_report_channel = utils.get_enviroment("VERBOSE_REPORT_CHANNEL")
    configs.set('Enviroments', 'github_api_key', github_api_key)
    configs.set('Slack', 'slack_bot_token', slack_bot_token)
    configs.set('Slack', 'log_channel', log_channel)
    configs.set('Slack', 'status_channel', status_channel)
    configs.set('Slack', 'report_channel', report_channel)
    configs.set('Slack', 'stds_channel', stds_channel)
    configs.set('Slack', 'verbose_report_channel', verbose_report_channel)

    telegram_bot_token = utils.get_enviroment("TELEGRAM_BOT_TOKEN")
    telegram_log_channel = utils.get_enviroment("TELEGRAM_LOG_CHANNEL")
    telegram_status_channel = utils.get_enviroment("TELEGRAM_STATUS_CHANNEL")
    telegram_report_channel = utils.get_enviroment("TELEGRAM_REPORT_CHANNEL")
    telegram_stds_channel = utils.get_enviroment("TELEGRAM_STDS_CHANNEL")
    telegram_verbose_report_channel = utils.get_enviroment("TELEGRAM_VERBOSE_REPORT_CHANNEL")
    configs.set('Telegram', 'telegram_bot_token', telegram_bot_token)
    configs.set('Telegram', 'telegram_log_channel', telegram_log_channel)
    configs.set('Telegram', 'telegram_status_channel', telegram_status_channel)
    configs.set('Telegram', 'telegram_report_channel', telegram_report_channel)
    configs.set('Telegram', 'telegram_stds_channel', telegram_stds_channel)
    configs.set('Telegram', 'telegram_verbose_report_channel', telegram_verbose_report_channel)

    # monitor mode
    backups = utils.join_path(utils.get_parent(
        utils.DEAFULT_CONFIG_PATH), 'backups')
    utils.make_directory(backups)

    monitors = utils.join_path(utils.get_parent(
        utils.DEAFULT_CONFIG_PATH), 'monitors')
    utils.make_directory(monitors)

    configs.set('Monitor', 'monitors', monitors)
    configs.set('Monitor', 'backups', backups)
    monitor_level = utils.get_enviroment("monitor_level", 'final')
    configs.set('Monitor', 'monitor_level', monitor_level)

    # monitor bot
    slack_monitor_token = utils.get_enviroment("SLACK_MONITOR_TOKEN")
    new_channel = utils.get_enviroment("NEW_CHANNEL")
    new_name = utils.get_enviroment("NEW_NAME")
    missing_channel = utils.get_enviroment("MISSING_CHANNEL")
    missing_name = utils.get_enviroment("MISSING_NAME")
    configs.set('Monitor', 'slack_monitor_token', slack_monitor_token)
    configs.set('Monitor', 'new_channel', new_channel)
    configs.set('Monitor', 'new_name', new_name)
    configs.set('Monitor', 'missing_channel', missing_channel)
    configs.set('Monitor', 'missing_name', missing_name)

    # write it again
    with open(config_path, 'w+') as configfile:
        configs.write(configfile)

    # read it again and return
    options = utils.just_read_config(config_path)
    return options