aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2023-01-04 15:49:04 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2023-01-04 15:49:04 +0100
commitdd0c15c8b264341c1fb8e4e862467c1bbcfacb55 (patch)
treed96b9c6f903e26fb0dfeef7e30a96675046545db
parent7c9a41df72a0a2610bb2ba76728c665af51e0ab8 (diff)
parentf80921ec8e917216ad891860fb32801b741838ec (diff)
downloadpython-phpipam-dd0c15c8b264341c1fb8e4e862467c1bbcfacb55.tar.gz
Merge branch 'danielbolsson-master'
-rw-r--r--README.md2
-rwxr-xr-xphpipam_api/__init__.py6
-rwxr-xr-xphpipam_api/backend.py12
-rwxr-xr-xphpipam_api/resources.py2
4 files changed, 13 insertions, 9 deletions
diff --git a/README.md b/README.md
index 59ba87c..e3c7c97 100644
--- a/README.md
+++ b/README.md
@@ -25,7 +25,7 @@ Functions shared by all controllers:
* `get()` returns all obejcts in in controller
* `byID(object_id=<object id>)` get specific obejct by ID
* `create(data=<data>)`
-* `edit(data=<data>)`
+* `edit(object_id=<object id>, data=<data>)`
* `delete(object_id=<object id>)`
### sections
diff --git a/phpipam_api/__init__.py b/phpipam_api/__init__.py
index 1dc065f..f579572 100755
--- a/phpipam_api/__init__.py
+++ b/phpipam_api/__init__.py
@@ -20,7 +20,7 @@ class PhpipamAPI:
https://phpipam.net/api-documentation/
"""
- def __init__(self, api_url, app_id, api_user, api_password):
+ def __init__(self, api_url, app_id, api_user, api_password, verify=True):
"""
Parameters
----------
@@ -32,9 +32,11 @@ class PhpipamAPI:
username, leave empty to use static token authentification
api_password : str
password or static authentification token
+ verify : Bool (optional)
+ verify API server SSL certificate
"""
- self._backend = PhpipamBackend(api_url, app_id, api_user, api_password)
+ self._backend = PhpipamBackend(api_url, app_id, api_user, api_password, verify)
def __getattr__(self, item):
return PhpipamResource(self._backend, item)
diff --git a/phpipam_api/backend.py b/phpipam_api/backend.py
index 85079df..b334ed2 100755
--- a/phpipam_api/backend.py
+++ b/phpipam_api/backend.py
@@ -18,10 +18,11 @@ class ApiObjectNotFoundException(Exception):
pass
class PhpipamBackend:
- def __init__(self, api_url, app_id, api_user, api_password):
+ def __init__(self, api_url, app_id, api_user, api_password, verify):
self.api_url = api_url.strip('/') + '/api/' + app_id
self.api_user = api_user
self.api_password = api_password
+ self.verify = verify
# Check for static auth
if len(self.api_user) == 0:
@@ -31,7 +32,7 @@ class PhpipamBackend:
self._getApiToken()
def _getApiToken(self):
- data = requests.post(self.api_url + "/user", auth=(self.api_user,self.api_password)).json()
+ data = requests.post(self.api_url + "/user", auth=(self.api_user,self.api_password), verify=self.verify).json()
if not data['success']:
raise ApiConnectionException('Failed to authenticate: ' + str(data['code']) + ' ' + data['message'])
@@ -52,10 +53,11 @@ class PhpipamBackend:
if self._isTokenExpired():
self._getApiToken()
- data = requests.request(method, self.api_url + url, data=data, headers={'token':self.api_token}).json()
+ data = requests.request(method, self.api_url + url, data=data, headers={'token':self.api_token}, verify=self.verify).json()
if not 'success' in data or not data['success']:
raise ApiQueryException("Query failed with code " + str(data['code']) + ": " + str(data['message']))
-
- return data['data']
+ if 'data' in data:
+ return data['data']
+ return data
diff --git a/phpipam_api/resources.py b/phpipam_api/resources.py
index 8f44c17..b8faef5 100755
--- a/phpipam_api/resources.py
+++ b/phpipam_api/resources.py
@@ -127,7 +127,7 @@ class PhpipamResource:
def create(self, data):
return self._backend.request('POST', f'/{self._type}/{object_id}', data=data)
- def edit(self, data):
+ def edit(self, object_id, data):
return self._backend.request('PATCH', f'/{self._type}/{object_id}', data=data)
def delete(self, object_id):