1616# under the License.
1717import base64
1818import os
19+ import socket
1920from typing import Optional
2021from urllib import parse
2122
23+ import certifi
24+
2225from selenium .webdriver .common .proxy import Proxy
2326from selenium .webdriver .common .proxy import ProxyType
2427
@@ -27,8 +30,12 @@ class ClientConfig:
2730 def __init__ (
2831 self ,
2932 remote_server_addr : str ,
30- keep_alive : bool = True ,
31- proxy : Proxy = Proxy (raw = {"proxyType" : ProxyType .SYSTEM }),
33+ keep_alive : Optional [bool ] = True ,
34+ proxy : Optional [Proxy ] = Proxy (raw = {"proxyType" : ProxyType .SYSTEM }),
35+ ignore_certificates : Optional [bool ] = False ,
36+ init_args_for_pool_manager : Optional [dict ] = None ,
37+ timeout : Optional [int ] = None ,
38+ ca_certs : Optional [str ] = None ,
3239 username : Optional [str ] = None ,
3340 password : Optional [str ] = None ,
3441 auth_type : Optional [str ] = "Basic" ,
@@ -37,17 +44,38 @@ def __init__(
3744 self .remote_server_addr = remote_server_addr
3845 self .keep_alive = keep_alive
3946 self .proxy = proxy
47+ self .ignore_certificates = ignore_certificates
48+ self .init_args_for_pool_manager = init_args_for_pool_manager or {}
49+ self .timeout = timeout
4050 self .username = username
4151 self .password = password
4252 self .auth_type = auth_type
4353 self .token = token
4454
55+ self .timeout = (
56+ (
57+ float (os .getenv ("GLOBAL_DEFAULT_TIMEOUT" , str (socket .getdefaulttimeout ())))
58+ if os .getenv ("GLOBAL_DEFAULT_TIMEOUT" ) is not None
59+ else socket .getdefaulttimeout ()
60+ )
61+ if timeout is None
62+ else timeout
63+ )
64+
65+ self .ca_certs = (
66+ (os .getenv ("REQUESTS_CA_BUNDLE" ) if "REQUESTS_CA_BUNDLE" in os .environ else certifi .where ())
67+ if ca_certs is None
68+ else ca_certs
69+ )
70+
4571 @property
4672 def remote_server_addr (self ) -> str :
73+ """:Returns: The address of the remote server."""
4774 return self ._remote_server_addr
4875
4976 @remote_server_addr .setter
5077 def remote_server_addr (self , value : str ) -> None :
78+ """Provides the address of the remote server."""
5179 self ._remote_server_addr = value
5280
5381 @property
@@ -73,45 +101,125 @@ def proxy(self) -> Proxy:
73101 def proxy (self , proxy : Proxy ) -> None :
74102 """Provides the information for communicating with the driver or
75103 server.
104+ For example: Proxy(raw={"proxyType": ProxyType.SYSTEM})
76105
77106 :Args:
78107 - value: the proxy information to use to communicate with the driver or server
79108 """
80109 self ._proxy = proxy
81110
111+ @property
112+ def ignore_certificates (self ) -> bool :
113+ """:Returns: The ignore certificate check value"""
114+ return self ._ignore_certificates
115+
116+ @ignore_certificates .setter
117+ def ignore_certificates (self , ignore_certificates : bool ) -> None :
118+ """Toggles the ignore certificate check.
119+
120+ :Args:
121+ - value: value of ignore certificate check
122+ """
123+ self ._ignore_certificates = ignore_certificates
124+
125+ @property
126+ def init_args_for_pool_manager (self ) -> dict :
127+ """:Returns: The dictionary of arguments will be appended while initializing the pool manager."""
128+ return self ._init_args_for_pool_manager
129+
130+ @init_args_for_pool_manager .setter
131+ def init_args_for_pool_manager (self , init_args_for_pool_manager : dict ) -> None :
132+ """Provides dictionary of arguments will be appended while initializing the pool manager.
133+ For example: {"init_args_for_pool_manager": {"retries": 3, "block": True}}
134+
135+ :Args:
136+ - value: the dictionary of arguments will be appended while initializing the pool manager
137+ """
138+ self ._init_args_for_pool_manager = init_args_for_pool_manager
139+
140+ @property
141+ def timeout (self ) -> int :
142+ """:Returns: The timeout (in seconds) used for communicating to the
143+ driver/server."""
144+ return self ._timeout
145+
146+ @timeout .setter
147+ def timeout (self , timeout : int ) -> None :
148+ """Provides the timeout (in seconds) for communicating with the driver
149+ or server.
150+
151+ :Args:
152+ - value: the timeout (in seconds) to use to communicate with the driver or server
153+ """
154+ self ._timeout = timeout
155+
156+ def reset_timeout (self ) -> None :
157+ """Resets the timeout to the default value of socket."""
158+ self ._timeout = socket .getdefaulttimeout ()
159+
160+ @property
161+ def ca_certs (self ) -> str :
162+ """:Returns: The path to bundle of CA certificates."""
163+ return self ._ca_certs
164+
165+ @ca_certs .setter
166+ def ca_certs (self , ca_certs : str ) -> None :
167+ """Provides the path to bundle of CA certificates for establishing
168+ secure connections.
169+
170+ :Args:
171+ - value: the path to bundle of CA certificates for establishing secure connections
172+ """
173+ self ._ca_certs = ca_certs
174+
82175 @property
83176 def username (self ) -> str :
177+ """Returns the username used for basic authentication to the remote
178+ server."""
84179 return self ._username
85180
86181 @username .setter
87182 def username (self , value : str ) -> None :
183+ """Sets the username used for basic authentication to the remote
184+ server."""
88185 self ._username = value
89186
90187 @property
91188 def password (self ) -> str :
189+ """Returns the password used for basic authentication to the remote
190+ server."""
92191 return self ._password
93192
94193 @password .setter
95194 def password (self , value : str ) -> None :
195+ """Sets the password used for basic authentication to the remote
196+ server."""
96197 self ._password = value
97198
98199 @property
99200 def auth_type (self ) -> str :
201+ """Returns the type of authentication to the remote server."""
100202 return self ._auth_type
101203
102204 @auth_type .setter
103205 def auth_type (self , value : str ) -> None :
206+ """Sets the type of authentication to the remote server if it is not
207+ using basic with username and password."""
104208 self ._auth_type = value
105209
106210 @property
107211 def token (self ) -> str :
212+ """Returns the token used for authentication to the remote server."""
108213 return self ._token
109214
110215 @token .setter
111216 def token (self , value : str ) -> None :
217+ """Sets the token used for authentication to the remote server if
218+ auth_type is not basic."""
112219 self ._token = value
113220
114221 def get_proxy_url (self ) -> Optional [str ]:
222+ """Returns the proxy URL to use for the connection."""
115223 proxy_type = self .proxy .proxy_type
116224 remote_add = parse .urlparse (self .remote_server_addr )
117225 if proxy_type is ProxyType .DIRECT :
@@ -136,6 +244,7 @@ def get_proxy_url(self) -> Optional[str]:
136244 return None
137245
138246 def get_auth_header (self ) -> Optional [dict ]:
247+ """Returns the authorization to add to the request headers."""
139248 auth_type = self .auth_type .lower ()
140249 if auth_type == "basic" and self .username and self .password :
141250 credentials = f"{ self .username } :{ self .password } "
0 commit comments