File size: 740 Bytes
06d0a3d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from cryptography.fernet import Fernet
from dotenv import load_dotenv
load_dotenv()

session_keys = {}

DEFAULT_KEYS = {
    "OPENAI_API_KEY": os.getenv("OPENAI_API_KEY"),
    "NEBIUS_API_KEY": os.getenv("NEBIUS_API_KEY"),
}


ENV_PATH = ".env"
CryptographyKey = os.getenv("CryptographyKey")
if not CryptographyKey:
    key = Fernet.generate_key().decode()
    CryptographyKey = key

    # Append the key to the existing .env content (don't overwrite)
    with open(ENV_PATH, "a") as f:
        f.write(f"\nCryptographyKey={CryptographyKey}\n")

    print("✅ CryptographyKey added to .env")
else:
    print("🔐 CryptographyKey already exists")


load_dotenv(dotenv_path=ENV_PATH)
CryptographyKey = os.getenv("CryptographyKey")