Skip to content

Commit 1fb97b1

Browse files
authored
Merge pull request #85 from Open-EO/fix/remove_vo_role_check
Fix - remove VO role check
2 parents 439b9bb + d15e502 commit 1fb97b1

File tree

10 files changed

+749
-642
lines changed

10 files changed

+749
-642
lines changed

rest/Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ zarr = "*"
3333
netcdf4 = "*"
3434
pip-tools = "==6.1.0"
3535
werkzeug = "==2.3.7"
36+
colorama = "==0.4.4"

rest/Pipfile.lock

Lines changed: 719 additions & 629 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rest/app.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
get_batch_job_status,
4141
create_or_get_estimate_values_from_db,
4242
)
43+
from processing.const import SH_PU_TO_PLATFORM_CREDIT_CONVERSION_RATE
4344
from post_processing.post_processing import parse_sh_gtiff_to_format
4445
from processing.utils import inject_variables_in_process_graph, overwrite_spatial_extent_without_parameters
4546
from processing.openeo_process_errors import OpenEOProcessError
@@ -495,7 +496,10 @@ def api_batch_job(job_id):
495496
if status is not openEOBatchJobStatus.CREATED:
496497
data_to_jsonify["costs"] = float(job.get("sum_costs", 0))
497498
data_to_jsonify["usage"] = {
498-
"Platform Credits": {"unit": "credits", "value": round(float(job.get("sum_costs", 0)) * 0.15, 3)},
499+
"Platform Credits": {
500+
"unit": "credits",
501+
"value": round(float(job.get("sum_costs", 0)) * SH_PU_TO_PLATFORM_CREDIT_CONVERSION_RATE, 3),
502+
},
499503
"Sentinel Hub": {
500504
"unit": "sentinelhub_processing_unit",
501505
"value": float(job.get("sum_costs", 0)),
@@ -531,7 +535,9 @@ def api_batch_job(job_id):
531535
estimated_sentinelhub_pu, estimated_file_size = get_batch_job_estimate(
532536
new_batch_request_id, data.get("process"), deployment_endpoint
533537
)
534-
estimated_platform_credits = round(estimated_sentinelhub_pu * 0.15, 3)
538+
estimated_platform_credits = round(
539+
estimated_sentinelhub_pu * SH_PU_TO_PLATFORM_CREDIT_CONVERSION_RATE, 3
540+
)
535541
JobsPersistence.update_key(
536542
job["id"], "estimated_sentinelhub_pu", str(round(estimated_sentinelhub_pu, 3))
537543
)

rest/authentication/authentication.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ def authenticate_user_oidc(self, access_token, oidc_provider_id):
6767
except BillingPlanInvalid:
6868
return None
6969

70-
if not user.is_in_group("vo.openeo.cloud"):
71-
return None
72-
7370
return user
7471

7572
def authenticate_user_basic(self, access_token):

rest/const.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ def get_billing_plan(entitlements):
9292
free_plan_supported = False
9393

9494
for entitlement in entitlements:
95-
if entitlement["namespace"] in ("urn:mace:egi.eu", "urn:mace:egi-dev.eu") and entitlement["group"] in (
96-
"vo.openeo.cloud"
97-
):
95+
if entitlement["namespace"] in ("urn:mace:egi.eu", "urn:mace:egi-dev.eu"):
9896
if entitlement["role"].lower() in ("early_adopter", "early-adopter", "earlyadopter"):
9997
return OpenEOPBillingPlan.EARLY_ADOPTER
10098
free_plan_supported = True

rest/processing/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,5 @@ def get_unsupported_mimetype_message(self):
9292
ProcessingRequestTypes.BATCH: "Currently supported formats for batch processing jobs are GTIFF, NETCDF and ZARR.",
9393
ProcessingRequestTypes.SYNC: "Currently supported formats for synchronous processing jobs are GTIFF, PNG and JPEG.",
9494
}
95+
96+
SH_PU_TO_PLATFORM_CREDIT_CONVERSION_RATE = 0.15 # platform credits === SH PU's * 0.15

rest/processing/processing.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from flask import g
66
from sentinelhub import BatchRequestStatus, BatchUserAction, SentinelHubBatch
77

8-
from processing.const import ProcessingRequestTypes
8+
from processing.const import ProcessingRequestTypes, SH_PU_TO_PLATFORM_CREDIT_CONVERSION_RATE
99
from processing.process import Process
1010
from processing.sentinel_hub import SentinelHub
1111
from processing.partially_supported_processes import partially_supported_processes
@@ -48,6 +48,12 @@ def new_sentinel_hub(deployment_endpoint=None):
4848

4949
def process_data_synchronously(process, width=None, height=None):
5050
p = new_process(process, width=width, height=height, request_type=ProcessingRequestTypes.SYNC)
51+
52+
# As we don't know before the execution of a sync job how much it will cost, we can check
53+
# if the user has X amount of credits that will most likely cover the execution costs
54+
ten_credits_as_pu = 10 / SH_PU_TO_PLATFORM_CREDIT_CONVERSION_RATE
55+
check_leftover_credits(ten_credits_as_pu)
56+
5157
return p.execute_sync(), p.mimetype.get_string()
5258

5359

@@ -224,7 +230,7 @@ def create_or_get_estimate_values_from_db(job, batch_request_id):
224230
estimated_sentinelhub_pu, estimated_file_size = get_batch_job_estimate(
225231
batch_request_id, json.loads(job["process"]), job["deployment_endpoint"]
226232
)
227-
estimated_platform_credits = round(estimated_sentinelhub_pu * 0.15, 3)
233+
estimated_platform_credits = round(estimated_sentinelhub_pu * SH_PU_TO_PLATFORM_CREDIT_CONVERSION_RATE, 3)
228234
JobsPersistence.update_key(job["id"], "estimated_sentinelhub_pu", str(round(estimated_sentinelhub_pu, 3)))
229235
JobsPersistence.update_key(job["id"], "estimated_platform_credits", str(estimated_platform_credits))
230236
JobsPersistence.update_key(job["id"], "estimated_file_size", str(estimated_file_size))
@@ -238,6 +244,6 @@ def create_or_get_estimate_values_from_db(job, batch_request_id):
238244

239245
def check_leftover_credits(estimated_pu):
240246
leftover_credits = g.user.get_leftover_credits()
241-
estimated_pu_as_credits = estimated_pu * 0.15 # platform credits === SH PU's * 0.15
247+
estimated_pu_as_credits = estimated_pu * SH_PU_TO_PLATFORM_CREDIT_CONVERSION_RATE
242248
if leftover_credits is not None and leftover_credits < estimated_pu_as_credits:
243249
raise InsufficientCredits()

tests/setup_tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ def decorated_function(*args, **kwargs):
139139
}
140140
],
141141
),
142+
responses.add(
143+
responses.GET,
144+
"https://etl.terrascope.be/user",
145+
json={"credits": 50},
146+
),
142147

143148
responses.add_passthru(re.compile(".*"))
144149
return func(*args, **kwargs)

tests/test_integration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,7 @@ def request_callback(request):
15711571

15721572

15731573
@with_mocked_auth
1574+
@with_mocked_reporting
15741575
@pytest.mark.parametrize(
15751576
"spatial_extent,temporal_extent",
15761577
[
@@ -1882,6 +1883,7 @@ def test_describe_account(app_client, example_authorization_header_with_oidc):
18821883

18831884

18841885
@with_mocked_auth
1886+
@with_mocked_reporting
18851887
@pytest.mark.parametrize(
18861888
"spatial_extent, is_error",
18871889
[

tests/test_units.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ def test_collections_provider(url, directory, expected_collection_ids):
123123
],
124124
},
125125
{"Authorization": "Bearer oidc/egi/<token>"},
126-
True,
127-
CredentialsInvalid,
126+
False,
127+
None,
128128
None,
129129
),
130130
(

0 commit comments

Comments
 (0)