From f69281a7ab2cbb0a6aa318dbfde53219dd76e9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Srokosz?= Date: Thu, 19 Sep 2024 15:47:50 +0200 Subject: [PATCH] Fix: add missing VNC_PASS generation in draksetup init (#970) --- drakrun/drakrun/draksetup/init.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drakrun/drakrun/draksetup/init.py b/drakrun/drakrun/draksetup/init.py index 3fa48f7e..d84d2439 100644 --- a/drakrun/drakrun/draksetup/init.py +++ b/drakrun/drakrun/draksetup/init.py @@ -1,5 +1,7 @@ import configparser import logging +import secrets +import string import sysconfig from pathlib import Path from typing import List, Optional @@ -38,6 +40,14 @@ def create_configuration_file(config_file_name, target_dir=None): return target_path +def set_template_vnc_password(template_path): + template_data = template_path.read_text() + passwd_characters = string.ascii_letters + string.digits + vnc_passwd = "".join(secrets.choice(passwd_characters) for _ in range(20)) + template_data = template_data.replace("{{ VNC_PASS }}", vnc_passwd) + template_path.write_text(template_data) + + def apply_local_minio_service_config(config: DrakrunConfig): parser = configparser.ConfigParser(strict=False, allow_no_value=True) minio_env = "[DEFAULT]\n" + MINIO_ENV_CONFIG_FILE.read_text() @@ -226,7 +236,10 @@ def is_component_to_init(component_name): create_configuration_file("hooks.txt") create_configuration_file("drakrun@.service", target_dir=SYSTEMD_SERVICE_PATH) fix_exec_start("drakrun@.service") - create_configuration_file("cfg.template", target_dir=ETC_SCRIPTS_DIR) + template_path = create_configuration_file( + "cfg.template", target_dir=ETC_SCRIPTS_DIR + ) + set_template_vnc_password(template_path) if is_component_to_init("system"): create_configuration_file(