Skip to content
This repository was archived by the owner on Mar 21, 2019. It is now read-only.

ensure media upload endpoints are one-off #392

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rjw57
Copy link
Member

@rjw57 rjw57 commented Nov 19, 2018

JWP media upload endpoints are one-use-only URLs. Unfortunately we allowed the same URL to be retrieved multiple times from the upload endpoint which meant that a client may try to upload a media item multiple times to the same URL.

Fix this by making the /media/{id}/upload endpoint a PUT-only endpoint. If the upload endpoint URL exists in the database to begin with, we return it and delete it from the database. If the endpoint does not exist, we create one first.

This involves a bit of an unnecessary write and then delete from the database in the case where the endpoint does not exist but for the common case of "create media item" then "get upload endpoint", it Does The Right Thing (TM).

Closes #367

@rjw57 rjw57 requested a review from a team November 19, 2018 15:40
@rjw57 rjw57 self-assigned this Nov 19, 2018
JWP media upload endpoints are one-use-only URLs. Unfortunately we
allowed the same URL to be retrieved multiple times from the upload
endpoint which meant that a client may try to upload a media item
multiple times to the same URL.

Fix this by making the /media/{id}/upload endpoint a PUT-only endpoint.
If the upload endpoint URL exists in the database to begin with, we
return it and delete it from the database. If the endpoint does not
exist, we create one first.

This involves a bit of an unnecessary write and then delete from the
database in the case where the endpoint does not exist but for the
common case of "create media item" then "get upload endpoint", it Does
The Right Thing (TM).

Closes #367
@rjw57 rjw57 force-pushed the issue-367-one-off-upload-endpoints branch from 2b55a26 to 2d31e18 Compare November 19, 2018 15:41
# If there is already a created upload endpoint which expires more than a day from now,
# we can use the instance as is.
if hasattr(instance, 'upload_endpoint'):
headroom = datetime.timedelta(days=1)
Copy link
Member

Choose a reason for hiding this comment

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

will this code ever get executed if the we always delete the instance from the database after we create it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes as an upload endpoint is created by JWP when we first create the media resource. See the last line of mediaplatform_jwp.api.management._perform_item_update().

@codecov
Copy link

codecov bot commented Nov 20, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@76a8891). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #392   +/-   ##
=========================================
  Coverage          ?   91.32%           
=========================================
  Files             ?       43           
  Lines             ?     1949           
  Branches          ?        0           
=========================================
  Hits              ?     1780           
  Misses            ?      169           
  Partials          ?        0
Impacted Files Coverage Δ
api/serializers.py 97.87% <100%> (ø)
api/views.py 95.18% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 76a8891...3802a13. Read the comment docs.

@abrahammartin abrahammartin self-requested a review November 22, 2018 09:28
@abrahammartin abrahammartin self-requested a review November 22, 2018 13:12
Copy link
Member

@abrahammartin abrahammartin left a comment

Choose a reason for hiding this comment

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

Executing a second PUT to the uploads API makes it fail. The error raised by the JWPlayer API is: JWPlatformPreconditionFailedError
'Video must have status ready or failed before its original file can be updated. Current status is: processing.'

@rjw57
Copy link
Member Author

rjw57 commented Mar 6, 2019

If the PUT succeeds after JWP has finished processing, I'd be inclined to call that good enough to fix the issue for the moment. We're likely to migrate away from JWP so re-woking all the API plumbing to support it is probably left for another issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants