2020-06-15 18:20:18 +02:00
|
|
|
import os
|
|
|
|
import shutil
|
2019-08-30 07:40:49 +02:00
|
|
|
from g import config_dir, templates_dir, data_dir, DEFAULT_GID, DEFAULT_UID
|
2018-11-15 04:09:57 +01:00
|
|
|
from utils.jinja import render_jinja
|
2020-06-15 18:20:18 +02:00
|
|
|
from utils.misc import prepare_dir, generate_random_string
|
2018-11-15 04:09:57 +01:00
|
|
|
|
|
|
|
core_config_dir = os.path.join(config_dir, "core", "certificates")
|
|
|
|
core_env_template_path = os.path.join(templates_dir, "core", "env.jinja")
|
|
|
|
core_conf_env = os.path.join(config_dir, "core", "env")
|
|
|
|
core_conf_template_path = os.path.join(templates_dir, "core", "app.conf.jinja")
|
|
|
|
core_conf = os.path.join(config_dir, "core", "app.conf")
|
|
|
|
|
2019-08-30 07:40:49 +02:00
|
|
|
ca_download_dir = os.path.join(data_dir, 'ca_download')
|
|
|
|
|
|
|
|
|
2023-02-16 11:11:05 +01:00
|
|
|
def prepare_core(config_dict, with_notary, with_trivy):
|
2019-08-30 07:40:49 +02:00
|
|
|
prepare_dir(ca_download_dir, uid=DEFAULT_UID, gid=DEFAULT_GID)
|
|
|
|
prepare_dir(core_config_dir)
|
2018-11-15 04:09:57 +01:00
|
|
|
# Render Core
|
2019-02-20 11:01:48 +01:00
|
|
|
|
2018-11-15 04:09:57 +01:00
|
|
|
render_jinja(
|
|
|
|
core_env_template_path,
|
|
|
|
core_conf_env,
|
2019-05-05 12:13:20 +02:00
|
|
|
with_notary=with_notary,
|
2020-02-10 16:46:26 +01:00
|
|
|
with_trivy=with_trivy,
|
2020-03-03 18:33:45 +01:00
|
|
|
csrf_key=generate_random_string(32),
|
2023-02-20 08:09:21 +01:00
|
|
|
scan_robot_prefix=generate_random_string(8),
|
2018-11-15 04:09:57 +01:00
|
|
|
**config_dict)
|
|
|
|
|
2019-11-07 06:02:17 +01:00
|
|
|
render_jinja(
|
|
|
|
core_conf_template_path,
|
|
|
|
core_conf,
|
|
|
|
uid=DEFAULT_UID,
|
2020-07-21 04:00:03 +02:00
|
|
|
gid=DEFAULT_GID,
|
|
|
|
**config_dict)
|
2019-11-07 06:02:17 +01:00
|
|
|
|
2018-11-15 04:09:57 +01:00
|
|
|
|
|
|
|
def copy_core_config(core_templates_path, core_config_path):
|
|
|
|
shutil.copyfile(core_templates_path, core_config_path)
|
2019-02-20 11:01:48 +01:00
|
|
|
print("Generated configuration file: %s" % core_config_path)
|