api_utils.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:lecli 作者: rapid7 项目源码 文件源码
def init_config():
    """
    Initialize config file in the OS specific config path if there is no config file exists.
    """
    config_dir = user_config_dir(lecli.__name__)

    if not os.path.exists(CONFIG_FILE_PATH):
        if not os.path.exists(config_dir):
            os.makedirs(config_dir)

        dummy_config = ConfigParser.ConfigParser()
        config_file = open(CONFIG_FILE_PATH, 'w')
        dummy_config.add_section(AUTH_SECTION)
        dummy_config.set(AUTH_SECTION, 'account_resource_id', '')
        dummy_config.set(AUTH_SECTION, 'owner_api_key_id', '')
        dummy_config.set(AUTH_SECTION, 'owner_api_key', '')
        dummy_config.set(AUTH_SECTION, 'rw_api_key', '')
        dummy_config.set(AUTH_SECTION, 'ro_api_key', '')

        dummy_config.add_section(CLI_FAVORITES_SECTION)
        dummy_config.add_section(URL_SECTION)
        dummy_config.set(URL_SECTION, 'api_url', 'https://rest.logentries.com')

        dummy_config.write(config_file)
        config_file.close()
        click.echo("An empty config file created in path %s, please check and configure it. To "
                   "learn how to get necessary api keys, go to this Logentries documentation "
                   "page: https://docs.logentries.com/docs/api-keys" % CONFIG_FILE_PATH)
    else:
        click.echo("Config file exists in the path: " + CONFIG_FILE_PATH, err=True)

    sys.exit(1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号