Skip to content

Commit

Permalink
sanatize the returned results - just in case API is messed up
Browse files Browse the repository at this point in the history
  • Loading branch information
mahtin committed Dec 11, 2016
1 parent 080733b commit 52dda2e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Change Log

- 2016-12-10 15:39:29 -0800 [080733b](https://github.com/cloudflare/python-cloudflare/commit/080733b58e144670116d7f3ccadf369d599bfc61) CHANGELOG.md pushed to github
- 2016-12-10 15:39:01 -0800 [f3d6377](https://github.com/cloudflare/python-cloudflare/commit/f3d637727d74acecd8faf4c9b6d652ee2cff183f) 1.4.1 release
- 2016-12-10 15:38:10 -0800 [8c66d32](https://github.com/cloudflare/python-cloudflare/commit/8c66d3253b6f257b61b0116600fb2b3d77e8f0fb) cleanup of yaml print output if yaml package isnt installed
- 2016-12-09 16:22:51 -0800 [894ae11](https://github.com/cloudflare/python-cloudflare/commit/894ae11788a2b1997e4f58895d205d1f74ab16f7) Moved walk into CloudFlare class - much cleaner
Expand Down
23 changes: 22 additions & 1 deletion CloudFlare/cloudflare.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def call_with_certauth(self, method,
params=None, data=None):
""" Cloudflare v4 API"""

if self.certtoken is '':
if self.certtoken is '' or self.certtoken is None:
raise CloudFlareAPIError(0, 'no cert token defined')
headers = {
'X-Auth-User-Service-Key': self.certtoken,
Expand Down Expand Up @@ -184,6 +184,27 @@ def _call(self, method, headers,
api_call_part1, api_call_part2, api_call_part3,
identifier1, identifier2,
params, data)

# Sanatize the returned results - just in case API is messed up
if 'success' not in response_data:
if 'errors' in response_data:
if self.logger:
self.logger.debug('Response: missing success value - assuming success = "False"')
response_data['success'] = False
else:
if 'result' not in response_data:
# Only happens on /certificates call - and should be fixed in /certificates API
if self.logger:
self.logger.debug('Response: missing success and error value - assuming success = "False"')
r = response_data
response_data['errors'] = []
response_data['errors'].append(r)
response_data['success'] = False
else:
if self.logger:
self.logger.debug('Response: missing success value - assuming success = "True"')
response_data['success'] = True

if response_data['success'] is False:
errors = response_data['errors'][0]
code = errors['code']
Expand Down

0 comments on commit 52dda2e

Please sign in to comment.