Skip to content

Commit 55d9ec0

Browse files
authored
Merge pull request #163 from ecmwf-projects/COPDS-1389-remove-acceptedLicences
Remove job submission with acceptedLicences
2 parents 7563e0b + 523134f commit 55d9ec0

File tree

5 files changed

+13
-102
lines changed

5 files changed

+13
-102
lines changed

cads_processing_api_service/auth.py

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -147,36 +147,14 @@ def verify_permission(user_uid: str, job: cads_broker.SystemRequest) -> None:
147147
raise exceptions.PermissionDenied()
148148

149149

150-
def get_contextual_accepted_licences(
151-
execution_content: dict[str, Any]
152-
) -> set[tuple[str, int]]:
153-
"""Get licences accepted in the context of a process execution request.
154-
155-
Parameters
156-
----------
157-
execution_content : dict[str, Any]
158-
Process execution request's payload.
159-
160-
Returns
161-
-------
162-
set[tuple[str, int]]
163-
Accepted licences.
164-
"""
165-
licences = execution_content.get("acceptedLicences")
166-
if not licences:
167-
licences = []
168-
accepted_licences = {(licence["id"], licence["revision"]) for licence in licences}
169-
return accepted_licences
170-
171-
172150
@cachetools.cached(
173151
cache=cachetools.TTLCache(
174152
maxsize=config.ensure_settings().cache_users_maxsize,
175153
ttl=config.ensure_settings().cache_users_ttl,
176154
),
177155
info=True,
178156
)
179-
def get_stored_accepted_licences(auth_header: tuple[str, str]) -> set[tuple[str, int]]:
157+
def get_accepted_licences(auth_header: tuple[str, str]) -> set[tuple[str, int]]:
180158
"""Get licences accepted by a user stored in the Extended Profiles database.
181159
182160
The user is identified by the provided authentication header.
@@ -246,22 +224,17 @@ def check_licences(
246224

247225

248226
def validate_licences(
249-
execution_content: dict[str, Any],
250-
stored_accepted_licences: set[tuple[str, str]],
227+
accepted_licences: set[tuple[str, str]],
251228
licences: list[tuple[str, int]],
252229
) -> None:
253230
"""Validate process execution request's payload in terms of required licences.
254231
255232
Parameters
256233
----------
257-
execution_content : dict[str, Any]
258-
Process execution request's payload.
259234
stored_accepted_licences : set[tuple[str, str]]
260235
Licences accepted by a user stored in the Extended Profiles database.
261236
licences : list[tuple[str, int]]
262237
Licences bound to the required process/dataset.
263238
"""
264239
required_licences = set(licences)
265-
contextual_accepted_licences = get_contextual_accepted_licences(execution_content)
266-
accepted_licences = contextual_accepted_licences.union(stored_accepted_licences)
267240
check_licences(required_licences, accepted_licences) # type: ignore

cads_processing_api_service/clients.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def get_process(
166166
def post_process_execution(
167167
self,
168168
process_id: str = fastapi.Path(...),
169-
execution_content: models.Execute = fastapi.Body(...),
169+
execution_content: ogc_api_processes_fastapi.models.Execute = fastapi.Body(...),
170170
auth_header: tuple[str, str] = fastapi.Depends(auth.get_auth_header),
171171
portal_header: str | None = fastapi.Header(
172172
None, alias=config.PORTAL_HEADER_NAME
@@ -192,7 +192,7 @@ def post_process_execution(
192192
"""
193193
user_uid = auth.authenticate_user(auth_header, portal_header)
194194
structlog.contextvars.bind_contextvars(user_uid=user_uid)
195-
stored_accepted_licences = auth.get_stored_accepted_licences(auth_header)
195+
accepted_licences = auth.get_accepted_licences(auth_header)
196196
execution_content = execution_content.model_dump()
197197
catalogue_sessionmaker = db_utils.get_catalogue_sessionmaker(
198198
db_utils.ConnectionMode.read
@@ -205,7 +205,7 @@ def post_process_execution(
205205
)
206206
adaptor = adaptors.instantiate_adaptor(resource)
207207
licences = adaptor.get_licences(execution_content)
208-
auth.validate_licences(execution_content, stored_accepted_licences, licences)
208+
auth.validate_licences(accepted_licences, licences)
209209
job_id = str(uuid.uuid4())
210210
structlog.contextvars.bind_contextvars(job_id=job_id)
211211
job_kwargs = adaptors.make_system_job_kwargs(

cads_processing_api_service/models.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,6 @@
2020
import pydantic
2121

2222

23-
class Licence(pydantic.BaseModel):
24-
id: str
25-
revision: int
26-
27-
28-
class Request(pydantic.BaseModel):
29-
ids: dict[
30-
str,
31-
ogc_api_processes_fastapi.models.InlineOrRefData
32-
| list[ogc_api_processes_fastapi.models.InlineOrRefData],
33-
] | None = None
34-
labels: dict[str, str | list[str]] | None = None
35-
36-
37-
class Execute(ogc_api_processes_fastapi.models.Execute):
38-
acceptedLicences: list[Licence] | None = None
39-
40-
4123
class StatusInfo(ogc_api_processes_fastapi.models.StatusInfo):
4224
request: dict[str, Any] | None = None
4325
results: dict[str, Any] | None = None

tests/integration_test_10_clients.py

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,6 @@
3737
"time": ["06:00"],
3838
}
3939
}
40-
POST_PROCESS_REQUEST_BODY_SUCCESS_W_LICENCES = {
41-
"inputs": {
42-
"product_type": ["reanalysis"],
43-
"format": ["grib"],
44-
"variable": ["temperature"],
45-
"pressure_level": ["1"],
46-
"year": ["1971"],
47-
"month": ["01"],
48-
"day": ["25"],
49-
"time": ["06:00"],
50-
},
51-
"acceptedLicences": [{"id": "licence-to-use-copernicus-products", "revision": 12}],
52-
}
5340
POST_PROCESS_REQUEST_BODY_FAIL = {
5441
"inputs": {
5542
"product_type": ["reanalysis"],
@@ -263,25 +250,7 @@ def test_post_process_execution_stored_accepted_licences(
263250
)
264251

265252

266-
def test_post_process_execution_context_accepted_licences(
267-
dev_env_proc_api_url: str,
268-
) -> None:
269-
response = submit_job(
270-
dev_env_proc_api_url,
271-
request_body=POST_PROCESS_REQUEST_BODY_SUCCESS_W_LICENCES,
272-
auth_headers=AUTH_HEADERS_VALID_2,
273-
)
274-
response_status_code = response.status_code
275-
exp_status_code = 201
276-
assert response_status_code == exp_status_code
277-
278-
response = delete_job(
279-
dev_env_proc_api_url,
280-
response.json()["jobID"],
281-
auth_headers=AUTH_HEADERS_VALID_2,
282-
)
283-
284-
253+
@pytest.mark.skip(reason="Submission of jobs with accepted licences is no more allowed")
285254
def test_post_process_execution_anon_user(
286255
dev_env_proc_api_url: str,
287256
) -> None:
@@ -292,7 +261,7 @@ def test_post_process_execution_anon_user(
292261

293262
response = submit_job(
294263
dev_env_proc_api_url,
295-
request_body=POST_PROCESS_REQUEST_BODY_SUCCESS_W_LICENCES,
264+
request_body=POST_PROCESS_REQUEST_BODY_SUCCESS,
296265
auth_headers=AUTH_HEADERS_VALID_ANON,
297266
)
298267
response_status_code = response.status_code
@@ -318,6 +287,7 @@ def test_post_process_execution_not_authorized(
318287
assert response.status_code == exp_status_code
319288

320289

290+
@pytest.mark.skip(reason="Test is not valid anymore")
321291
def test_post_process_execution_missing_licences(
322292
dev_env_proc_api_url: str,
323293
) -> None:
@@ -591,13 +561,16 @@ def test_get_jobs(dev_env_proc_api_url: str) -> None:
591561
assert all([key in response_body for key in exp_keys])
592562

593563

594-
def test_get_jobs_different_user(dev_env_proc_api_url: str) -> None:
564+
def test_get_jobs_different_user(
565+
dev_env_prof_api_url: str, dev_env_proc_api_url: str
566+
) -> None:
567+
response = accept_licence(dev_env_prof_api_url, auth_headers=AUTH_HEADERS_VALID_2)
595568
number_of_new_jobs = 1
596569
job_ids: list[str] = []
597570
for _ in range(number_of_new_jobs):
598571
response = submit_job(
599572
dev_env_proc_api_url,
600-
request_body=POST_PROCESS_REQUEST_BODY_SUCCESS_W_LICENCES,
573+
request_body=POST_PROCESS_REQUEST_BODY_SUCCESS,
601574
auth_headers=AUTH_HEADERS_VALID_2,
602575
)
603576
job_ids.append(response.json()["jobID"])

tests/test_30_auth.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,6 @@
1818
from cads_processing_api_service import auth, exceptions
1919

2020

21-
def test_get_contextual_accepted_licences() -> None:
22-
execution_content: dict[str, list[dict[str, str | int]] | None] = {
23-
"acceptedLicences": [
24-
{"id": "licence", "revision": 0},
25-
{"id": "licence", "revision": 0},
26-
]
27-
}
28-
licences = auth.get_contextual_accepted_licences(execution_content)
29-
exp_licences = {("licence", 0)}
30-
assert licences == exp_licences
31-
32-
execution_content = {"acceptedLicences": None}
33-
licences = auth.get_contextual_accepted_licences(execution_content)
34-
exp_licences = set()
35-
assert licences == exp_licences
36-
37-
3821
def test_check_licences() -> None:
3922
required_licences = {("licence_1", 1), ("licence_2", 2)}
4023
accepted_licences = {("licence_1", 1), ("licence_2", 2), ("licence_3", 3)}

0 commit comments

Comments
 (0)