Skip to content

Commit

Permalink
ftd httpapi plugin: handle missing urllib3 imports (#150) (#152)
Browse files Browse the repository at this point in the history
* ftd httpapi plugin: handle missing urllib3 imports

(cherry picked from commit 172ba15)

Co-authored-by: Felix Fontein <[email protected]>
  • Loading branch information
patchback[bot] and felixfontein authored Nov 14, 2020
1 parent f3eaa48 commit d136513
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/ftd-imports.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "ftd httpapi plugin - make sure that plugin errors out on initialization if the required library is not found, and not on load-time (https://github.com/ansible-collections/community.network/pull/150)."
15 changes: 12 additions & 3 deletions plugins/httpapi/ftd.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,22 @@
from ansible import __version__ as ansible_version

from ansible.module_utils.basic import to_text
from ansible.errors import AnsibleConnectionFailure
from ansible.errors import AnsibleConnectionFailure, AnsibleError
from ansible_collections.community.network.plugins.module_utils.network.ftd.fdm_swagger_client import FdmSwaggerParser, SpecProp, FdmSwaggerValidator
from ansible_collections.community.network.plugins.module_utils.network.ftd.common import HTTPMethod, ResponseParams
from ansible.module_utils.six.moves.urllib.error import HTTPError
from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.plugins.httpapi import HttpApiBase
from urllib3 import encode_multipart_formdata
from urllib3.fields import RequestField
from ansible.module_utils.connection import ConnectionError

try:
from urllib3 import encode_multipart_formdata
from urllib3.fields import RequestField
HAS_URLLIB3 = True
except ImportError:
HAS_URLLIB3 = False


BASE_HEADERS = {
'Content-Type': 'application/json',
'Accept': 'application/json',
Expand Down Expand Up @@ -89,6 +95,9 @@ def __init__(self, connection):
self._api_spec = None
self._api_validator = None
self._ignore_http_errors = False
if not HAS_URLLIB3:
raise AnsibleError(
'The community.network.ftd httpapi plugin requires urllib3. Use `pip install urllib3` to install it')

def login(self, username, password):
def request_token_payload(username, password):
Expand Down

0 comments on commit d136513

Please sign in to comment.