Skip to content

Commit

Permalink
Merge pull request #85 from Open-EO/fix/remove_vo_role_check
Browse files Browse the repository at this point in the history
Fix - remove VO role check
  • Loading branch information
zansinergise authored Aug 14, 2024
2 parents 439b9bb + d15e502 commit 1fb97b1
Show file tree
Hide file tree
Showing 10 changed files with 749 additions and 642 deletions.
1 change: 1 addition & 0 deletions rest/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ zarr = "*"
netcdf4 = "*"
pip-tools = "==6.1.0"
werkzeug = "==2.3.7"
colorama = "==0.4.4"
1,348 changes: 719 additions & 629 deletions rest/Pipfile.lock

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions rest/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
get_batch_job_status,
create_or_get_estimate_values_from_db,
)
from processing.const import SH_PU_TO_PLATFORM_CREDIT_CONVERSION_RATE
from post_processing.post_processing import parse_sh_gtiff_to_format
from processing.utils import inject_variables_in_process_graph, overwrite_spatial_extent_without_parameters
from processing.openeo_process_errors import OpenEOProcessError
Expand Down Expand Up @@ -495,7 +496,10 @@ def api_batch_job(job_id):
if status is not openEOBatchJobStatus.CREATED:
data_to_jsonify["costs"] = float(job.get("sum_costs", 0))
data_to_jsonify["usage"] = {
"Platform Credits": {"unit": "credits", "value": round(float(job.get("sum_costs", 0)) * 0.15, 3)},
"Platform Credits": {
"unit": "credits",
"value": round(float(job.get("sum_costs", 0)) * SH_PU_TO_PLATFORM_CREDIT_CONVERSION_RATE, 3),
},
"Sentinel Hub": {
"unit": "sentinelhub_processing_unit",
"value": float(job.get("sum_costs", 0)),
Expand Down Expand Up @@ -531,7 +535,9 @@ def api_batch_job(job_id):
estimated_sentinelhub_pu, estimated_file_size = get_batch_job_estimate(
new_batch_request_id, data.get("process"), deployment_endpoint
)
estimated_platform_credits = round(estimated_sentinelhub_pu * 0.15, 3)
estimated_platform_credits = round(
estimated_sentinelhub_pu * SH_PU_TO_PLATFORM_CREDIT_CONVERSION_RATE, 3
)
JobsPersistence.update_key(
job["id"], "estimated_sentinelhub_pu", str(round(estimated_sentinelhub_pu, 3))
)
Expand Down
3 changes: 0 additions & 3 deletions rest/authentication/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ def authenticate_user_oidc(self, access_token, oidc_provider_id):
except BillingPlanInvalid:
return None

if not user.is_in_group("vo.openeo.cloud"):
return None

return user

def authenticate_user_basic(self, access_token):
Expand Down
4 changes: 1 addition & 3 deletions rest/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ def get_billing_plan(entitlements):
free_plan_supported = False

for entitlement in entitlements:
if entitlement["namespace"] in ("urn:mace:egi.eu", "urn:mace:egi-dev.eu") and entitlement["group"] in (
"vo.openeo.cloud"
):
if entitlement["namespace"] in ("urn:mace:egi.eu", "urn:mace:egi-dev.eu"):
if entitlement["role"].lower() in ("early_adopter", "early-adopter", "earlyadopter"):
return OpenEOPBillingPlan.EARLY_ADOPTER
free_plan_supported = True
Expand Down
2 changes: 2 additions & 0 deletions rest/processing/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,5 @@ def get_unsupported_mimetype_message(self):
ProcessingRequestTypes.BATCH: "Currently supported formats for batch processing jobs are GTIFF, NETCDF and ZARR.",
ProcessingRequestTypes.SYNC: "Currently supported formats for synchronous processing jobs are GTIFF, PNG and JPEG.",
}

SH_PU_TO_PLATFORM_CREDIT_CONVERSION_RATE = 0.15 # platform credits === SH PU's * 0.15
12 changes: 9 additions & 3 deletions rest/processing/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flask import g
from sentinelhub import BatchRequestStatus, BatchUserAction, SentinelHubBatch

from processing.const import ProcessingRequestTypes
from processing.const import ProcessingRequestTypes, SH_PU_TO_PLATFORM_CREDIT_CONVERSION_RATE
from processing.process import Process
from processing.sentinel_hub import SentinelHub
from processing.partially_supported_processes import partially_supported_processes
Expand Down Expand Up @@ -48,6 +48,12 @@ def new_sentinel_hub(deployment_endpoint=None):

def process_data_synchronously(process, width=None, height=None):
p = new_process(process, width=width, height=height, request_type=ProcessingRequestTypes.SYNC)

# As we don't know before the execution of a sync job how much it will cost, we can check
# if the user has X amount of credits that will most likely cover the execution costs
ten_credits_as_pu = 10 / SH_PU_TO_PLATFORM_CREDIT_CONVERSION_RATE
check_leftover_credits(ten_credits_as_pu)

return p.execute_sync(), p.mimetype.get_string()


Expand Down Expand Up @@ -224,7 +230,7 @@ def create_or_get_estimate_values_from_db(job, batch_request_id):
estimated_sentinelhub_pu, estimated_file_size = get_batch_job_estimate(
batch_request_id, json.loads(job["process"]), job["deployment_endpoint"]
)
estimated_platform_credits = round(estimated_sentinelhub_pu * 0.15, 3)
estimated_platform_credits = round(estimated_sentinelhub_pu * SH_PU_TO_PLATFORM_CREDIT_CONVERSION_RATE, 3)
JobsPersistence.update_key(job["id"], "estimated_sentinelhub_pu", str(round(estimated_sentinelhub_pu, 3)))
JobsPersistence.update_key(job["id"], "estimated_platform_credits", str(estimated_platform_credits))
JobsPersistence.update_key(job["id"], "estimated_file_size", str(estimated_file_size))
Expand All @@ -238,6 +244,6 @@ def create_or_get_estimate_values_from_db(job, batch_request_id):

def check_leftover_credits(estimated_pu):
leftover_credits = g.user.get_leftover_credits()
estimated_pu_as_credits = estimated_pu * 0.15 # platform credits === SH PU's * 0.15
estimated_pu_as_credits = estimated_pu * SH_PU_TO_PLATFORM_CREDIT_CONVERSION_RATE
if leftover_credits is not None and leftover_credits < estimated_pu_as_credits:
raise InsufficientCredits()
5 changes: 5 additions & 0 deletions tests/setup_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ def decorated_function(*args, **kwargs):
}
],
),
responses.add(
responses.GET,
"https://etl.terrascope.be/user",
json={"credits": 50},
),

responses.add_passthru(re.compile(".*"))
return func(*args, **kwargs)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,7 @@ def request_callback(request):


@with_mocked_auth
@with_mocked_reporting
@pytest.mark.parametrize(
"spatial_extent,temporal_extent",
[
Expand Down Expand Up @@ -1882,6 +1883,7 @@ def test_describe_account(app_client, example_authorization_header_with_oidc):


@with_mocked_auth
@with_mocked_reporting
@pytest.mark.parametrize(
"spatial_extent, is_error",
[
Expand Down
4 changes: 2 additions & 2 deletions tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def test_collections_provider(url, directory, expected_collection_ids):
],
},
{"Authorization": "Bearer oidc/egi/<token>"},
True,
CredentialsInvalid,
False,
None,
None,
),
(
Expand Down

0 comments on commit 1fb97b1

Please sign in to comment.