@@ -271,6 +271,61 @@ def construct(self):
271271 """Constructs and returns the desired Client object.
272272 The instance of this class will reset to default values for further building.
273273
274+ Returns
275+ -------
276+ Client or NXClient or XEClient or XRClient
277+ """
278+ channel = None
279+ channel_ssl_creds = None
280+ channel_metadata_creds = None
281+ channel_creds = None
282+ channel_ssl_creds = None
283+ if any ((self .__root_certificates , self .__private_key , self .__certificate_chain )):
284+ channel_ssl_creds = grpc .ssl_channel_credentials (
285+ self .__root_certificates , self .__private_key , self .__certificate_chain
286+ )
287+ if self .__username and self .__password :
288+ channel_metadata_creds = grpc .metadata_call_credentials (
289+ CiscoAuthPlugin (self .__username , self .__password )
290+ )
291+ logging .debug ("Using username/password call authentication." )
292+ if channel_ssl_creds and channel_metadata_creds :
293+ channel_creds = grpc .composite_channel_credentials (
294+ channel_ssl_creds , channel_metadata_creds
295+ )
296+ logging .debug ("Using SSL/metadata authentication composite credentials." )
297+ elif channel_ssl_creds :
298+ channel_creds = channel_ssl_creds
299+ logging .debug ("Using SSL credentials, no metadata authentication." )
300+ if channel_creds :
301+ if self .__ssl_target_name_override is not False :
302+ if self .__ssl_target_name_override is None :
303+ if not self .__root_certificates :
304+ raise Exception ("Deriving override requires root certificate!" )
305+ self .__ssl_target_name_override = get_cn_from_cert (
306+ self .__root_certificates
307+ )
308+ logging .warning (
309+ "Overriding SSL option from certificate could increase MITM susceptibility!"
310+ )
311+ self .set_channel_option (
312+ "grpc.ssl_target_name_override" , self .__ssl_target_name_override
313+ )
314+ channel = grpc .secure_channel (
315+ self .__target_netloc .netloc , channel_creds , self .__channel_options
316+ )
317+ else :
318+ channel = grpc .insecure_channel (self .__target_netloc .netloc )
319+ if self .__client_class is None :
320+ self .set_os ()
321+ client = self .__client_class (channel )
322+ self ._reset ()
323+ return client
324+
325+ def save_construct (self ):
326+ """Constructs and returns the desired Client object.
327+ The instance of this class will reset to default values for further building.
328+
274329 Returns
275330 -------
276331 Client or NXClient or XEClient or XRClient
0 commit comments