/
info.py
85 lines (60 loc) · 2.11 KB
/
info.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
81
82
83
84
85
"""info.py
Informational endpoints
"""
# Standard Library
import re
# Third Party
import fastapi
from fastapi import APIRouter, Depends
from loguru import logger
# Local
import bel.core.settings as settings
import bel.terms.terms
from bel.__version__ import __version__ as bel_lib_version
from bel.schemas.info import Status, Version
router = APIRouter()
@router.get("/status", tags=["Info"], response_model=Status)
def get_status():
"""Get status"""
status = {
"state": "OK",
"bel_lib_version": bel_lib_version,
"fastapi_version": fastapi.__version__,
# "settings": settings.show_settings(),
# "elasticsearch_stats": bel.terms.terms.namespace_term_counts(),
}
return status
@router.get("/version", tags=["Info"], response_model=Version)
def get_version():
"""Get Version"""
return {"version": bel_lib_version}
# @router.get("/settings", tags=["Info"], response_model=dict)
# def get_settings():
# """ Settings
# Any uppercased attributes in the settings module will be exposed in this endpoint.
# Any settings.secrets that are cast as a Secret will be masked.
# Any URLs that are cast as a URL will have embedded passwords in the url string masked.
# """
# return settings.show_settings()
@router.get("/ping", tags=["Info"])
def ping() -> dict:
"""Check service - no authentication/token required"""
return {"running": True}
@router.get("/settings", tags=["Info"], response_model=dict)
def get_settings():
"""Settings
Only show UPPER_CASED settings that do not have ['SECRET', 'TOKEN', 'PASSWORD', 'PASSWD'] in the name
"""
"""Show settable settings via .env file or environment
- Only show UPPER_CASED settings that do not have ['SECRET', 'TOKEN', 'PASSWORD', 'PASSWD'] in the name
"""
skip_list = ["SECRET", "TOKEN", "PASSWD", "PASSWORD"]
try:
s = {
var: getattr(settings, var)
for var in dir(settings)
if var.isupper() and not re.search("SECRET|TOKEN|PASSWD|PASSWORD", var)
}
except Exception as e:
print("Error", str(e))
return s