Add some basic logging around auth
This commit is contained in:
parent
c89afe5b94
commit
6a92249ca2
|
@ -1,2 +1,14 @@
|
|||
import logging
|
||||
|
||||
import redstring.parser
|
||||
import redstring.server
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue