Files
templates/file_generator/generate_tokens.py
2026-01-22 12:37:26 +01:00

41 lines
1.1 KiB
Python

import os
import random
import string
from conpeek_setup import util
def generate_password(length=64, lowercase=True, uppercase=True, digits=True):
basic_characters = ""
if lowercase:
basic_characters += string.ascii_lowercase
if uppercase:
basic_characters += string.ascii_uppercase
if digits:
basic_characters += string.digits
if not lowercase and not uppercase and not digits:
util.print_red("Password must contain at least lowercase, uppercase or digits.")
password = ''.join(random.choices(basic_characters, k=length))
return password
def run(config):
output_directory = os.path.join(util.get_output_path(), "tokens")
os.makedirs(output_directory, exist_ok=True)
passwords = {
"system_token_secretkey": 64,
".erlang.cookie": 56,
}
for key in passwords.keys():
token_path = os.path.join(output_directory, key)
if not os.path.exists(token_path):
with open(token_path, "w") as file:
file.write(generate_password(length=passwords[key]))