Skip to content

Commit

Permalink
Fix CertificateError import in Ansible devel. (#1127)
Browse files Browse the repository at this point in the history
  • Loading branch information
BGmot authored Nov 13, 2023
1 parent 4d7f533 commit 1365f11
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions plugins/module_utils/api_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@

from uuid import uuid4

from ssl import CertificateError
from ansible.module_utils.connection import ConnectionError
from ansible.module_utils.connection import Connection
from ansible.module_utils._text import to_text
try:
from ansible.module_utils.urls import CertificateError
HAS_CERT_ERROR = True
except ImportError:
HAS_CERT_ERROR = False


class ZabbixApiRequest(object):
Expand All @@ -29,22 +25,14 @@ def __init__(self, module):
self.connection = Connection(self.module._socket_path)

def _httpapi_error_handle(self, payload=None):
if HAS_CERT_ERROR:
try:
code, response = self.connection.send_request(data=payload)
except ConnectionError as e:
self.module.fail_json(msg="connection error occurred: {0}".format(e))
except CertificateError as e:
self.module.fail_json(msg="certificate error occurred: {0}".format(e))
except ValueError as e:
self.module.fail_json(msg="certificate not found: {0}".format(e))
else:
try:
code, response = self.connection.send_request(data=payload)
except ConnectionError as e:
self.module.fail_json(msg="connection error occurred: {0}".format(e))
except ValueError as e:
self.module.fail_json(msg="certificate not found: {0}".format(e))
try:
code, response = self.connection.send_request(data=payload)
except ConnectionError as e:
self.module.fail_json(msg="connection error occurred: {0}".format(e))
except CertificateError as e:
self.module.fail_json(msg="certificate error occurred: {0}".format(e))
except ValueError as e:
self.module.fail_json(msg="certificate not found: {0}".format(e))

if code == 404:
if to_text(u"Object not found") in to_text(response) or to_text(
Expand Down

0 comments on commit 1365f11

Please sign in to comment.