-
Notifications
You must be signed in to change notification settings - Fork 6
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
Download results with signed url's #63
Conversation
…iration timestamp
openeo_driver/views.py
Outdated
return None | ||
|
||
def download_url(filename) -> str: | ||
if os.getenv("SIGNED_URL", "FALSE").upper() == "TRUE": |
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.
use smart_bool
(imported already here from openeo_driver.utils
)
openeo_driver/views.py
Outdated
return _compute_secure_token(job_id, user.user_id, filename, expires) | ||
|
||
def expiration_timestamp() -> Union[str, None]: | ||
if 'SIGNED_URL_EXPIRATION' in os.environ: |
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.
I think it's cleaner to use current_app.config
instead of os.environ
(see usage in other places of views.py)
this config is populated here:
openeo-python-driver/openeo_driver/server.py
Lines 19 to 23 in 5c1e927
app.config['OPENEO_BACKEND_VERSION'] = backend_version | |
app.config['OPENEO_TITLE'] = title | |
app.config['OPENEO_DESCRIPTION'] = description | |
app.config['OPENEO_BACKEND_DEPLOY_METADATA'] = deploy_metadata | |
app.config['MAX_CONTENT_LENGTH'] = 1024 * 1024 # bytes |
at this place you could get the values from
os.environ
. I would just avoid using os.environ in views.py directly
openeo_driver/views.py
Outdated
def secure_token(filename, expires) -> str: | ||
return _compute_secure_token(job_id, user.user_id, filename, expires) | ||
|
||
def expiration_timestamp() -> Union[str, None]: |
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.
expiration timestamp return value can still be int at this point I think
openeo_driver/views.py
Outdated
|
||
|
||
def _compute_secure_token(job_id, user_id, filename, expiration_timestamp): | ||
token_key = job_id + user_id + filename + str(expiration_timestamp) + os.environ['SIGNED_URL_SECRET'] |
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.
see above: avoid os.environ here
tests/test_views.py
Outdated
@@ -864,6 +864,138 @@ def test_get_job_results_100(self, api100): | |||
'type': 'Feature' | |||
} | |||
|
|||
@mock.patch.dict(os.environ, {'SIGNED_URL': 'TRUE', 'SIGNED_URL_SECRET': '123&@#'}) |
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.
regarding the avoiding of os.environ
not of above: I think you can just do @mock.patch.dict(app.config, {'SIG...
here (app
object is already available at this point)
openeo_driver/errors.py
Outdated
@@ -215,6 +215,17 @@ def __init__(self, filename: str): | |||
super().__init__(message=self.message.format(file=filename)) | |||
|
|||
|
|||
class FileExpiredException(OpenEOApiException): |
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.
New errors in this file have first to be defined through https://github.com/Open-EO/openeo-api/blob/master/errors.json
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.
in the mean time, you can just raise a generic exception:
raise OpenEOApiException(
status_code=410,
code="FileExpired",
message="File '{file}' has expired".format(file=filename)"
)
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.
Interesting suggestion from Open-EO/openeo-api#379 (comment):
raise it with something like:
raise OpenEOApiException(
status_code=410,
code="AssetLinkExpired",
message="Batch job asset link has expired. Request the batch job results again for fresh asset links" ,
)
FYI: Open-EO/openeo-api#380 is now merged in draft and the newly introduced error is
so you could already adapt that error code |
is that bump of the openeo_driver/specs/openeo-api/0.4 submodule intentional? |
No description provided.