Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f704a23
translated swagger file to openapi3, added clkwithblocks upload support
Feb 5, 2020
d577c16
api file name changed
Feb 5, 2020
fb51125
api filename change
Feb 5, 2020
72f5ec8
shiny new openapi filename
Feb 5, 2020
6ea62a3
fix indentation
Feb 5, 2020
76afa6e
we need a newer version of connexion to support openapi3
Feb 5, 2020
8ecfb2d
new endpoint for uploading binary clks
Feb 5, 2020
b13f71f
modify tests to use new binary clks endpoint
Feb 5, 2020
7d0a963
openapi filename change
Feb 5, 2020
11bab45
Merge commit '03e491d6ce89e8def6151edff9b5398bbceaeadd' into feature_…
Feb 6, 2020
32bad8e
updated descriptions
Feb 6, 2020
9217096
fighting connexion again...
Feb 7, 2020
6d06aa9
I don't think the swagger-ui provides value
Feb 7, 2020
68481c9
clarifying the request format
Feb 10, 2020
87c90eb
translated swagger file to openapi3, added clkwithblocks upload support
Feb 5, 2020
9f3872b
api file name changed
Feb 5, 2020
395aeda
api filename change
Feb 5, 2020
3b70e7b
shiny new openapi filename
Feb 5, 2020
00d5bc4
fix indentation
Feb 5, 2020
f76a9a7
we need a newer version of connexion to support openapi3
Feb 5, 2020
d86a84b
new endpoint for uploading binary clks
Feb 5, 2020
d2ca6c6
modify tests to use new binary clks endpoint
Feb 5, 2020
ec70193
openapi filename change
Feb 5, 2020
eef4c4a
updated descriptions
Feb 6, 2020
bbdfae5
fighting connexion again...
Feb 7, 2020
777e42a
I don't think the swagger-ui provides value
Feb 7, 2020
9da2a74
clarifying the request format
Feb 10, 2020
6d6e3de
Merge branch 'feature_openapi3' of github.com:data61/anonlink-entity-…
Feb 10, 2020
798ed6f
changed to new binary upload endpoint
Feb 10, 2020
3486bc6
Merge branch 'develop' into feature_openapi3
wilko77 Feb 10, 2020
ff203c4
stop warning messages about missing swagger-ui
Feb 11, 2020
b60617b
feedback from PR
Feb 11, 2020
9d27fa2
merging...
Feb 11, 2020
919a427
clarify description
Feb 12, 2020
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
Prev Previous commit
Next Next commit
new endpoint for uploading binary clks
  • Loading branch information
wilko committed Feb 10, 2020
commit d86a84b08f5a81fee8de546f12ddae189bc64d7b
76 changes: 76 additions & 0 deletions backend/entityservice/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,82 @@ def project_get(project_id):
return ProjectDescription().dump(project_object)


def project_binaryclks_post(project_id):
"""
Update a project to provide encoded PII data.
"""
log = logger.bind(pid=project_id)
headers = request.headers

parent_span = g.flask_tracer.get_span()

with opentracing.tracer.start_span('check-auth', child_of=parent_span) as span:
abort_if_project_doesnt_exist(project_id)
if headers is None or 'Authorization' not in headers:
safe_fail_request(401, message="Authentication token required")

token = headers['Authorization']

# Check the caller has valid token -> otherwise 403
abort_if_invalid_dataprovider_token(token)

with DBConn() as conn:
dp_id = db.get_dataprovider_id(conn, token)
project_encoding_size = db.get_project_schema_encoding_size(conn, project_id)
upload_state_updated = db.is_dataprovider_allowed_to_upload_and_lock(conn, dp_id)

if not upload_state_updated:
return safe_fail_request(403, "This token has already been used to upload clks.")

log = log.bind(dp_id=dp_id)
log.info("Receiving CLK data.")
receipt_token = None

with opentracing.tracer.start_span('upload-clk-data', child_of=parent_span) as span:
span.set_tag("project_id", project_id)
try:
if headers['Content-Type'] == "application/octet-stream":
span.set_tag("content-type", 'binary')
log.info("Handling binary CLK upload")
try:
count, size = check_binary_upload_headers(headers)
log.info(f"Headers tell us to expect {count} encodings of {size} bytes")
span.log_kv({'count': count, 'size': size})
except Exception:
log.warning("Upload failed due to problem with headers in binary upload")
raise
# Check against project level encoding size (if it has been set)
if project_encoding_size is not None and size != project_encoding_size:
# fail fast - we haven't stored the encoded data yet
return safe_fail_request(400, "Upload 'Hash-Size' doesn't match project settings")

# TODO actually stream the upload data straight to Minio. Currently we can't because
# connexion has already read the data before our handler is called!
# https://github.com/zalando/connexion/issues/592
# stream = get_stream()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shame this hasn't been fixed :-/

stream = BytesIO(request.data)
expected_bytes = binary_format(size).size * count
log.debug(f"Stream size is {len(request.data)} B, and we expect {expected_bytes} B")
if len(request.data) != expected_bytes:
safe_fail_request(400,
"Uploaded data did not match the expected size. Check request headers are correct")
try:
receipt_token = upload_clk_data_binary(project_id, dp_id, stream, count, size)
except ValueError:
safe_fail_request(400,
"Uploaded data did not match the expected size. Check request headers are correct.")
else:
safe_fail_request(400, "Content Type not supported")
except Exception:
log.info("The dataprovider was not able to upload her clks,"
" re-enable the corresponding upload token to be used.")
with DBConn() as conn:
db.set_dataprovider_upload_state(conn, dp_id, state='error')
raise
with DBConn() as conn:
db.set_dataprovider_upload_state(conn, dp_id, state='done')
return {'message': 'Updated', 'receipt_token': receipt_token}, 201

def project_clks_post(project_id):
"""
Update a project to provide encoded PII data.
Expand Down