Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to upload datapackages when not using SSL #94

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions taky/dps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions taky/dps/views/datapackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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")
Expand Down