Skip to content

Conversation

@laxiwuka
Copy link
Contributor

No description provided.

@laxiwuka laxiwuka requested a review from soxofaan April 13, 2021 12:50
return None

def download_url(filename) -> str:
if os.getenv("SIGNED_URL", "FALSE").upper() == "TRUE":
Copy link
Member

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)

return _compute_secure_token(job_id, user.user_id, filename, expires)

def expiration_timestamp() -> Union[str, None]:
if 'SIGNED_URL_EXPIRATION' in os.environ:
Copy link
Member

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:

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

def secure_token(filename, expires) -> str:
return _compute_secure_token(job_id, user.user_id, filename, expires)

def expiration_timestamp() -> Union[str, None]:
Copy link
Member

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



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']
Copy link
Member

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

'type': 'Feature'
}

@mock.patch.dict(os.environ, {'SIGNED_URL': 'TRUE', 'SIGNED_URL_SECRET': '123&@#'})
Copy link
Member

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)

super().__init__(message=self.message.format(file=filename))


class FileExpiredException(OpenEOApiException):
Copy link
Member

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

see Open-EO/openeo-api#379

Copy link
Member

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)"
         )

Copy link
Member

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" ,
)

@soxofaan
Copy link
Member

FYI: Open-EO/openeo-api#380 is now merged in draft and the newly introduced error is

	"ResultLinkExpired": {
		"description": "The signed URLs for batch job results have expired. Please send a request to `GET /jobs/{job_id}/results` to refresh the links.",
		"message": "The link to the batch job result has expired. Please request the results again.",
		"http": 410,

so you could already adapt that error code ResultLinkExpired too

@soxofaan
Copy link
Member

is that bump of the openeo_driver/specs/openeo-api/0.4 submodule intentional?

@jdries jdries merged commit 5cb4160 into master Apr 20, 2021
@jdries jdries deleted the feature/EP-3769 branch April 20, 2021 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants