Skip to content

Commit b21fd04

Browse files
fix: Fixed documentation, and code in general
1 parent 962c6a4 commit b21fd04

File tree

7 files changed

+12
-50
lines changed

7 files changed

+12
-50
lines changed

diracx-db/src/diracx/db/sql/pilot_agents/db.py

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from datetime import datetime, timezone
44
from os import urandom
55

6-
from sqlalchemy import insert, select, update
6+
from sqlalchemy import DateTime, insert, select, update
77
from sqlalchemy.exc import IntegrityError
88

99
from diracx.core.exceptions import (
@@ -93,42 +93,17 @@ async def verify_pilot_secret(self, pilot_id: int, pilot_secret: str) -> None:
9393

9494
# Increment the count
9595
await self.increment_pilot_secret_use(pilot_id=pilot_id)
96-
return
9796

9897
async def register_new_pilot(
9998
self,
10099
vo: str,
101-
initial_job_id: int = 0,
102-
current_job_id: int = 0,
103-
benchmark: float = 0.0,
104-
pilot_job_reference: str = "Unknown",
105-
pilot_stamp: str = "",
106-
status: str = "Unknown",
107-
status_reason: str = "Unknown",
108-
queue: str = "Unknown",
109-
grid_site: str = "Unknown",
110-
destination_site: str = "NotAssigned",
111-
grid_type: str = "LCG",
112-
submission_time: str | None = None, # ?
113-
last_update_time: str | None = None, # = now?
114-
accounting_sent: bool = False,
100+
submission_time: DateTime | None = None, # ?
101+
last_update_time: DateTime | None = None, # = now?
115102
) -> int | None:
116103
stmt = insert(PilotAgents).values(
117-
initial_job_id=initial_job_id,
118-
current_job_id=current_job_id,
119-
pilot_job_reference=pilot_job_reference,
120-
pilot_stamp=pilot_stamp,
121-
destination_site=destination_site,
122-
queue=queue,
123-
grid_site=grid_site,
124104
vo=vo,
125-
grid_type=grid_type,
126-
benchmark=benchmark,
127105
submission_time=submission_time,
128106
last_update_time=last_update_time,
129-
status=status,
130-
status_reason=status_reason,
131-
accounting_sent=accounting_sent,
132107
)
133108

134109
# Execute the request
@@ -163,11 +138,11 @@ async def add_pilot_credentials(self, pilot_id: int) -> str:
163138

164139
return random_secret
165140

166-
async def get_pilots(self):
141+
async def fetch_all_pilots(self):
167142
stmt = select(PilotRegistrations).with_for_update()
168143
result = await self.conn.execute(stmt)
169144

170-
# Convertir les résultats en dictionnaires
145+
# Convert results into a dictionary
171146
pilots = [dict(row._mapping) for row in result]
172147

173148
return pilots

diracx-db/tests/pilot_agents/test_pilot_agents_db.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ async def test_insert_and_select(pilot_agents_db: PilotAgentsDB):
3636
async def test_insert_and_select_single(pilot_agents_db: PilotAgentsDB):
3737

3838
async with pilot_agents_db as pilot_agents_db:
39-
# Add a pilot reference
40-
new_pilot_id = await pilot_agents_db.register_new_pilot(
41-
vo="pilot-vo", pilot_job_reference="pilot-ref"
42-
)
39+
new_pilot_id = await pilot_agents_db.register_new_pilot(vo="pilot-vo")
4340

4441
res = await pilot_agents_db.get_pilot_by_id(new_pilot_id)
4542

@@ -49,7 +46,6 @@ async def test_insert_and_select_single(pilot_agents_db: PilotAgentsDB):
4946
# Set values
5047
assert res["PilotID"] == new_pilot_id
5148
assert res["VO"] == "pilot-vo"
52-
assert res["PilotJobReference"] == "pilot-ref"
5349

5450
# Default values
5551
assert res["PilotStamp"] == ""
@@ -60,12 +56,7 @@ async def test_insert_and_select_single(pilot_agents_db: PilotAgentsDB):
6056
async def test_create_pilot_and_verify_secret(pilot_agents_db: PilotAgentsDB):
6157

6258
async with pilot_agents_db as pilot_agents_db:
63-
# Add a pilot reference
64-
pilot_ref = "pilot-ref"
65-
66-
new_pilot_id = await pilot_agents_db.register_new_pilot(
67-
vo="pilot-vo", pilot_job_reference=pilot_ref
68-
)
59+
new_pilot_id = await pilot_agents_db.register_new_pilot(vo="pilot-vo")
6960

7061
# Add creds
7162
secret = await pilot_agents_db.add_pilot_credentials(new_pilot_id)

diracx-logic/src/diracx/logic/auth/token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ async def get_oidc_token_info_from_device_flow(
106106
# TODO: use HTTPException while still respecting the standard format
107107
# required by the RFC
108108
if info["Status"] != FlowStatus.READY:
109-
# That should exnever ever happen
109+
# That should never ever happen
110110
raise NotImplementedError(f"Unexpected flow status {info['status']!r}")
111111
return (oidc_token_info, scope)
112112

diracx-routers/src/diracx/routers/auth/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .authorize_code_flow import router as authorize_code_flow_router
66
from .device_flow import router as device_flow_router
77
from .management import router as management_router
8-
from .pilot_auth import router as pilot_auth_router
8+
from .pilot import router as pilot_router
99
from .token import router as token_router
1010
from .utils import has_properties
1111

@@ -14,6 +14,6 @@
1414
router.include_router(management_router)
1515
router.include_router(authorize_code_flow_router)
1616
router.include_router(token_router)
17-
router.include_router(pilot_auth_router)
17+
router.include_router(pilot_router)
1818

1919
__all__ = ["has_properties", "verify_dirac_access_token"]

diracx-routers/src/diracx/routers/pilots/access_policies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async def policy(
4343
return
4444

4545
raise HTTPException(
46-
status.HTTP_401_UNAUTHORIZED, "you don't have the right properties"
46+
status.HTTP_403_FORBIDDEN, "you don't have the right properties"
4747
)
4848
return
4949

diracx-routers/tests/auth/test_pilot_auth.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,10 @@ async def test_create_pilot_and_verify_secret(test_client):
3535

3636
# Add a pilot vo
3737
pilot_vo = "lhcb"
38-
# Add a pilot reference
39-
pilot_ref = "pilot-ref"
4038

4139
async with db as pilot_agents_db:
4240
# Register a pilot
43-
pilot_id = await pilot_agents_db.register_new_pilot(
44-
vo=pilot_vo, pilot_job_reference=pilot_ref
45-
)
41+
pilot_id = await pilot_agents_db.register_new_pilot(vo=pilot_vo)
4642

4743
# Add credentials to this pilot
4844
secret = await pilot_agents_db.add_pilot_credentials(pilot_id=pilot_id)

0 commit comments

Comments
 (0)