diff options
author | Michael Grüner <michael.gruener@chaosmoon.net> | 2016-09-14 14:16:51 +0200 |
---|---|---|
committer | René Moser <mail@renemoser.net> | 2016-09-14 14:16:51 +0200 |
commit | d69a6f20daadf802e987697259ce40b41684f4bc (patch) | |
tree | 4821fd5a42625fbbb26b915818c78e3013294796 | |
parent | 2b6f3419b6c3103195d576996c9464b334fb6489 (diff) | |
download | ansible-modules-extras-d69a6f20daadf802e987697259ce40b41684f4bc.tar.gz |
letsencrypt: Improve error handling (#2868)
* letsencrypt: improve error handling
Use the new "body" field of the info dict in case of a HTTPError.
* letsencrypt: HTTP 202 is a valid status while polling
-rw-r--r-- | web_infrastructure/letsencrypt.py | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/web_infrastructure/letsencrypt.py b/web_infrastructure/letsencrypt.py index 2b792285..d5afebea 100644 --- a/web_infrastructure/letsencrypt.py +++ b/web_infrastructure/letsencrypt.py @@ -169,14 +169,18 @@ def simple_get(module,url): result = None try: content = resp.read() + except AttributeError: + if info['body']: + content = info['body'] + + if content: if info['content-type'].startswith('application/json'): - result = module.from_json(content.decode('utf8')) + try: + result = module.from_json(content.decode('utf8')) + except ValueError: + module.fail_json(msg="Failed to parse the ACME response: {0} {1}".format(url,content)) else: result = content - except AttributeError: - result = None - except ValueError: - module.fail_json(msg="Failed to parse the ACME response: {0} {1}".format(url,content)) if info['status'] >= 400: module.fail_json(msg="ACME request failed: CODE: {0} RESULT:{1}".format(info['status'],result)) @@ -370,14 +374,18 @@ class ACMEAccount(object): result = None try: content = resp.read() + except AttributeError: + if info['body']: + content = info['body'] + + if content: if info['content-type'].startswith('application/json'): - result = self.module.from_json(content.decode('utf8')) + try: + result = self.module.from_json(content.decode('utf8')) + except ValueError: + self.module.fail_json(msg="Failed to parse the ACME response: {0} {1}".format(url,content)) else: result = content - except AttributeError: - result = None - except ValueError: - self.module.fail_json(msg="Failed to parse the ACME response: {0} {1}".format(url,content)) return result,info @@ -637,7 +645,7 @@ class ACMEClient(object): "keyAuthorization": keyauthorization, } result, info = self.account.send_signed_request(uri, challenge_response) - if info['status'] != 200: + if info['status'] not in [200,202]: self.module.fail_json(msg="Error validating challenge: CODE: {0} RESULT: {1}".format(info['status'], result)) status = '' |