diff --git a/taky/dps/__init__.py b/taky/dps/__init__.py index 587d582..9d76aaf 100644 --- a/taky/dps/__init__.py +++ b/taky/dps/__init__.py @@ -11,21 +11,26 @@ def requires_auth(func): """ - Function to ensure that a valid client certificate is submitted + Function to ensure that a valid client certificate is submitted if SSL is enabled """ - + @functools.wraps(func) def check_headers(*args, **kwargs): if not flask.request.headers.get("X-USER"): - flask.abort(401) + if app.config["SSL"] == True: + flask.abort(401) + else: + return func(*args, **kwargs) + if flask.request.headers.get("X-REVOKED"): flask.abort(403) return func(*args, **kwargs) - + return check_headers + def configure_app(config): app.config["HOSTNAME"] = config.get("taky", "hostname") app.config["NODEID"] = config.get("taky", "node_id") @@ -34,8 +39,10 @@ def configure_app(config): cot_port = config.getint("cot_server", "port") if config.getboolean("ssl", "enabled"): app.config["COT_CONN_STR"] = f'ssl:{app.config["HOSTNAME"]}:{cot_port}' + app.config["SSL"] = True else: app.config["COT_CONN_STR"] = f'tcp:{app.config["HOSTNAME"]}:{cot_port}' + app.config["SSL"] = False try: diff --git a/taky/dps/views/datapackage.py b/taky/dps/views/datapackage.py index b2d98c5..4826aa9 100644 --- a/taky/dps/views/datapackage.py +++ b/taky/dps/views/datapackage.py @@ -42,6 +42,9 @@ def put_meta(meta): # Save the file's meta/{filename}.json meta_path = os.path.join(app.config["UPLOAD_PATH"], "meta", f"{filename}.json") + # Create directories if they do not exist + os.makedirs(os.path.dirname(meta_path), exist_ok=True) + with open(meta_path, "w", encoding="utf8") as meta_fp: json.dump(meta, meta_fp) @@ -135,8 +138,12 @@ def datapackage_upload(): except: # pylint: disable=bare-except pass + # Save the uploaded file file_path = os.path.join(app.config["UPLOAD_PATH"], filename) + + # Create the directory if it doesn't exist + os.makedirs(os.path.dirname(file_path), exist_ok=True) asset_fp.save(file_path) sub_user = request.headers.get("X-USER", "Anonymous")