-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.py
63 lines (55 loc) · 1.94 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import boto3
import firebase_admin
from firebase_admin import credentials
import os
from dotenv import load_dotenv
import json
import base64
load_dotenv()
def initialize():
dynamodb = boto3.resource(
'dynamodb',
region_name=os.getenv("MY_AWS_REGION"),
aws_access_key_id=os.getenv("MY_AWS_ACCESS_KEY"),
aws_secret_access_key=os.getenv("MY_AWS_SECRET_KEY")
)
domain_tables = {
"ai": dynamodb.Table("domain-ai"),
"app": dynamodb.Table("domain-app"),
"events": dynamodb.Table("domain-events"),
"graphic": dynamodb.Table("domain-graphic"),
"iot": dynamodb.Table("domain-iot"),
"pnm": dynamodb.Table("domain-pnm"),
"rnd": dynamodb.Table("domain-rnd"),
"ui": dynamodb.Table("domain-ui"),
"video": dynamodb.Table("domain-video"),
"web": dynamodb.Table("domain-web")
}
user_table = dynamodb.Table("enrollments-site-users")
admin_table = dynamodb.Table("enrollments-site-admins")
quiz_table = dynamodb.Table("enrollments-site-quiz")
interview_table = dynamodb.Table("enrollments-site-interview")
if not firebase_admin._apps:
encoded_key = os.getenv("MY_FIREBASE_SERVICE_ACCOUNT_KEY")
if encoded_key:
decoded_key = json.loads(base64.b64decode(encoded_key).decode('utf-8'))
cred = credentials.Certificate(decoded_key)
firebase_app = firebase_admin.initialize_app(cred)
else:
raise ValueError("FIREBASE_SERVICE_ACCOUNT_KEY is not set")
else:
firebase_app = firebase_admin.get_app()
return {
'firebase_app': firebase_app,
'user_table': user_table,
'admin_table':admin_table,
'quiz_table': quiz_table,
'interview_table': interview_table,
'domain_tables': domain_tables
}
resources = None
def get_resources():
global resources
if resources is None:
resources = initialize()
return resources