-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.py
39 lines (33 loc) · 1.13 KB
/
config.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
import os
import json
import boto3
from botocore.exceptions import ClientError
class Config:
SECRET_KEY = os.urandom(24)
SQLALCHEMY_TRACK_MODIFICATIONS = False
@staticmethod
def get_secret():
secret_name = "yousecret"
region_name = "eu-west-3"
# Create a Secrets Manager client
session = boto3.session.Session()
client = session.client(
service_name='secretsmanager',
region_name=region_name
)
try:
get_secret_value_response = client.get_secret_value(
SecretId=secret_name
)
except ClientError as e:
raise e
secret = get_secret_value_response['SecretString']
secret_dict = json.loads(secret)
db_username = secret_dict['username']
db_password = secret_dict['password']
db_host = "yourHostDb"
db_name = "mydb"
return db_username, db_password, db_host, db_name
print(db_name)
db_username, db_password, db_host, db_name = get_secret()
SQLALCHEMY_DATABASE_URI = f"postgresql://{db_username}:{db_password}@{db_host}:5432/{db_name}"