@@ -431,6 +431,8 @@ class Context(object):
431
431
:type port: ``integer``
432
432
:param scheme: The scheme for accessing the service (the default is "https").
433
433
:type scheme: "https" or "http"
434
+ :param verify: Enable (True) or disable (False) SSL verrification for https connections.
435
+ :type verify: ``Boolean``
434
436
:param sharing: The sharing mode for the namespace (the default is "user").
435
437
:type sharing: "global", "system", "app", or "user"
436
438
:param owner: The owner context of the namespace (optional, the default is "None").
@@ -463,7 +465,7 @@ class Context(object):
463
465
c = binding.Context(cookie="splunkd_8089=...")
464
466
"""
465
467
def __init__ (self , handler = None , ** kwargs ):
466
- self .http = HttpLib (handler )
468
+ self .http = HttpLib (handler , kwargs . get ( "verify" , True ) )
467
469
self .token = kwargs .get ("token" , _NoAuthenticationToken )
468
470
if self .token is None : # In case someone explicitly passes token=None
469
471
self .token = _NoAuthenticationToken
@@ -1103,9 +1105,11 @@ class HttpLib(object):
1103
1105
The response dictionary is returned directly by ``HttpLib``'s methods with
1104
1106
no further processing. By default, ``HttpLib`` calls the :func:`handler` function
1105
1107
to get a handler function.
1108
+
1109
+ If using the default handler, SSL verification can be disabled by passing verify=False.
1106
1110
"""
1107
- def __init__ (self , custom_handler = None ):
1108
- self .handler = handler () if custom_handler is None else custom_handler
1111
+ def __init__ (self , custom_handler = None , verify = True ):
1112
+ self .handler = handler (verify = verify ) if custom_handler is None else custom_handler
1109
1113
self ._cookies = {}
1110
1114
1111
1115
def delete (self , url , headers = None , ** kwargs ):
@@ -1313,7 +1317,7 @@ def readinto(self, byte_array):
1313
1317
return bytes_read
1314
1318
1315
1319
1316
- def handler (key_file = None , cert_file = None , timeout = None ):
1320
+ def handler (key_file = None , cert_file = None , timeout = None , verify = True ):
1317
1321
"""This class returns an instance of the default HTTP request handler using
1318
1322
the values you provide.
1319
1323
@@ -1323,6 +1327,8 @@ def handler(key_file=None, cert_file=None, timeout=None):
1323
1327
:type cert_file: ``string``
1324
1328
:param `timeout`: The request time-out period, in seconds (optional).
1325
1329
:type timeout: ``integer`` or "None"
1330
+ :param `verify`: Set to False to disable SSL verification on https connections.
1331
+ :type verify: ``Boolean``
1326
1332
"""
1327
1333
1328
1334
def connect (scheme , host , port ):
@@ -1335,7 +1341,7 @@ def connect(scheme, host, port):
1335
1341
if cert_file is not None : kwargs ['cert_file' ] = cert_file
1336
1342
1337
1343
# If running Python 2.7.9+, disable SSL certificate validation
1338
- if sys .version_info >= (2 ,7 ,9 ) and key_file is None and cert_file is None :
1344
+ if ( sys .version_info >= (2 ,7 ,9 ) and key_file is None and cert_file is None ) or not verify :
1339
1345
kwargs ['context' ] = ssl ._create_unverified_context ()
1340
1346
return six .moves .http_client .HTTPSConnection (host , port , ** kwargs )
1341
1347
raise ValueError ("unsupported scheme: %s" % scheme )
0 commit comments