aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar daniel.x.olsson@ri.se <daniel.b.olsson@gmail.com> 2023-01-02 15:30:55 +0100
committerGravatar daniel.x.olsson@ri.se <daniel.b.olsson@gmail.com> 2023-01-02 15:30:55 +0100
commit2fd3f9fb2b6fcaee2a579722cee91d13d5e87ecd (patch)
tree1ee1bf183926ec88cc1ac4d6b924564b9ff17660
parent7c9a41df72a0a2610bb2ba76728c665af51e0ab8 (diff)
downloadpython-phpipam-2fd3f9fb2b6fcaee2a579722cee91d13d5e87ecd.tar.gz
Added SSL verify option and fixed edit function
-rw-r--r--README.md2
-rwxr-xr-xphpipam_api/backend.py12
-rwxr-xr-xphpipam_api/resources.py2
3 files changed, 9 insertions, 7 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/backend.py b/phpipam_api/backend.py
index 85079df..b5ad180 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=True):
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):