Skip to content

Commit

Permalink
v0.5.0 release (#10)
Browse files Browse the repository at this point in the history
* added proper content type header to all requests

* convert data to json

* strip None values on write request
  • Loading branch information
lampwins authored Aug 25, 2018
1 parent 0bb9375 commit 7a78756
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Change Log
## 0.5.0
- Added proper application/json Content-Type header to all requests
## 0.4.2
- Changed the `id` parameter on `ipam_post_available_ips` to `prefix_id` so it does not auto convert to a detail route
## 0.4.1
Expand Down
13 changes: 9 additions & 4 deletions actions/lib/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,34 @@ def _make_request(self, endpoint_uri, http_action, **kwargs):

headers = {
'Authorization': 'Token ' + self.config['api_token'],
'Accept': 'application/json'
'Accept': 'application/json',
'Content-Type': 'application/json',
}

# transform `in__id` if present
if kwargs.get('id__in'):
kwargs['id__in'] = ','.join(kwargs['id__in'])
self.logger.debug('id__in transformed to {}'.format(kwargs['id__in']))

# strip values which have a None value if we are making a write request
if http_action != "GET":
kwargs = {key: value for key, value in kwargs.items() if value is not None}

if http_action == "GET":
self.logger.debug("Calling base get with kwargs: {}".format(kwargs))
r = requests.get(url, verify=self.config['ssl_verify'], headers=headers, params=kwargs)

elif http_action == "POST":
self.logger.debug("Calling base post with kwargs: {}".format(kwargs))
r = requests.post(url, verify=self.config['ssl_verify'], headers=headers, data=kwargs)
r = requests.post(url, verify=self.config['ssl_verify'], headers=headers, json=kwargs)

elif http_action == "PUT":
self.logger.debug("Calling base put with kwargs: {}".format(kwargs))
r = requests.put(url, verify=self.config['ssl_verify'], headers=headers, data=kwargs)
r = requests.put(url, verify=self.config['ssl_verify'], headers=headers, json=kwargs)

elif http_action == "PATCH":
self.logger.debug("Calling base patch with kwargs: {}".format(kwargs))
r = requests.patch(url, verify=self.config['ssl_verify'], headers=headers, data=kwargs)
r = requests.patch(url, verify=self.config['ssl_verify'], headers=headers, json=kwargs)

return {'raw': r.json()}

Expand Down
2 changes: 1 addition & 1 deletion pack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ keywords:
- networking
- ipam
- dcim
version: 0.4.2
version: 0.5.0
author: John Anderson, Jefferson White
email: [email protected]

0 comments on commit 7a78756

Please sign in to comment.