-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
60 lines (52 loc) · 2.03 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
from pathlib import Path
from sys import exit
import os
SECRETS_TO_PATHS = {
"FLASK_SECRET_KEY": Path(".secrets/flask_secret_key"),
"GITHUB_CLIENT_ID": Path(".secrets/github_client_id"),
"GITHUB_CLIENT_SECRET": Path(".secrets/github_client_secret"),
"GOOGLE_CLIENT_ID": Path(".secrets/google_client_id"),
"GOOGLE_CLIENT_SECRET": Path(".secrets/google_client_secret"),
"DATABASE_URL": Path(".secrets/database_url"),
}
def get_secret_file(path) -> str:
try:
with path.open("r") as f:
return f.read()
except:
exit(f"Error getting secret {path}")
def get_secret(name: str):
if os.getenv("LIFECAL_ENV") == "RENDER":
return get_secret_file(SECRETS_TO_PATHS[name].relative_to(".secrets"))
elif os.getenv("LIFECAL_ENV") == "FLY":
if name in os.environ:
return os.getenv(name)
else:
raise Exception
else:
return get_secret_file(SECRETS_TO_PATHS[name])
def get_oauth2_providers():
return {
"github": {
"client_id": get_secret("GITHUB_CLIENT_ID"),
"client_secret": get_secret("GITHUB_CLIENT_SECRET"),
"authorize_url": "https://github.com/login/oauth/authorize",
"token_url": "https://github.com/login/oauth/access_token",
"userinfo": {
"url": "https://api.github.com/user",
"oauth_id": lambda r: "gh_" + str(r.json()["id"]),
},
"scopes": ["read:user"],
},
"google": {
"client_id": get_secret("GOOGLE_CLIENT_ID"),
"client_secret": get_secret("GOOGLE_CLIENT_SECRET"),
"authorize_url": "https://accounts.google.com/o/oauth2/auth",
"token_url": "https://accounts.google.com/o/oauth2/token",
"userinfo": {
"url": "https://www.googleapis.com/oauth2/v3/userinfo",
"oauth_id": lambda r: "go_" + str(r.json()["sub"]),
},
"scopes": ["https://www.googleapis.com/auth/userinfo.profile"],
},
}