-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.py
80 lines (60 loc) · 2.24 KB
/
settings.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import json
import os
import re
from dotenv import load_dotenv
load_dotenv()
is_docker = os.path.exists("/.dockerenv")
# Secretの設定
if is_docker:
SECRET_DIR = os.environ.get("SECRET_DIR", "/run/secrets")
GCP_SERVICE_ACCOUNT_KEY = os.path.join(SECRET_DIR, "gcp_service_account_key")
else:
SECRET_DIR = "./secrets"
GCP_SERVICE_ACCOUNT_KEY = os.path.join(SECRET_DIR, "save-slack-gsheet-e7e41bdd1d33.json")
def load_secrets(name: str) -> str:
if not is_docker:
path = os.path.join(SECRET_DIR, f"{name}.txt")
else:
path = os.path.join(SECRET_DIR, f"{name}")
with open(path) as f:
try:
secrets = json.load(f)
except json.decoder.JSONDecodeError:
f.seek(0)
secrets = f.read().strip()
return str(secrets)
ALLOWED_DOMAINS = ["save-slack-gsheet.iam.gserviceaccount.com", "gmail.com"]
def check_email_domain(email_list: list) -> list:
filtered = []
for email in email_list:
if re.search(rf"@({'|'.join(ALLOWED_DOMAINS)})$", email):
filtered.append(email)
else:
raise AttributeError(f"Invalid email: {email}. Gmail only allowed.")
return filtered
# Slack
SLACK_APP_TOKEN = load_secrets("slack_app_token")
SLACK_BOT_TOKEN = load_secrets("slack_bot_token")
SLACK_SIGNING_SECRET = load_secrets("slack_signing_secret")
SLACK_WORKSPACE_TEAM_ID = os.environ["SLACK_WORKSPACE_TEAM_ID"]
ERROR_CHANNEL = os.environ["ERROR_CHANNEL"]
SPREAD_SHEET_KEY = os.environ["SPREAD_SHEET_KEY"]
MASTER_SHEET_KEY = os.environ["MASTER_SHEET_KEY"]
ANNOTATION_FOLDER_KEY = os.environ["ANNOTATION_FOLDER_KEY"]
# MySQL
if is_docker:
DB_URL = os.environ["MYSQL_URL"]
else:
DB_URL = f'mysql://root:{os.environ["MYSQL_PASSWORD"]}@localhost/{os.environ["MYSQL_DATABASE"]}'
# Other settings
LOG_DIR = os.environ["LOG_DIR"]
TMP_DIR = os.environ["TMP_DIR"]
INSTRUCTION_URL = os.environ["INSTRUCTION_URL"]
BOT_ID = os.environ["BOT_ID"]
BOT_EMAIL = os.environ["BOT_EMAIL"]
STAFF_ID = os.environ["STAFF_ID"]
STAFF_EMAIL = os.environ["STAFF_EMAIL"]
STAFF_BOT_IDS = [STAFF_ID, BOT_ID]
STAFF_BOT_EMALS = [STAFF_EMAIL, BOT_EMAIL]
STAFF_BOT_ID_GMAILS = check_email_domain(STAFF_BOT_EMALS)
AFTER_DOWNLOAD_TASK_SCRIPT = os.environ["AFTER_DOWNLOAD_TASK_SCRIPT"]