Skip to content

Commit 252da7c

Browse files
fix: Moving pilot secret gen to diracx-logic
1 parent a38f6ea commit 252da7c

File tree

2 files changed

+8
-2
lines changed
  • diracx-db/src/diracx/db/sql/pilot_agents
  • diracx-logic/src/diracx/logic/auth

2 files changed

+8
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
from datetime import datetime, timezone
4-
from os import urandom
54

65
from sqlalchemy import DateTime, insert, select, update
76
from sqlalchemy.exc import IntegrityError, NoResultFound
@@ -12,6 +11,7 @@
1211
PilotNotFoundError,
1312
)
1413
from diracx.db.sql.utils.functions import hash
14+
from diracx.logic.auth.token import generate_pilot_secret
1515

1616
from ..utils import BaseSQLDB
1717
from .schema import PilotAgents, PilotAgentsDBBase, PilotRegistrations
@@ -129,7 +129,7 @@ async def add_pilot_credentials(self, pilot_id: int) -> str:
129129

130130
# Get a random string
131131
# Can be customized
132-
random_secret = urandom(30).hex()
132+
random_secret = generate_pilot_secret()
133133

134134
hashed_random_secret = hash(random_secret)
135135

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import hashlib
77
import re
88
from datetime import datetime, timedelta, timezone
9+
from secrets import token_hex
910
from uuid import UUID, uuid4
1011

1112
from authlib.jose import JsonWebToken
@@ -417,3 +418,8 @@ async def get_authorization_flow(auth_db: AuthDB, code: str, max_validity: int):
417418
raise AuthorizationError("Code was already used")
418419

419420
raise AuthorizationError("Bad state in authorization flow")
421+
422+
423+
def generate_pilot_secret():
424+
# Can change with time
425+
return token_hex(16)

0 commit comments

Comments
 (0)