Skip to content

Commit

Permalink
Merge pull request #252 from digitalocean/remove-ssl-verify
Browse files Browse the repository at this point in the history
Remove ssl_verify init kwarg
  • Loading branch information
Zach Moody authored Jun 24, 2020
2 parents 0fc7373 + 190f87a commit ce74ebb
Show file tree
Hide file tree
Showing 13 changed files with 2 additions and 100 deletions.
11 changes: 1 addition & 10 deletions pynetbox/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,12 @@ class Api(object):
Calling any of these attributes will return
:py:class:`.App` which exposes endpoints as attributes.
:type ssl_verify: bool or str
:param str url: The base URL to the instance of NetBox you
wish to connect to.
:param str token: Your NetBox token.
:param str,optional private_key_file: The path to your private
key file.
:param str,optional private_key: Your private key.
:param bool/str,optional ssl_verify: Specify SSL verification behavior
see: requests_.
:param bool,optional threading: Set to True to use threading in ``.all()``
and ``.filter()`` requests.
:raises ValueError: If *private_key* and *private_key_file* are both
Expand All @@ -62,17 +59,14 @@ class Api(object):
... token='d6f4e314a5b5fefd164995169f28ae32d987704f'
... )
>>> nb.dcim.devices.all()
.. _requests: http://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification
""" # noqa
"""

def __init__(
self,
url,
token=None,
private_key=None,
private_key_file=None,
ssl_verify=True,
threading=False,
):
if private_key and private_key_file:
Expand All @@ -84,7 +78,6 @@ def __init__(
self.private_key = private_key
self.private_key_file = private_key_file
self.base_url = base_url
self.ssl_verify = ssl_verify
self.session_key = None
self.http_session = requests.Session()
if threading and sys.version_info.major == 2:
Expand Down Expand Up @@ -127,7 +120,6 @@ def version(self):
"""
version = Request(
base=self.base_url,
ssl_verify=self.ssl_verify,
http_session=self.http_session,
).get_version()
return version
Expand All @@ -152,6 +144,5 @@ def openapi(self):
"""
return Request(
base=self.base_url,
ssl_verify=self.ssl_verify,
http_session=self.http_session,
).get_openapi()
3 changes: 0 additions & 3 deletions pynetbox/core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def _set_session_key(self):
base=self.api.base_url,
token=self.api.token,
private_key=self.api.private_key,
ssl_verify=self.api.ssl_verify,
http_session=self.api.http_session
).get_session_key()

Expand All @@ -90,7 +89,6 @@ def choices(self):
base="{}/{}/_choices/".format(self.api.base_url, self.name),
token=self.api.token,
private_key=self.api.private_key,
ssl_verify=self.api.ssl_verify,
http_session=self.api.http_session,
).get()

Expand All @@ -114,7 +112,6 @@ def custom_choices(self):
),
token=self.api.token,
private_key=self.api.private_key,
ssl_verify=self.api.ssl_verify,
http_session=self.api.http_session,
).get()
return custom_field_choices
8 changes: 0 additions & 8 deletions pynetbox/core/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def __init__(self, api, app, name, model=None):
self.base_url = api.base_url
self.token = api.token
self.session_key = api.session_key
self.ssl_verify = api.ssl_verify
self.url = "{base_url}/{app}/{endpoint}".format(
base_url=self.base_url,
app=app.name,
Expand Down Expand Up @@ -94,7 +93,6 @@ def all(self):
base="{}/".format(self.url),
token=self.token,
session_key=self.session_key,
ssl_verify=self.ssl_verify,
http_session=self.api.http_session,
threading=self.api.threading,
)
Expand Down Expand Up @@ -154,7 +152,6 @@ def get(self, *args, **kwargs):
base=self.url,
token=self.token,
session_key=self.session_key,
ssl_verify=self.ssl_verify,
http_session=self.api.http_session,
)
except RequestError:
Expand Down Expand Up @@ -222,7 +219,6 @@ def filter(self, *args, **kwargs):
base=self.url,
token=self.token,
session_key=self.session_key,
ssl_verify=self.ssl_verify,
http_session=self.api.http_session,
threading=self.api.threading,
)
Expand Down Expand Up @@ -285,7 +281,6 @@ def create(self, *args, **kwargs):
base=self.url,
token=self.token,
session_key=self.session_key,
ssl_verify=self.ssl_verify,
http_session=self.api.http_session,
).post(args[0] if args else kwargs)

