NSO - added validate_certs parameter to allow for ignoring of SSL certificates (#51981)

* added validate_certs paramter to allow for ignoring of SSL certificates

* formatting

* updated NSO unit tests with validate_certs variable

* fixed NSO tests
This commit is contained in:
Theron Savery 2019-02-25 09:17:56 -05:00 committed by John R Barker
commit 1f7ffe2619
9 changed files with 46 additions and 26 deletions

View file

@ -23,6 +23,7 @@ nso_argument_spec = dict(
username=dict(type='str', required=True, fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])),
password=dict(type='str', required=True, no_log=True, fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD'])),
timeout=dict(type='int', default=300),
validate_certs=dict(type='bool', default=False)
)
@ -52,10 +53,10 @@ class NsoException(Exception):
class JsonRpc(object):
def __init__(self, url, timeout):
def __init__(self, url, timeout, validate_certs):
self._url = url
self._timeout = timeout
self._validate_certs = validate_certs
self._id = 0
self._trans = {}
self._headers = {'Content-Type': 'application/json'}
@ -224,7 +225,8 @@ class JsonRpc(object):
data = json.dumps(payload)
resp = open_url(
self._url, timeout=self._timeout,
method='POST', data=data, headers=self._headers)
method='POST', data=data, headers=self._headers,
validate_certs=self._validate_certs)
if resp.code != 200:
raise NsoException(
'NSO returned HTTP code {0}, expected 200'.format(resp.status), {})
@ -635,7 +637,9 @@ class ValueBuilder(object):
def connect(params):
client = JsonRpc(params['url'], params['timeout'])
client = JsonRpc(params['url'],
params['timeout'],
params['validate_certs'])
client.login(params['username'], params['password'])
return client