Skip to content

Commit 8645c01

Browse files
fix: Added auth support to the pilot
Squashed commits: [a269416] fix: Fixed documentation and autorest [076e25d] fix: Removing os endpoints [9d1c062] test: Improving pilot auth tests [be5347a] fix: Small fixes with the debug endpoints [cf3b2cc] fix: Moving pilot auth to auth endpoint, and fixes [513fc64] fix: Removed garbage code, and improving tests [30c7030] fix: Added get_pilot_by_id [71a1a8f] feat: Adding pilot secret creation [c236983] feat: Pilot can exchange against nothing a secret
1 parent a37ff0d commit 8645c01

File tree

20 files changed

+988
-29
lines changed

20 files changed

+988
-29
lines changed

diracx-client/src/diracx/client/generated/_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
AuthOperations,
2020
ConfigOperations,
2121
JobsOperations,
22+
PilotsOperations,
2223
WellKnownOperations,
2324
)
2425

@@ -34,6 +35,8 @@ class Dirac: # pylint: disable=client-accepts-api-version-keyword
3435
:vartype config: generated.operations.ConfigOperations
3536
:ivar jobs: JobsOperations operations
3637
:vartype jobs: generated.operations.JobsOperations
38+
:ivar pilots: PilotsOperations operations
39+
:vartype pilots: generated.operations.PilotsOperations
3740
:keyword endpoint: Service URL. Required. Default value is "".
3841
:paramtype endpoint: str
3942
"""
@@ -85,6 +88,9 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
8588
self.jobs = JobsOperations(
8689
self._client, self._config, self._serialize, self._deserialize
8790
)
91+
self.pilots = PilotsOperations(
92+
self._client, self._config, self._serialize, self._deserialize
93+
)
8894

8995
def send_request(
9096
self, request: HttpRequest, *, stream: bool = False, **kwargs: Any

diracx-client/src/diracx/client/generated/aio/_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
AuthOperations,
2020
ConfigOperations,
2121
JobsOperations,
22+
PilotsOperations,
2223
WellKnownOperations,
2324
)
2425

@@ -34,6 +35,8 @@ class Dirac: # pylint: disable=client-accepts-api-version-keyword
3435
:vartype config: generated.aio.operations.ConfigOperations
3536
:ivar jobs: JobsOperations operations
3637
:vartype jobs: generated.aio.operations.JobsOperations
38+
:ivar pilots: PilotsOperations operations
39+
:vartype pilots: generated.aio.operations.PilotsOperations
3740
:keyword endpoint: Service URL. Required. Default value is "".
3841
:paramtype endpoint: str
3942
"""
@@ -85,6 +88,9 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
8588
self.jobs = JobsOperations(
8689
self._client, self._config, self._serialize, self._deserialize
8790
)
91+
self.pilots = PilotsOperations(
92+
self._client, self._config, self._serialize, self._deserialize
93+
)
8894

8995
def send_request(
9096
self, request: HttpRequest, *, stream: bool = False, **kwargs: Any

diracx-client/src/diracx/client/generated/aio/operations/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ._operations import AuthOperations # type: ignore
1515
from ._operations import ConfigOperations # type: ignore
1616
from ._operations import JobsOperations # type: ignore
17+
from ._operations import PilotsOperations # type: ignore
1718

1819
from ._patch import __all__ as _patch_all
1920
from ._patch import *
@@ -24,6 +25,7 @@
2425
"AuthOperations",
2526
"ConfigOperations",
2627
"JobsOperations",
28+
"PilotsOperations",
2729
]
2830
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
2931
_patch_sdk()

