Skip to content

Commit 7c3dfb0

Browse files
authored
Merge branch 'DIRACGrid:main' into refactor/sqlalchemy-DeclarativeBase
2 parents 505cf1f + 0440a9c commit 7c3dfb0

52 files changed

Lines changed: 284 additions & 252 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

diracx-cli/src/diracx/cli/jobs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
from typer import FileText, Option
1414

1515
from diracx.client.aio import AsyncDiracClient
16-
from diracx.core.models import ScalarSearchOperator, SearchSpec, VectorSearchOperator
16+
from diracx.core.models.search import (
17+
ScalarSearchOperator,
18+
SearchSpec,
19+
VectorSearchOperator,
20+
)
1721
from diracx.core.preferences import OutputFormats, get_diracx_preferences
1822

1923
from .utils import AsyncTyper

diracx-client/src/diracx/client/patches/auth/aio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from azure.core.pipeline import PipelineResponse
1616
from azure.core.tracing.decorator_async import distributed_trace_async
17-
from diracx.core.models import TokenResponse
17+
from diracx.core.models.auth import TokenResponse
1818

1919
from ..._generated.aio.operations._operations import (
2020
_models,

diracx-client/src/diracx/client/patches/client/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import jwt
2121
from azure.core.credentials import AccessToken
2222
from diracx.core.utils import EXPIRES_GRACE_SECONDS, serialize_credentials
23-
from diracx.core.models import TokenResponse
23+
from diracx.core.models.auth import TokenResponse
2424

2525

2626
class TokenStatus(Enum):

diracx-client/src/diracx/client/patches/jobs/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from io import BytesIO, IOBase
1717
from typing import Any, IO, Dict, TypedDict, Union, Unpack, cast, Literal
1818

19-
from diracx.core.models import SearchSpec
19+
from diracx.core.models.search import SearchSpec
2020

2121

2222
class ResponseExtra(TypedDict, total=False):

diracx-client/src/diracx/client/patches/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from azure.core.pipeline import PipelineRequest
2323
from azure.core.pipeline.policies import BearerTokenCredentialPolicy
2424

25-
from diracx.core.models import TokenResponse
25+
from diracx.core.models.auth import TokenResponse
2626
from diracx.core.preferences import DiracxPreferences, get_diracx_preferences
2727

2828

diracx-client/tests/test_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from azure.core.credentials import AccessToken
1010

1111
from diracx.client.patches.utils import get_token
12-
from diracx.core.models import TokenResponse
12+
from diracx.core.models.auth import TokenResponse
1313
from diracx.core.utils import serialize_credentials
1414

1515
# Create a fake jwt dictionary
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""Models are used to define the data structure of the requests and responses
2+
for the DiracX API. They are shared between the client components (cli, api) and
3+
services components (db, logic, routers).
4+
"""
5+
6+
# in order to avoid DIRAC from failing to import TokenResponse
7+
# TODO: remove after DIRACGrid/DIRAC#8433
8+
from __future__ import annotations
9+
10+
from .auth import TokenResponse
11+
12+
__all__ = ["TokenResponse"]
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
from __future__ import annotations
2+
3+
from datetime import datetime
4+
from enum import StrEnum
5+
6+
from pydantic import BaseModel
7+
from typing_extensions import TypedDict
8+
9+
10+
class UserInfo(BaseModel):
11+
sub: str # dirac generated vo:sub
12+
preferred_username: str
13+
dirac_group: str
14+
vo: str
15+
16+
17+
class TokenTypeHint(StrEnum):
18+
"""Token type hints for RFC7009 revocation endpoint."""
19+
20+
access_token = "access_token" # noqa: S105
21+
refresh_token = "refresh_token" # noqa: S105
22+
23+
24+
class GrantType(StrEnum):
25+
"""Grant types for OAuth2."""
26+
27+
authorization_code = "authorization_code"
28+
device_code = "urn:ietf:params:oauth:grant-type:device_code"
29+
refresh_token = "refresh_token" # noqa: S105 # False positive of Bandit about hard coded password
30+
31+
32+
class InitiateDeviceFlowResponse(TypedDict):
33+
"""Response for the device flow initiation."""
34+
35+
user_code: str
36+
device_code: str
37+
verification_uri_complete: str
38+
verification_uri: str
39+
expires_in: int
40+
41+
42+
class OpenIDConfiguration(TypedDict):
43+
issuer: str
44+
token_endpoint: str
45+
userinfo_endpoint: str
46+
authorization_endpoint: str
47+
device_authorization_endpoint: str
48+
revocation_endpoint: str
49+
jwks_uri: str
50+
grant_types_supported: list[str]
51+
scopes_supported: list[str]
52+
response_types_supported: list[str]
53+
token_endpoint_auth_signing_alg_values_supported: list[str]
54+
token_endpoint_auth_methods_supported: list[str]
55+
code_challenge_methods_supported: list[str]
56+
57+
58+
class TokenPayload(TypedDict):
59+
jti: str
60+
exp: datetime
61+
dirac_policies: dict
62+
63+
64+
class TokenResponse(BaseModel):
65+
# Based on RFC 6749
66+
access_token: str
67+
expires_in: int
68+
token_type: str = "Bearer" # noqa: S105
69+
refresh_token: str | None = None
70+
71+
72+
class AccessTokenPayload(TokenPayload):
73+
sub: str
74+
vo: str
75+
iss: str
76+
dirac_properties: list[str]
77+
preferred_username: str
78+
dirac_group: str
79+
80+
81+
class RefreshTokenPayload(TokenPayload):
82+
legacy_exchange: bool
83+
84+
85+
class SupportInfo(TypedDict):
86+
message: str
87+
webpage: str | None
88+
email: str | None
89+
90+
91+
class GroupInfo(TypedDict):
92+
properties: list[str]
93+
94+
95+
class VOInfo(TypedDict):
96+
groups: dict[str, GroupInfo]
97+
support: SupportInfo
98+
default_group: str
99+
100+
101+
class Metadata(TypedDict):
102+
virtual_organizations: dict[str, VOInfo]

0 commit comments

Comments
 (0)