55
66from __future__ import annotations
77
8+ import uuid as std_uuid
89from datetime import datetime
9- from enum import StrEnum
10- from typing import Literal , Optional
10+ from enum import StrEnum , auto
11+ from typing import Any , Literal , Optional
1112
12- from pydantic import BaseModel , Field
13+ from pydantic import BaseModel , Field , GetCoreSchemaHandler , GetJsonSchemaHandler
14+ from pydantic_core import CoreSchema , core_schema
1315from typing_extensions import TypedDict
16+ from uuid_utils import UUID as _UUID
1417
1518
1619class ScalarSearchOperator (StrEnum ):
@@ -37,7 +40,7 @@ class ScalarSearchSpec(TypedDict):
3740class VectorSearchSpec (TypedDict ):
3841 parameter : str
3942 operator : VectorSearchOperator
40- values : list [str ] | list [int ]
43+ values : list [str ] | list [int ] | list [ bytes ]
4144
4245
4346SearchSpec = ScalarSearchSpec | VectorSearchSpec
@@ -179,6 +182,29 @@ class SandboxUploadResponse(BaseModel):
179182 fields : dict [str , str ] = {}
180183
181184
185+ class UUID (_UUID ):
186+ """Subclass of uuid_utils.UUID to add pydantic support."""
187+
188+ @classmethod
189+ def __get_pydantic_core_schema__ (
190+ cls , source_type : Any , handler : GetCoreSchemaHandler
191+ ) -> CoreSchema :
192+ """Use the stdlib uuid.UUID schema for validation and serialization."""
193+ std_schema = handler (std_uuid .UUID )
194+
195+ def to_uuid_utils (u : std_uuid .UUID ) -> UUID :
196+ return cls (str (u ))
197+
198+ return core_schema .no_info_after_validator_function (to_uuid_utils , std_schema )
199+
200+ @classmethod
201+ def __get_pydantic_json_schema__ (
202+ cls , core_schema : CoreSchema , handler : GetJsonSchemaHandler
203+ ) -> dict [str , Any ]:
204+ """Return the stdlib uuid.UUID schema for JSON serialization."""
205+ return handler (core_schema )
206+
207+
182208class GrantType (StrEnum ):
183209 """Grant types for OAuth2."""
184210
@@ -213,9 +239,14 @@ class OpenIDConfiguration(TypedDict):
213239 code_challenge_methods_supported : list [str ]
214240
215241
216- class TokenPayload (TypedDict ):
242+ class BaseTokenPayload (TypedDict ):
243+ """This class helps having pilot and user tokens without code duplication."""
244+
217245 jti : str
218246 exp : datetime
247+
248+
249+ class TokenPayload (BaseTokenPayload ):
219250 dirac_policies : dict
220251
221252
@@ -308,3 +339,56 @@ class PilotStatus(StrEnum):
308339 ABORTED = "Aborted"
309340 #: Cannot get information about the pilot status:
310341 UNKNOWN = "Unknown"
342+
343+
344+ class PilotSecretConstraints (TypedDict , total = False ):
345+ VOs : list [str ] # Authorize only a list of VOs
346+ PilotStamps : list [str ] # Authorize only a list of stamps
347+ Sites : list [str ] # Authorize only a list of sites
348+ # ...
349+ # We can add constraints here
350+
351+
352+ class TokenType (StrEnum ):
353+ # Pilot token
354+ PILOT_TOKEN = auto ()
355+ # User token
356+ USER_TOKEN = auto ()
357+
358+
359+ class PilotSecretsInfo (BaseModel ):
360+ pilot_secret : str
361+ pilot_secret_expires_in : int
362+
363+
364+ class PilotAccessTokenPayload (BaseTokenPayload ):
365+ sub : str
366+ vo : str
367+ iss : str
368+ pilot_stamp : str
369+
370+
371+ class PilotInfo (BaseModel ):
372+ pilot_stamp : str
373+ vo : str
374+ sub : str
375+
376+
377+ class PilotRefreshTokenPayload (BaseTokenPayload ):
378+ legacy_exchange : bool
379+
380+
381+ class PilotCredentialsInfo (PilotSecretsInfo ):
382+ pilot_stamp : str
383+
384+
385+ class PilotAuthCredentials (TypedDict ):
386+ pilot_stamp : str
387+ pilot_secret : str
388+
389+
390+ class VacuumPilotAuth (PilotAuthCredentials ):
391+ vo : str
392+ grid_type : str
393+ grid_site : str
394+ status : str
0 commit comments