diracx-client/src/diracx/client/generated/aio/operations/_operations.py

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
build_auth_get_refresh_tokens_request,
3434
build_auth_initiate_authorization_flow_request,
3535
build_auth_initiate_device_flow_request,
36+
build_auth_pilot_login_request,
3637
build_auth_revoke_refresh_token_request,
3738
build_auth_userinfo_request,
3839
build_config_serve_config_request,
@@ -50,6 +51,7 @@
5051
build_jobs_summary_request,
5152
build_jobs_unassign_bulk_jobs_sandboxes_request,
5253
build_jobs_unassign_job_sandboxes_request,
54+
build_pilots_get_pilot_info_request,
5355
build_well_known_get_installation_metadata_request,
5456
build_well_known_get_openid_configuration_request,
5557
)
@@ -824,6 +826,67 @@ async def complete_authorization_flow(
824826

825827
return deserialized # type: ignore
826828

829+
@distributed_trace_async
830+
async def pilot_login(
831+
self, *, pilot_id: int, pilot_secret: str, **kwargs: Any
832+
) -> _models.TokenResponse:
833+
"""Pilot Login.
834+
835+
Endpoint without policy, the pilot uses only its secret.
836+
837+
:keyword pilot_id: Required.
838+
:paramtype pilot_id: int
839+
:keyword pilot_secret: Required.
840+
:paramtype pilot_secret: str
841+
:return: TokenResponse
842+
:rtype: ~generated.models.TokenResponse
843+
:raises ~azure.core.exceptions.HttpResponseError:
844+
"""
845+
error_map: MutableMapping = {
846+
401: ClientAuthenticationError,
847+
404: ResourceNotFoundError,
848+
409: ResourceExistsError,
849+
304: ResourceNotModifiedError,
850+
}
851+
error_map.update(kwargs.pop("error_map", {}) or {})
852+
853+
_headers = kwargs.pop("headers", {}) or {}
854+
_params = kwargs.pop("params", {}) or {}
855+
856+
cls: ClsType[_models.TokenResponse] = kwargs.pop("cls", None)
857+
858+
_request = build_auth_pilot_login_request(
859+
pilot_id=pilot_id,
860+
pilot_secret=pilot_secret,
861+
headers=_headers,
862+
params=_params,
863+
)
864+
_request.url = self._client.format_url(_request.url)
865+
866+
_stream = False
867+
pipeline_response: PipelineResponse = (
868+
await self._client._pipeline.run( # pylint: disable=protected-access
869+
_request, stream=_stream, **kwargs
870+
)
871+
)
872+
873+
response = pipeline_response.http_response
874+
875+
if response.status_code not in [200]:
876+
map_error(
877+
status_code=response.status_code, response=response, error_map=error_map
878+
)
879+
raise HttpResponseError(response=response)
880+
881+
deserialized = self._deserialize(
882+
"TokenResponse", pipeline_response.http_response
883+
)
884+
885+
if cls:
886+
return cls(pipeline_response, deserialized, {}) # type: ignore
887+
888+
return deserialized # type: ignore
889+
827890

828891
class ConfigOperations:
829892
"""
@@ -2157,3 +2220,84 @@ async def submit_jdl_jobs(
21572220
return cls(pipeline_response, deserialized, {}) # type: ignore
21582221

21592222
return deserialized # type: ignore
2223+
2224+
2225+
class PilotsOperations:
2226+
"""
2227+
.. warning::
2228+
**DO NOT** instantiate this class directly.
2229+
2230+
Instead, you should access the following operations through
2231+
:class:`~generated.aio.Dirac`'s
2232+
:attr:`pilots` attribute.
2233+
"""
2234+
2235+
models = _models
2236+
2237+
def __init__(self, *args, **kwargs) -> None:
2238+
input_args = list(args)
2239+
self._client: AsyncPipelineClient = (
2240+
input_args.pop(0) if input_args else kwargs.pop("client")
2241+
)
2242+
self._config: DiracConfiguration = (
2243+
input_args.pop(0) if input_args else kwargs.pop("config")
2244+
)
2245+
self._serialize: Serializer = (
2246+
input_args.pop(0) if input_args else kwargs.pop("serializer")
2247+
)
2248+
self._deserialize: Deserializer = (
2249+
input_args.pop(0) if input_args else kwargs.pop("deserializer")
2250+
)
2251+
2252+
@distributed_trace_async
2253+
async def get_pilot_info(self, **kwargs: Any) -> _models.AuthorizedUserInfo:
2254+
"""Get Pilot Info.
2255+
2256+
Get Pilot Info.
2257+
2258+
:return: AuthorizedUserInfo
2259+
:rtype: ~generated.models.AuthorizedUserInfo
2260+
:raises ~azure.core.exceptions.HttpResponseError:
2261+
"""
2262+
error_map: MutableMapping = {
2263+
401: ClientAuthenticationError,
2264+
404: ResourceNotFoundError,
2265+
409: ResourceExistsError,
2266+
304: ResourceNotModifiedError,
2267+
}
2268+
error_map.update(kwargs.pop("error_map", {}) or {})
2269+
2270+
_headers = kwargs.pop("headers", {}) or {}
2271+
_params = kwargs.pop("params", {}) or {}
2272+
2273+
cls: ClsType[_models.AuthorizedUserInfo] = kwargs.pop("cls", None)
2274+
2275+
_request = build_pilots_get_pilot_info_request(
2276+
headers=_headers,
2277+
params=_params,
2278+
)
2279+
_request.url = self._client.format_url(_request.url)
2280+
2281+
_stream = False
2282+
pipeline_response: PipelineResponse = (
2283+
await self._client._pipeline.run( # pylint: disable=protected-access
2284+
_request, stream=_stream, **kwargs
2285+
)
2286+
)
2287+
2288+
response = pipeline_response.http_response
2289+
2290+
if response.status_code not in [200]:
2291+
map_error(
2292+
status_code=response.status_code, response=response, error_map=error_map
2293+
)
2294+
raise HttpResponseError(response=response)
2295+
2296+
deserialized = self._deserialize(
2297+
"AuthorizedUserInfo", pipeline_response.http_response
2298+
)
2299+
2300+
if cls:
2301+
return cls(pipeline_response, deserialized, {}) # type: ignore
2302+
2303+
return deserialized # type: ignore

diracx-client/src/diracx/client/generated/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
from ._models import ( # type: ignore
15+
AuthorizedUserInfo,
1516
BodyAuthGetOidcToken,
1617
BodyAuthGetOidcTokenGrantType,
1718
GroupInfo,
@@ -57,6 +58,7 @@
5758
from ._patch import patch_sdk as _patch_sdk
5859

5960
__all__ = [
61+
"AuthorizedUserInfo",
6062
"BodyAuthGetOidcToken",
6163
"BodyAuthGetOidcTokenGrantType",
6264
"GroupInfo",

diracx-client/src/diracx/client/generated/models/_models.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,92 @@
2121
JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object
2222

2323

24+
class AuthorizedUserInfo(_serialization.Model):
25+
"""AuthorizedUserInfo.
26+
27+
All required parameters must be populated in order to send to server.
28+
29+
:ivar sub: Sub. Required.
30+
:vartype sub: str
31+
:ivar preferred_username: Preferred Username. Required.
32+
:vartype preferred_username: str
33+
:ivar dirac_group: Dirac Group. Required.
34+
:vartype dirac_group: str
35+
:ivar vo: Vo. Required.
36+
:vartype vo: str
37+
:ivar bearer_token: Bearer Token. Required.
38+
:vartype bearer_token: str
39+
:ivar token_id: Token Id. Required.
40+
:vartype token_id: str
41+
:ivar properties: Properties. Required.
42+
:vartype properties: list[str]
43+
:ivar policies: Policies.
44+
:vartype policies: JSON
45+
"""
46+
47+
_validation = {
48+
"sub": {"required": True},
49+
"preferred_username": {"required": True},
50+
"dirac_group": {"required": True},
51+
"vo": {"required": True},
52+
"bearer_token": {"required": True},
53+
"token_id": {"required": True},
54+
"properties": {"required": True},
55+
}
56+
57+
_attribute_map = {
58+
"sub": {"key": "sub", "type": "str"},
59+
"preferred_username": {"key": "preferred_username", "type": "str"},
60+
"dirac_group": {"key": "dirac_group", "type": "str"},
61+
"vo": {"key": "vo", "type": "str"},
62+
"bearer_token": {"key": "bearer_token", "type": "str"},
63+
"token_id": {"key": "token_id", "type": "str"},
64+
"properties": {"key": "properties", "type": "[str]"},
65+
"policies": {"key": "policies", "type": "object"},
66+
}
67+
68+
def __init__(
69+
self,
70+
*,
71+
sub: str,
72+
preferred_username: str,
73+
dirac_group: str,
74+
vo: str,
75+
bearer_token: str,
76+
token_id: str,
77+
properties: List[str],
78+
policies: Optional[JSON] = None,
79+
**kwargs: Any,
80+
) -> None:
81+
"""
82+
:keyword sub: Sub. Required.
83+
:paramtype sub: str
84+
:keyword preferred_username: Preferred Username. Required.
85+
:paramtype preferred_username: str
86+
:keyword dirac_group: Dirac Group. Required.
87+
:paramtype dirac_group: str
88+
:keyword vo: Vo. Required.
89+
:paramtype vo: str
90+
:keyword bearer_token: Bearer Token. Required.
91+
:paramtype bearer_token: str
92+
:keyword token_id: Token Id. Required.
93+
:paramtype token_id: str
94+
:keyword properties: Properties. Required.
95+
:paramtype properties: list[str]
96+
:keyword policies: Policies.
97+
:paramtype policies: JSON
98+
"""
99+
super().__init__(**kwargs)
100+
self.sub = sub
101+
self.preferred_username = preferred_username
102+
self.dirac_group = dirac_group
103+
self.vo = vo
104+
self.bearer_token = bearer_token
105+
self.token_id = token_id
106+
self.properties = properties
107+
self.policies = policies
108+
109+
24110
class BodyAuthGetOidcToken(_serialization.Model):
25111
"""Body_auth_get_oidc_token.
26112

diracx-client/src/diracx/client/generated/operations/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ._operations import AuthOperations # type: ignore
1515
from ._operations import ConfigOperations # type: ignore
1616
from ._operations import JobsOperations # type: ignore
17+
from ._operations import PilotsOperations # type: ignore
1718

1819
from ._patch import __all__ as _patch_all
1920
from ._patch import *
@@ -24,6 +25,7 @@
2425
"AuthOperations",
2526
"ConfigOperations",
2627
"JobsOperations",
28+
"PilotsOperations",
2729
]
2830
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
2931
_patch_sdk()

0 commit comments

Comments
 (0)