certbot/certbot-compatibility-test/certbot_compatibility_test/util.py

54 lines
1.5 KiB
Python
Raw Permalink Normal View History

2016-04-14 20:04:23 -04:00
"""Utility functions for Certbot plugin tests."""
2015-07-16 19:57:47 -04:00
import argparse
2015-07-16 02:00:18 -04:00
import copy
2015-07-10 14:42:10 -04:00
import os
2015-07-16 02:00:18 -04:00
import re
2015-07-14 21:04:43 -04:00
import shutil
2015-07-10 14:42:10 -04:00
import tarfile
import josepy as jose
2015-07-21 21:14:57 -04:00
from acme import test_util
from certbot import constants
from certbot_compatibility_test import errors
2015-07-10 14:42:10 -04:00
2015-07-21 21:14:57 -04:00
_KEY_BASE = "rsa1024_key.pem"
KEY_PATH = test_util.vector_path(_KEY_BASE)
KEY = test_util.load_pyopenssl_private_key(_KEY_BASE)
JWK = jose.JWKRSA(key=test_util.load_rsa_private_key(_KEY_BASE))
2015-07-16 02:00:18 -04:00
IP_REGEX = re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
2015-07-10 14:42:10 -04:00
2015-07-16 02:00:18 -04:00
def create_le_config(parent_dir):
"""Sets up LE dirs in parent_dir and returns the config dict"""
config = copy.deepcopy(constants.CLI_DEFAULTS)
le_dir = os.path.join(parent_dir, "certbot")
2015-07-16 02:00:18 -04:00
config["config_dir"] = os.path.join(le_dir, "config")
config["work_dir"] = os.path.join(le_dir, "work")
config["logs_dir"] = os.path.join(le_dir, "logs_dir")
os.makedirs(config["config_dir"])
os.mkdir(config["work_dir"])
os.mkdir(config["logs_dir"])
config["domains"] = None
2015-09-06 05:21:28 -04:00
return argparse.Namespace(**config) # pylint: disable=star-args
2015-07-16 02:00:18 -04:00
2015-07-22 22:51:05 -04:00
2015-07-16 02:00:18 -04:00
def extract_configs(configs, parent_dir):
"""Extracts configs to a new dir under parent_dir and returns it"""
2015-10-11 20:33:00 -04:00
config_dir = os.path.join(parent_dir, "configs")
2015-07-10 14:42:10 -04:00
2015-07-14 21:04:43 -04:00
if os.path.isdir(configs):
shutil.copytree(configs, config_dir, symlinks=True)
elif tarfile.is_tarfile(configs):
2015-07-16 02:00:18 -04:00
with tarfile.open(configs, "r") as tar:
2015-07-14 21:04:43 -04:00
tar.extractall(config_dir)
else:
2015-07-16 02:00:18 -04:00
raise errors.Error("Unknown configurations file type")
2015-07-14 21:04:43 -04:00
2015-07-16 02:00:18 -04:00
return config_dir