This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
53 lines (43 loc) · 1.79 KB
/
main.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
import logging
import os
from flask import Flask
import flask_cors
from sqlalchemy import create_engine
import config
from models import Users, Domains, Records, Glues, Dnskeys, DDNS, Elastic, db
from services import AuthService, DNSService, MailService, Oauth
env_test = os.getenv('TEST')
app = Flask(__name__)
flask_cors.CORS(app)
app.logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
formatter = logging.Formatter(
'%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d] [%(remote_addr)s] [%(url)s]'
)
handler.setFormatter(formatter)
app.logger.addHandler(handler)
BASE_URL = config.BASE_URL
SQL_ENGINE = None
if env_test is not None:
SQL_ENGINE = create_engine("sqlite:///:memory:")
db.Base.metadata.create_all(SQL_ENGINE)
else:
connection_string = (
f"mysql+pymysql://{config.MYSQL_USER}:{config.MYSQL_PSWD}"
f"@{config.MYSQL_HOST}/{config.MYSQL_DB}"
)
SQL_ENGINE = create_engine(connection_string)
ddns = DDNS(logging, config.DDNS_KEY, config.DDNS_SERVER, config.DDNS_ZONE)
users = Users(SQL_ENGINE)
domains = Domains(SQL_ENGINE)
records = Records(SQL_ENGINE)
glues = Glues(SQL_ENGINE)
dnskeys = Dnskeys(SQL_ENGINE)
nycu_oauth = Oauth(redirect_uri = config.NYCU_OAUTH_RURL,
client_id = config.NYCU_OAUTH_ID,
client_secret = config.NYCU_OAUTH_KEY)
elastic = Elastic(config.ELASTICSERVER, config.ELASTICUSER, config.ELASTICPASS)
authService = AuthService(logging, config.JWT_SECRET, users, domains)
dnsService = DNSService(logging, users, domains, records, glues, dnskeys, ddns, config.HOST_DOMAINS)
mailService = MailService(logging, config.SMTP_SERVER, config.SMTP_PORT, config.SMTP_USER, config.SMTP_PASS, config.SMTP_FROM)
from controllers import auth, domains, ddns, glue, dnssec, metrics # pylint: disable=all