-
Notifications
You must be signed in to change notification settings - Fork 1
/
settings.py
70 lines (50 loc) · 2.86 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import secrets
from dotenv import load_dotenv
def generate_url_safe_secret(length=32):
alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_'
url_safe_secret = ''.join(secrets.choice(alphabet) for _ in range(length))
return url_safe_secret
def load_settings_or_prompt():
env_file = ".env"
if not os.path.exists(env_file):
# Prompt the user for input
fast_api_secret = generate_url_safe_secret(48)
print("PEERBRAIN SERVER INITIAL CONFIG \n\n")
print('No .env file could be found. Please enter all the necessary info below: \n\n')
server_url = input("Enter the url for your Peerbrain Server: \n")
database_uri = input("Enter your database URI: \n")
database_name = input("Enter your database name: \n")
sym_key_api_url = input("Enter the URL of your Symmetric Key Server: \n")
sym_key_gen_api_key = input("Enter your Symmetric Key API key from the init endpoint: \n")
sym_key_micro_key = input("Enter your Symmetric Key Micro Key: \n")
email_password = input("Enter the password for your email: \n")
email_sender = input("Enter your email address: \n")
email_username = input("Enter your username for the email address: \n")
email_server = input("Enter the SMTP server for your email: \n")
reset_password_route = generate_url_safe_secret()
otp_secret = generate_url_safe_secret()
# Write the values to the .env file
with open(env_file, "w") as f:
f.write(f"#Fast API Secret key ==> To be randomly generated in the future\n")
f.write(f"SECRET_KEY={fast_api_secret}\n\n")
f.write(f"#Peerbrain application server url\n")
f.write(f"SERVER_URL={server_url}\n\n")
f.write(f"#Database URI\n")
f.write(f"DATABASE_URI={database_uri}\n\n")
f.write(f"DATABASE_NAME={database_name}\n\n")
f.write(f"#Symmetric Key Server API Credentials\n")
f.write(f"SYM_KEY_API_URL={sym_key_api_url}\n")
f.write(f"SYM_KEY_API_KEY={sym_key_gen_api_key}\n")
f.write(f"SYM_KEY_X_API_KEY={sym_key_micro_key}\n\n")
f.write(f"#Email Credentials\n")
f.write(f"EMAIL_PASS={email_password}\n")
f.write(f"EMAIL_SENDER={email_sender}\n")
f.write(f"EMAIL_USERNAME={email_username}\\nn")
f.write(f"EMAIL_SERVER={email_server}\n\n")
f.write(f"#Reset Password route\n")
f.write(f"RESET_PASSWORD_ROUTE={reset_password_route}\n")
f.write(f"#OTP Secret\n")
f.write(f"OTP_SECRET={otp_secret}\n")
# Load the environment variables from the .env file
load_dotenv(env_file)