Expand Down Expand Up @@ -330,7 +325,6 @@ def choices(self):
base=self.url,
token=self.api.token,
private_key=self.api.private_key,
ssl_verify=self.api.ssl_verify,
http_session=self.api.http_session,
).options()
try:
Expand Down Expand Up @@ -393,7 +387,6 @@ def count(self, *args, **kwargs):
base=self.url,
token=self.token,
session_key=self.session_key,
ssl_verify=self.ssl_verify,
http_session=self.api.http_session,
)

Expand All @@ -417,7 +410,6 @@ def __init__(self, parent_obj, name, custom_return=None):
base=self.url,
token=parent_obj.api.token,
session_key=parent_obj.api.session_key,
ssl_verify=parent_obj.api.ssl_verify,
http_session=parent_obj.api.http_session,
)

Expand Down
7 changes: 1 addition & 6 deletions pynetbox/core/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def __init__(
token=None,
private_key=None,
session_key=None,
ssl_verify=True,
threading=False,
):
"""
Expand All @@ -170,7 +169,6 @@ def __init__(
self.token = token
self.private_key = private_key
self.session_key = session_key
self.ssl_verify = ssl_verify
self.http_session = http_session
self.url = self.base if not key else "{}{}/".format(self.base, key)
self.threading = threading
Expand All @@ -183,7 +181,6 @@ def get_openapi(self):
req = self.http_session.get(
"{}docs/?format=openapi".format(self.normalize_url(self.base)),
headers=headers,
verify=self.ssl_verify,
)
if req.ok:
return req.json()
Expand All @@ -206,7 +203,6 @@ def get_version(self):
req = requests.get(
self.normalize_url(self.base),
headers=headers,
verify=self.ssl_verify,
)
if req.ok:
return req.headers.get("API-Version", "")
Expand All @@ -229,7 +225,6 @@ def get_session_key(self):
"Content-Type": "application/x-www-form-urlencoded",
},
data=urlencode({"private_key": self.private_key.strip("\n")}),
verify=self.ssl_verify,
)
if req.ok:
try:
Expand Down Expand Up @@ -268,7 +263,7 @@ def _make_call(
params.update(add_params)

req = getattr(self.http_session, verb)(
url_override or self.url, headers=headers, verify=self.ssl_verify,
url_override or self.url, headers=headers,
params=params, json=data
)

Expand Down
3 changes: 0 additions & 3 deletions pynetbox/core/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ def full_details(self):
base=self.url,
token=self.api.token,
session_key=self.api.session_key,
ssl_verify=self.api.ssl_verify,
http_session=self.api.http_session,
)
self._parse_values(req.get())
Expand Down Expand Up @@ -400,7 +399,6 @@ def save(self):
base=self.endpoint.url,
token=self.api.token,
session_key=self.api.session_key,
ssl_verify=self.api.ssl_verify,
http_session=self.api.http_session,
)
if req.patch({i: serialized[i] for i in diff}):
Expand Down Expand Up @@ -449,7 +447,6 @@ def delete(self):
base=self.endpoint.url,
token=self.api.token,
session_key=self.api.session_key,
ssl_verify=self.api.ssl_verify,
http_session=self.api.http_session,
)
return True if req.delete() else False
36 changes: 0 additions & 36 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,42 +53,6 @@ def test_sanitize_url(self, *_):
self.assertEqual(api.base_url, 'http://localhost:8000/api')


class ApiArgumentsTestCase(unittest.TestCase):

@patch(
'pynetbox.core.query.requests.sessions.Session.post',
return_value=Response(fixture='api/get_session_key.json')
)
def common_arguments(self, kwargs, arg, expect, *_):
'''
Ensures the api and endpoint instances have ssl_verify set
as expected
'''
api = pynetbox.api(
host,
**kwargs
)
self.assertIs(getattr(api, arg, "fail"), expect)
for app, endpoint in endpoints.items():
ep = getattr(getattr(api, app), endpoint)
self.assertIs(getattr(ep, arg), expect)

def test_ssl_verify_default(self):
self.common_arguments(def_kwargs, 'ssl_verify', True)

def test_ssl_verify_true(self):
kwargs = dict(def_kwargs, **{'ssl_verify': True})
self.common_arguments(kwargs, 'ssl_verify', True)

def test_ssl_verify_false(self):
kwargs = dict(def_kwargs, **{'ssl_verify': False})
self.common_arguments(kwargs, 'ssl_verify', False)

def test_ssl_verify_string(self):
kwargs = dict(def_kwargs, **{'ssl_verify': '/path/to/bundle'})
self.common_arguments(kwargs, 'ssl_verify', '/path/to/bundle')


class ApiVersionTestCase(unittest.TestCase):

class ResponseHeadersWithVersion:
Expand Down
3 changes: 0 additions & 3 deletions tests/test_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def test_get_all(self):
params={},
json=None,
headers=HEADERS,
verify=True
)

def test_filter(self):
Expand All @@ -69,7 +68,6 @@ def test_filter(self):
params={"name": "test"},
json=None,
headers=HEADERS,
verify=True
)

def test_get(self):
Expand All @@ -91,7 +89,6 @@ def test_get(self):
params={},
json=None,
headers=HEADERS,
verify=True
)


Expand Down
13 changes: 0 additions & 13 deletions tests/test_dcim.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def test_get_all(self):
params={},
json=None,
headers=HEADERS,
verify=True
)

def test_filter(self):
Expand All @@ -72,7 +71,6 @@ def test_filter(self):
params={"name": "test"},
json=None,
headers=HEADERS,
verify=True
)

def test_get(self):
Expand All @@ -96,7 +94,6 @@ def test_get(self):
params={},
json=None,
headers=HEADERS,
verify=True
)

def test_delete(self):
Expand All @@ -117,7 +114,6 @@ def test_delete(self):
params={},
json=None,
headers=HEADERS,
verify=True
)
delete.assert_called_with(
'http://localhost:8000/api/{}/{}/1/'.format(
Expand All @@ -127,7 +123,6 @@ def test_delete(self):
params={},
json=None,
headers=HEADERS,
verify=True
)

def test_compare(self):
Expand Down Expand Up @@ -179,7 +174,6 @@ def test_get(self, mock):
params={},
json=None,
headers=HEADERS,
verify=True
)

@patch(
Expand All @@ -199,7 +193,6 @@ def test_multi_filter(self, mock):
params={'role': ['test', 'test1'], 'site': 'TEST#1'},
json=None,
headers=HEADERS,
verify=True
)

@patch(
Expand Down Expand Up @@ -285,7 +278,6 @@ def test_get_napalm(self, mock):
params={"method": "get_facts"},
json=None,
headers=HEADERS,
verify=True,
)
self.assertTrue(ret)
self.assertTrue(ret['get_facts'])
Expand Down Expand Up @@ -372,7 +364,6 @@ def test_get_all(self, mock):
params={"limit": 221, "offset": 50},
json=None,
headers=HEADERS,
verify=True
)


Expand All @@ -394,7 +385,6 @@ def test_get_units(self, mock):
params={},
json=None,
headers=HEADERS,
verify=True,
)
self.assertTrue(ret)
self.assertTrue(
Expand All @@ -416,7 +406,6 @@ def test_get_elevation(self, mock):
params={},
json=None,
headers=HEADERS,
verify=True,
)
self.assertTrue(ret)
self.assertTrue(
Expand Down Expand Up @@ -533,7 +522,6 @@ def test_get(self):
params={},
json=None,
headers=HEADERS,
verify=True
)


Expand Down Expand Up @@ -596,5 +584,4 @@ def test_get_circuit(self):
headers=HEADERS,
params={},
json=None,
verify=True
)
Loading

0 comments on commit ce74ebb

Please sign in to comment.