-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
77 lines (64 loc) · 2.12 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import logging
import os
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.auth import get_firebase_credentials, setup_firebase_auth
from app.routers import (
actionlogs,
actions,
auth,
external,
misptags,
pteams,
tags,
threat,
topics,
users,
)
from app.ssvc import deployer_data
def create_app():
app = FastAPI(title="Threatconnectome")
origins = [
"http://localhost:3000", # dev
"http://localhost:8080", # dev
"http://localhost", # dev
"https://threatconnectome.firebase.app", # prod-alias
"https://threatconnectome.metemcyber.ntt.com", # prod
"https://threatconnectome.web.app", # prod-alias
]
app.add_middleware(
CORSMiddleware,
allow_credentials=True,
allow_headers=["*"],
allow_methods=["DELETE", "GET", "OPTION", "POST", "PUT"],
allow_origin_regex=r"https:\/\/threatconnectome--.+-[0-9a-z]{8}\.(firebaseapp\.com|web\.app)",
allow_origins=origins,
)
# Register routersx
app.include_router(auth.router) # place auth on the top for comfortable docs
app.include_router(actionlogs.router)
app.include_router(actions.router)
app.include_router(external.router)
app.include_router(misptags.router)
app.include_router(pteams.router)
app.include_router(tags.router)
app.include_router(topics.router)
app.include_router(users.router)
app.include_router(threat.router)
# setup firebase
cred = setup_firebase_auth()
# Dependency injection as needed
app.dependency_overrides[get_firebase_credentials] = lambda: cred
return app
app = create_app()
LOGLEVEL = os.environ.get("API_LOGLEVEL", "INFO").upper()
logging.basicConfig(
level=LOGLEVEL if LOGLEVEL != "" else "INFO",
format="%(levelname)s - %(asctime)s - %(name)s - %(message)s",
)
try:
deployer_data.initialize()
except OSError as error:
raise Exception(f"Cannot open file Deployer.json. detail: {error}")
except (KeyError, TypeError) as error:
raise Exception(f"File Deployer.json has invalid syntax. detail: {error}")