From 58709ebca01940b57527664adf6ad0309d6dd980 Mon Sep 17 00:00:00 2001 From: Jan Friedli Date: Sun, 30 Aug 2020 14:44:41 +0200 Subject: added more logging for the helpers and the frontend --- matweb/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'matweb/utils.py') diff --git a/matweb/utils.py b/matweb/utils.py index 915d735..ea84f4f 100644 --- a/matweb/utils.py +++ b/matweb/utils.py @@ -3,7 +3,7 @@ import os import hashlib import mimetypes as mtype -from flask_restful import abort +from flask_restful import abort, current_app from libmat2 import parser_factory from werkzeug.utils import secure_filename @@ -31,6 +31,7 @@ def hash_file(filepath: str, secret: str) -> str: def check_upload_folder(upload_folder): if not os.path.exists(upload_folder): + current_app.logger.info('Upload folder does not exist - creating it') os.mkdir(upload_folder) @@ -98,14 +99,17 @@ def get_file_paths(filename, upload_folder): def is_valid_api_download_file(filename: str, key: str, secret: str, upload_folder: str) -> [str, str]: if filename != secure_filename(filename): + current_app.logger.error('Insecure filename %', filename) abort(400, message='Insecure filename') complete_path, filepath = get_file_paths(filename, upload_folder) if not os.path.exists(complete_path): + current_app.logger.error('File not found') abort(404, message='File not found') if hmac.compare_digest(hash_file(complete_path, secret), key) is False: + current_app.logger.error('The file hash does not match') abort(400, message='The file hash does not match') return complete_path, filepath -- cgit v1.3