Compare commits

...

2 Commits

Author SHA1 Message Date
Tim Van Baak 6a92249ca2 Add some basic logging around auth 2021-02-18 19:03:45 -08:00
Tim Van Baak c89afe5b94 Change gunicorn to an optional dependency 2021-02-18 19:03:21 -08:00
4 changed files with 34 additions and 5 deletions

9
poetry.lock generated
View File

@ -50,10 +50,10 @@ WTForms = "*"
itsdangerous = "*"
[[package]]
category = "dev"
category = "main"
description = "WSGI HTTP Server for UNIX"
name = "gunicorn"
optional = false
optional = true
python-versions = ">=3.4"
version = "20.0.4"
@ -164,8 +164,11 @@ email = ["email-validator"]
ipaddress = ["ipaddress"]
locale = ["Babel (>=1.3)"]
[extras]
dev = ["gunicorn"]
[metadata]
content-hash = "5a3b077899ce6bd8f1a70c4fc48784486bb1373081d94c5b772191e7edb2788c"
content-hash = "e4930aaf62df0a261424129ab0d89af96ea4e19f80b76c7c6fbcb25c491a213d"
lock-version = "1.0"
python-versions = "^3.8"

View File

@ -9,10 +9,13 @@ python = "^3.8"
flask = "^1.1.2"
flask-login = "^0.5.0"
flask_wtf = "^0.14.3"
gunicorn = {version = "^20.0.4", optional = true}
[tool.poetry.dev-dependencies]
mypy = "^0.800"
gunicorn = "^20.0.4"
[tool.poetry.extras]
dev = ["gunicorn"]
[tool.poetry.scripts]
redstring-check = "redstring.parser:main"

View File

@ -1,2 +1,14 @@
import logging
import redstring.parser
import redstring.server
formatter = logging.Formatter('[{asctime}] [{process}] [{levelname}] {message}', '%Y-%m-%d %H:%M:%S %z', style='{')
handler = logging.StreamHandler()
handler.setFormatter(formatter)
handler.setLevel(logging.DEBUG)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)

View File

@ -3,6 +3,7 @@ Logic for serving a collection of documents through a web frontend.
"""
import argparse
import json
import logging
import os
import random
import string
@ -47,6 +48,8 @@ class LoginForm(FlaskForm):
CONFIG_ENVVAR = 'REDSTRING_CONFIG'
logger = logging.getLogger(__name__)
app = Flask(__name__)
app.secret_key = ''.join(random.choices(string.ascii_uppercase + string.digits, k=32))
@ -60,10 +63,16 @@ def check_password(app, password):
Checks if a password is correct
"""
password_file = app.config['password_file']
if not os.path.isfile(password_file):
logger.debug('Authentication failed: no password file found')
with open(password_file) as f:
real_password = f.read().strip()
correct = password == real_password
del real_password
if correct:
logger.debug('Authentication successful')
else:
logger.debug('Authentication failed: password incorrect')
return correct
@ -223,4 +232,6 @@ def cli():
def wsgi():
config_path = os.environ.get(CONFIG_ENVVAR) or '/etc/redstring.conf'
config = read_config(app, config_path)
logger.setLevel(logging.DEBUG)
logger.debug(f'Loaded config from {config_path}: {config}')
return app