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,126 @@ 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
128+ initializing the pool manager."""
129+ return self ._init_args_for_pool_manager
130+
131+ @init_args_for_pool_manager .setter
132+ def init_args_for_pool_manager (self , init_args_for_pool_manager : dict ) -> None :
133+ """Provides dictionary of arguments will be appended while initializing the pool manager.
134+ For example: {"init_args_for_pool_manager": {"retries": 3, "block": True}}
135+
136+ :Args:
137+ - value: the dictionary of arguments will be appended while initializing the pool manager
138+ """
139+ self ._init_args_for_pool_manager = init_args_for_pool_manager
140+
141+ @property
142+ def timeout (self ) -> int :
143+ """:Returns: The timeout (in seconds) used for communicating to the
144+ driver/server."""
145+ return self ._timeout
146+
147+ @timeout .setter
148+ def timeout (self , timeout : int ) -> None :
149+ """Provides the timeout (in seconds) for communicating with the driver
150+ or server.
151+
152+ :Args:
153+ - value: the timeout (in seconds) to use to communicate with the driver or server
154+ """
155+ self ._timeout = timeout
156+
157+ def reset_timeout (self ) -> None :
158+ """Resets the timeout to the default value of socket."""
159+ self ._timeout = socket .getdefaulttimeout ()
160+
161+ @property
162+ def ca_certs (self ) -> str :
163+ """:Returns: The path to bundle of CA certificates."""
164+ return self ._ca_certs
165+
166+ @ca_certs .setter
167+ def ca_certs (self , ca_certs : str ) -> None :
168+ """Provides the path to bundle of CA certificates for establishing
169+ secure connections.
170+
171+ :Args:
172+ - value: the path to bundle of CA certificates for establishing secure connections
173+ """
174+ self ._ca_certs = ca_certs
175+
82176 @property
83177 def username (self ) -> str :
178+ """Returns the username used for basic authentication to the remote
179+ server."""
84180 return self ._username
85181
86182 @username .setter
87183 def username (self , value : str ) -> None :
184+ """Sets the username used for basic authentication to the remote
185+ server."""
88186 self ._username = value
89187
90188 @property
91189 def password (self ) -> str :
190+ """Returns the password used for basic authentication to the remote
191+ server."""
92192 return self ._password
93193
94194 @password .setter
95195 def password (self , value : str ) -> None :
196+ """Sets the password used for basic authentication to the remote
197+ server."""
96198 self ._password = value
97199
98200 @property
99201 def auth_type (self ) -> str :
202+ """Returns the type of authentication to the remote server."""
100203 return self ._auth_type
101204
102205 @auth_type .setter
103206 def auth_type (self , value : str ) -> None :
207+ """Sets the type of authentication to the remote server if it is not
208+ using basic with username and password."""
104209 self ._auth_type = value
105210
106211 @property
107212 def token (self ) -> str :
213+ """Returns the token used for authentication to the remote server."""
108214 return self ._token
109215
110216 @token .setter
111217 def token (self , value : str ) -> None :
218+ """Sets the token used for authentication to the remote server if
219+ auth_type is not basic."""
112220 self ._token = value
113221
114222 def get_proxy_url (self ) -> Optional [str ]:
223+ """Returns the proxy URL to use for the connection."""
115224 proxy_type = self .proxy .proxy_type
116225 remote_add = parse .urlparse (self .remote_server_addr )
117226 if proxy_type is ProxyType .DIRECT :
@@ -136,6 +245,7 @@ def get_proxy_url(self) -> Optional[str]:
136245 return None
137246
138247 def get_auth_header (self ) -> Optional [dict ]:
248+ """Returns the authorization to add to the request headers."""
139249 auth_type = self .auth_type .lower ()
140250 if auth_type == "basic" and self .username and self .password :
141251 credentials = f"{ self .username } :{ self .password } "
0 commit comments