-
Notifications
You must be signed in to change notification settings - Fork 7
ensure media upload endpoints are one-off #392
base: master
Are you sure you want to change the base?
Conversation
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
2b55a26
to
2d31e18
Compare
# 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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 Report
@@ Coverage Diff @@
## master #392 +/- ##
=========================================
Coverage ? 91.32%
=========================================
Files ? 43
Lines ? 1949
Branches ? 0
=========================================
Hits ? 1780
Misses ? 169
Partials ? 0
Continue to review full report at Codecov.
|
There was a problem hiding this 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.'
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. |
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