generated from ouslan/project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv.py
25 lines (20 loc) · 871 Bytes
/
env.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
from dotenv import load_dotenv
import os
load_dotenv()
def read_secret_file(secret_path):
with open(secret_path, "r") as file:
return file.read().strip()
def db_credentials():
DB_USER = str(os.environ.get("POSTGRES_USER")).strip()
DB_DB = str(os.environ.get("POSTGRES_DB")).strip()
PORT = str(os.environ.get("POSTGRES_PORT")).strip()
if os.environ.get("DEV") == "True":
DB_PASSWORD = str(os.environ.get("POSTGRES_PASSWORD")).strip()
PORT = str(os.environ.get("POSTGRES_PORT")).strip()
HOST = "localhost"
DATABASE_URL = f"postgresql://{DB_USER}:{DB_PASSWORD}@{HOST}:{PORT}/{DB_DB}"
else:
DB_PASSWORD = str(read_secret_file("/run/secrets/db-password")).strip()
HOST = "database"
DATABASE_URL = f"postgresql://{DB_USER}:{DB_PASSWORD}@{HOST}:{PORT}/{DB_DB}"
return DATABASE_URL