copied from internal repo
This commit is contained in:
40
file_generator/generate_tokens.py
Normal file
40
file_generator/generate_tokens.py
Normal file
@@ -0,0 +1,40 @@
|
||||
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]))
|
||||
Reference in New Issue
Block a user