-
Notifications
You must be signed in to change notification settings - Fork 6
1111 return stac11 items #411
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
base: master
Are you sure you want to change the base?
Changes from all commits
488e95c
26c99fd
24a6a29
9398d35
67301fc
9374765
3df0a5e
7aeca37
eea9cb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1160,16 +1160,20 @@ def job_results_canonical_url() -> str: | |||||
if TREAT_JOB_RESULTS_V100_LIKE_V110 or requested_api_version().at_least("1.1.0"): | ||||||
ml_model_metadata = None | ||||||
|
||||||
def job_result_item_url(item_id) -> str: | ||||||
def job_result_item_url(item_id, is11 = False) -> str: | ||||||
signer = get_backend_config().url_signer | ||||||
|
||||||
method_start = ".get_job_result_item" | ||||||
if is11: | ||||||
method_start = method_start + "11" | ||||||
if not signer: | ||||||
return url_for(".get_job_result_item", job_id=job_id, item_id=item_id, _external=True) | ||||||
return url_for(method_start, job_id=job_id, item_id=item_id, _external=True) | ||||||
|
||||||
expires = signer.get_expires() | ||||||
secure_key = signer.sign_job_item(job_id=job_id, user_id=user_id, item_id=item_id, expires=expires) | ||||||
user_base64 = user_id_b64_encode(user_id) | ||||||
return url_for( | ||||||
".get_job_result_item_signed", | ||||||
method_start + "_signed", | ||||||
job_id=job_id, | ||||||
user_base64=user_base64, | ||||||
secure_key=secure_key, | ||||||
|
@@ -1178,19 +1182,32 @@ def job_result_item_url(item_id) -> str: | |||||
_external=True, | ||||||
) | ||||||
|
||||||
for filename, metadata in result_assets.items(): | ||||||
if ("data" in metadata.get("roles", []) and | ||||||
any(media_type in metadata.get("type", "") for media_type in | ||||||
["geotiff", "netcdf", "text/csv", "application/parquet"])): | ||||||
links.append( | ||||||
{"rel": "item", "href": job_result_item_url(item_id=filename), "type": stac_item_media_type} | ||||||
) | ||||||
elif metadata.get("ml_model_metadata", False): | ||||||
# TODO: Currently we only support one ml_model per batch job. | ||||||
ml_model_metadata = metadata | ||||||
|
||||||
if len(result_metadata.items) > 0 : | ||||||
for item_id, metadata in result_metadata.items.items(): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
links.append( | ||||||
{"rel": "item", "href": job_result_item_url(item_id=filename), "type": "application/json"} | ||||||
{"rel": "item", "href": job_result_item_url(item_id=item_id, is11=True), "type": stac_item_media_type} | ||||||
) | ||||||
for asset_key, asset in metadata.get("assets").items(): | ||||||
links.append( | ||||||
{"rel": "item", "href": job_result_item_url(item_id=asset.get("href")), | ||||||
"type": stac_item_media_type} | ||||||
) | ||||||
else: | ||||||
|
||||||
for filename, metadata in result_assets.items(): | ||||||
if ("data" in metadata.get("roles", []) and | ||||||
any(media_type in metadata.get("type", "") for media_type in | ||||||
["geotiff", "netcdf", "text/csv", "application/parquet"])): | ||||||
links.append( | ||||||
{"rel": "item", "href": job_result_item_url(item_id=filename), "type": stac_item_media_type} | ||||||
) | ||||||
elif metadata.get("ml_model_metadata", False): | ||||||
# TODO: Currently we only support one ml_model per batch job. | ||||||
ml_model_metadata = metadata | ||||||
links.append( | ||||||
{"rel": "item", "href": job_result_item_url(item_id=filename), "type": "application/json"} | ||||||
) | ||||||
|
||||||
result = dict_no_none( | ||||||
{ | ||||||
|
@@ -1357,11 +1374,43 @@ def get_job_result_item_signed(job_id, user_base64, secure_key, item_id): | |||||
signer.verify_job_item(signature=secure_key, job_id=job_id, user_id=user_id, item_id=item_id, expires=expires) | ||||||
return _get_job_result_item(job_id, item_id, user_id) | ||||||
|
||||||
@api_endpoint | ||||||
@blueprint.route('/jobs/<job_id>/results/items11/<user_base64>/<secure_key>/<item_id>', methods=['GET']) | ||||||
def get_job_result_item11_signed(job_id, user_base64, secure_key, item_id): | ||||||
expires = request.args.get('expires') | ||||||
signer = get_backend_config().url_signer | ||||||
user_id = user_id_b64_decode(user_base64) | ||||||
signer.verify_job_item(signature=secure_key, job_id=job_id, user_id=user_id, item_id=item_id, expires=expires) | ||||||
return _get_job_result_item11(job_id, item_id, user_id) | ||||||
|
||||||
@blueprint.route('/jobs/<job_id>/results/items/<item_id>', methods=['GET']) | ||||||
@auth_handler.requires_bearer_auth | ||||||
def get_job_result_item(job_id: str, item_id: str, user: User) -> flask.Response: | ||||||
return _get_job_result_item(job_id, item_id, user.user_id) | ||||||
|
||||||
@api_endpoint(version=ComparableVersion("1.1.0").or_higher) | ||||||
@blueprint.route('/jobs/<job_id>/results/items11/<item_id>', methods=['GET']) | ||||||
@auth_handler.requires_bearer_auth | ||||||
def get_job_result_item11(job_id: str, item_id: str, user: User) -> flask.Response: | ||||||
return _get_job_result_item11(job_id, item_id, user.user_id) | ||||||
|
||||||
def _get_job_result_item11(job_id, item_id, user_id): | ||||||
if item_id == DriverMlModel.METADATA_FILE_NAME: | ||||||
return _download_ml_model_metadata(job_id, item_id, user_id) | ||||||
Comment on lines
+1398
to
+1399
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this ever be the case? |
||||||
|
||||||
metadata = backend_implementation.batch_jobs.get_result_metadata( | ||||||
job_id=job_id, user_id=user_id | ||||||
) | ||||||
|
||||||
if item_id not in metadata.items: | ||||||
raise OpenEOApiException("Item with id {item_id!r} not found in job {job_id!r}".format(item_id=item_id, job_id=job_id), status_code=404) | ||||||
item_metadata = metadata.items.get(item_id,None) | ||||||
|
||||||
resp = jsonify(item_metadata) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basic, will probably require more work e.g. sign its asset URLs? |
||||||
resp.mimetype = stac_item_media_type | ||||||
return resp | ||||||
|
||||||
|
||||||
def _get_job_result_item(job_id, item_id, user_id): | ||||||
if item_id == DriverMlModel.METADATA_FILE_NAME: | ||||||
return _download_ml_model_metadata(job_id, item_id, user_id) | ||||||
|
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.
Is it possible to avoid a new endpoint (
/jobs/<job_id>/results/items11/<item_id>
)? I suppose the original_get_job_result_item
method can also check whether the item ID corresponds to either: