1212# limitations under the License
1313
1414"""This package is the base package for ReportPortal client."""
15- import typing
15+
16+ import sys
17+ from typing import Optional , Tuple , TypedDict , Union
18+
19+ # noinspection PyUnreachableCode
20+ if sys .version_info >= (3 , 11 ):
21+ from typing import Unpack
22+ else :
23+ from typing_extensions import Unpack
1624
1725import aenum
1826
@@ -33,73 +41,93 @@ class ClientType(aenum.Enum):
3341 ASYNC_BATCHED = aenum .auto ()
3442
3543
44+ class _ClientOptions (TypedDict , total = False ):
45+ client_type : ClientType
46+ endpoint : str
47+ project : str
48+ api_key : Optional [str ]
49+ # OAuth 2.0 parameters
50+ oauth_oauth_uri : Optional [str ]
51+ oauth_username : Optional [str ]
52+ oauth_password : Optional [str ]
53+ oauth_client_id : Optional [str ]
54+ oauth_client_secret : Optional [str ]
55+ oauth_scope : Optional [str ]
56+ # Common client parameters
57+ launch_uuid : Optional [str ]
58+ is_skipped_an_issue : bool
59+ verify_ssl : Union [bool , str ]
60+ retries : int
61+ max_pool_size : int
62+ http_timeout : Union [float , Tuple [float , float ]]
63+ mode : str
64+ launch_uuid_print : bool
65+ print_output : OutputType
66+ truncate_attributes : bool
67+ log_batch_size : int
68+ log_batch_payload_limit : int
69+ # Async client specific parameters
70+ keepalive_timeout : float
71+ # Async threaded/batched client specific parameters
72+ task_timeout : float
73+ shutdown_timeout : float
74+ # Async batched client specific parameters
75+ trigger_num : int
76+ trigger_interval : float
77+
78+
3679# noinspection PyIncorrectDocstring
3780def create_client (
38- client_type : ClientType , endpoint : str , project : str , * , api_key : str = None , ** kwargs : typing . Any
39- ) -> typing . Optional [RP ]:
81+ client_type : ClientType , endpoint : str , project : str , ** kwargs : Unpack [ _ClientOptions ]
82+ ) -> Optional [RP ]:
4083 """Create and ReportPortal Client based on the type and arguments provided.
4184
4285 :param client_type: Type of the Client to create.
43- :type client_type: ClientType
4486 :param endpoint: Endpoint of the ReportPortal service.
45- :type endpoint: str
4687 :param project: Project name to report to.
47- :type project: str
4888 :param api_key: Authorization API key.
49- :type api_key: str
89+ :param oauth_oauth_uri: OAuth 2.0 token endpoint URI (for OAuth authentication).
90+ :param oauth_username: Username for OAuth 2.0 authentication.
91+ :param oauth_password: Password for OAuth 2.0 authentication.
92+ :param oauth_client_id: OAuth 2.0 client ID.
93+ :param oauth_client_secret: OAuth 2.0 client secret (optional).
94+ :param oauth_scope: OAuth 2.0 scope (optional).
5095 :param launch_uuid: A launch UUID to use instead of starting own one.
51- :type launch_uuid: str
5296 :param is_skipped_an_issue: Option to mark skipped tests as not 'To Investigate' items on the server
5397 side.
54- :type is_skipped_an_issue: bool
5598 :param verify_ssl: Option to skip ssl verification.
56- :type verify_ssl: typing.Union[bool, str]
5799 :param retries: Number of retry attempts to make in case of connection / server
58100 errors.
59- :type retries: int
60101 :param max_pool_size: Option to set the maximum number of connections to save the pool.
61- :type max_pool_size: int
62102 :param http_timeout : A float in seconds for connect and read timeout. Use a Tuple to
63103 specific connect and read separately.
64- :type http_timeout: Tuple[float, float]
65104 :param mode: Launch mode, all Launches started by the client will be in that mode.
66- :type mode: str
67105 :param launch_uuid_print: Print Launch UUID into passed TextIO or by default to stdout.
68- :type launch_uuid_print: bool
69106 :param print_output: Set output stream for Launch UUID printing.
70- :type print_output: OutputType
71107 :param truncate_attributes: Truncate test item attributes to default maximum length.
72- :type truncate_attributes: bool
73108 :param log_batch_size: Option to set the maximum number of logs that can be processed in one
74109 batch.
75- :type log_batch_size: int
76110 :param log_batch_payload_limit: Maximum size in bytes of logs that can be processed in one batch.
77- :type log_batch_payload_limit: int
78111 :param keepalive_timeout: For Async Clients only. Maximum amount of idle time in seconds before
79112 force connection closing.
80- :type keepalive_timeout: int
81113 :param task_timeout: For Async Threaded and Batched Clients only. Time limit in seconds for a
82114 Task processing.
83- :type task_timeout: float
84115 :param shutdown_timeout: For Async Threaded and Batched Clients only. Time limit in seconds for
85116 shutting down internal Tasks.
86- :type shutdown_timeout: float
87117 :param trigger_num: For Async Batched Client only. Number of tasks which triggers Task batch
88118 execution.
89- :type trigger_num: int
90119 :param trigger_interval: For Async Batched Client only. Time limit which triggers Task batch
91120 execution.
92- :type trigger_interval: float
93121 :return: ReportPortal Client instance.
94122 """
95123 if client_type is ClientType .SYNC :
96- return RPClient (endpoint , project , api_key = api_key , ** kwargs )
124+ return RPClient (endpoint , project , ** kwargs )
97125 if client_type is ClientType .ASYNC :
98- return AsyncRPClient (endpoint , project , api_key = api_key , ** kwargs )
126+ return AsyncRPClient (endpoint , project , ** kwargs )
99127 if client_type is ClientType .ASYNC_THREAD :
100- return ThreadedRPClient (endpoint , project , api_key = api_key , ** kwargs )
128+ return ThreadedRPClient (endpoint , project , ** kwargs )
101129 if client_type is ClientType .ASYNC_BATCHED :
102- return BatchedRPClient (endpoint , project , api_key = api_key , ** kwargs )
130+ return BatchedRPClient (endpoint , project , ** kwargs )
103131 raise ValueError (f"Unknown ReportPortal Client type requested: { client_type } " )
104132
105133
0 commit comments