mirror of https://gitlab.com/litecord/litecord.git
Compare commits
No commits in common. "83179f21ab4cb620348c506ec6d2cab9d35690fd" and "610b7e9811cf5fcab10eec8fe89184cef7789d7b" have entirely different histories.
83179f21ab
...
610b7e9811
|
|
@ -18,6 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from logbook import Logger
|
||||||
|
|
||||||
|
|
||||||
|
log = Logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
MODE = "Development"
|
MODE = "Development"
|
||||||
|
|
@ -72,8 +76,22 @@ class Config:
|
||||||
#: Shared secret for LVSP
|
#: Shared secret for LVSP
|
||||||
LVSP_SECRET = ""
|
LVSP_SECRET = ""
|
||||||
|
|
||||||
ADMIN_ID = None
|
#: Admin credentials for automated testing
|
||||||
ADMIN_TOKEN = None
|
# The token is the value to pass in the Authorization header, and the ID
|
||||||
|
# is the user ID to use when it is passed.
|
||||||
|
ADMIN_ID = os.getenv("ADMIN_ID")
|
||||||
|
ADMIN_TOKEN = os.getenv("ADMIN_TOKEN")
|
||||||
|
|
||||||
|
if None in {ADMIN_ID, ADMIN_TOKEN} and not ADMIN_ID == ADMIN_TOKEN:
|
||||||
|
log.warning(
|
||||||
|
"Not both admin ID ({}) and token ({}) configured; ignoring",
|
||||||
|
ADMIN_ID,
|
||||||
|
ADMIN_TOKEN,
|
||||||
|
)
|
||||||
|
ADMIN_ID = ADMIN_TOKEN = None
|
||||||
|
|
||||||
|
if ADMIN_ID is not None:
|
||||||
|
ADMIN_ID = int(ADMIN_ID)
|
||||||
|
|
||||||
|
|
||||||
class Development(Config):
|
class Development(Config):
|
||||||
|
|
@ -86,12 +104,6 @@ class Development(Config):
|
||||||
"database": "litecord",
|
"database": "litecord",
|
||||||
}
|
}
|
||||||
|
|
||||||
ADMIN_ID = os.getenv("ADMIN_ID")
|
|
||||||
ADMIN_TOKEN = os.getenv("ADMIN_TOKEN")
|
|
||||||
|
|
||||||
if ADMIN_ID is not None:
|
|
||||||
ADMIN_ID = int(ADMIN_ID)
|
|
||||||
|
|
||||||
|
|
||||||
class Production(Config):
|
class Production(Config):
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import binascii
|
import binascii
|
||||||
from hmac import compare_digest
|
|
||||||
|
|
||||||
import bcrypt
|
import bcrypt
|
||||||
from itsdangerous import TimestampSigner, BadSignature
|
from itsdangerous import TimestampSigner, BadSignature
|
||||||
|
|
@ -48,9 +47,7 @@ async def raw_token_check(token: str, db=None) -> int:
|
||||||
Forbidden
|
Forbidden
|
||||||
If token validation fails.
|
If token validation fails.
|
||||||
"""
|
"""
|
||||||
if app.config["ADMIN_TOKEN"] is not None and compare_digest(
|
if app.config["ADMIN_TOKEN"] is not None:
|
||||||
token, app.config["ADMIN_TOKEN"]
|
|
||||||
):
|
|
||||||
return app.config["ADMIN_ID"]
|
return app.config["ADMIN_ID"]
|
||||||
|
|
||||||
db = db or app.db
|
db = db or app.db
|
||||||
|
|
|
||||||
15
run.py
15
run.py
|
|
@ -122,22 +122,7 @@ redirect_logging()
|
||||||
|
|
||||||
def make_app():
|
def make_app():
|
||||||
app = Quart(__name__)
|
app = Quart(__name__)
|
||||||
|
|
||||||
app.config.from_object(f"config.{config.MODE}")
|
app.config.from_object(f"config.{config.MODE}")
|
||||||
|
|
||||||
admin_id, admin_token = app.config["ADMIN_ID"], app.config["ADMIN_TOKEN"]
|
|
||||||
if None in {admin_id, admin_token} and not admin_id == admin_token:
|
|
||||||
log.warning(
|
|
||||||
"Not both admin ID ({}) and token ({}) configured; ignoring",
|
|
||||||
admin_id,
|
|
||||||
admin_token,
|
|
||||||
)
|
|
||||||
admin_id = admin_token = None
|
|
||||||
|
|
||||||
# update config if the variables were updated
|
|
||||||
app.config["ADMIN_ID"] = admin_id
|
|
||||||
app.config["ADMIN_TOKEN"] = admin_token
|
|
||||||
|
|
||||||
is_debug = app.config.get("DEBUG", False)
|
is_debug = app.config.get("DEBUG", False)
|
||||||
app.debug = is_debug
|
app.debug = is_debug
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue