Debian Codegraph @

src/globus_sdk/globus_app/protocols.py

raw
1 from __future__ import annotations
2
3 import typing as t
4 import uuid
5
6 if t.TYPE_CHECKING:
7 from globus_sdk import AuthLoginClient, IDTokenDecoder
8 from globus_sdk.login_flows import LoginFlowManager
9 from globus_sdk.token_storage import TokenStorage, TokenValidationError
10
11 from .app import GlobusApp
12 from .config import GlobusAppConfig
13
14
15 @t.runtime_checkable
16 class TokenStorageProvider(t.Protocol):
17 r"""
18 A protocol for a factory which can create ``TokenStorage``\s.
19
20 SDK-provided :ref:`token_storages` support this protocol.
21 """
22
23 @classmethod
24 def for_globus_app(
25 cls,
26 *,
27 app_name: str,
28 config: GlobusAppConfig,
29 client_id: uuid.UUID | str,
30 namespace: str,
31 ) -> TokenStorage:
32 """
33 Create a ``TokenStorage`` for use in a GlobusApp.
34
35 :param app_name: The name supplied to the GlobusApp.
36 :param config: The configuration supplied to the GlobusApp.
37 :param client_id: The client_id of to the GlobusApp.
38 :param namespace: A namespace to use for instantiating a TokenStorage.
39 """
40
41
42 @t.runtime_checkable
43 class LoginFlowManagerProvider(t.Protocol):
44 r"""
45 A protocol for a factory which can create ``LoginFlowManager``\s.
46
47 SDK-provided :ref:`login_flow_managers` support this protocol.
48 """
49
50 @classmethod
51 def for_globus_app(
52 cls, *, app_name: str, config: GlobusAppConfig, login_client: AuthLoginClient
53 ) -> LoginFlowManager:
54 """
55 Create a ``CommandLineLoginFlowManager`` for use in a GlobusApp.
56
57 :param app_name: The name supplied to the GlobusApp.
58 :param config: The configuration supplied to the GlobusApp.
59 :param login_client: A login client to use for instantiating a LoginFlowManager.
60 """
61
62
63 @t.runtime_checkable
64 class IDTokenDecoderProvider(t.Protocol):
65 r"""
66 A protocol for a factory which can create ``IDTokenDecoder``\s.
67
68 The SDK-provided ``IDTokenDecoder`` class supports this protocol.
69 """
70
71 @classmethod
72 def for_globus_app(
73 cls,
74 *,
75 app_name: str,
76 config: GlobusAppConfig,
77 login_client: AuthLoginClient,
78 ) -> IDTokenDecoder:
79 """
80 Create an ``IDTokenDecoder`` for use in a GlobusApp.
81
82 :param app_name: The name supplied to the GlobusApp.
83 :param config: The configuration supplied to the GlobusApp.
84 :param login_client: A login client to use for instantiating an
85 ``IDTokenDecoder``.
86 """
87
88
89 class TokenValidationErrorHandler(t.Protocol):
90 """
91 A handler invoked when a :class:`TokenValidationError` is raised during a
92 service client call.
93
94 If this call completes without raising an exception, the service client call
95 will retry once more (subsequent errors will not call this handler).
96 """
97
98 def __call__(self, app: GlobusApp, error: TokenValidationError) -> None:
99 """
100 Resolve a token validation error.
101
102 :param app: The GlobusApp instance which encountered an error.
103 :param error: The error which was encountered.
104 """