Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ftd httpapi plugin: handle missing urllib3 imports #150

Merged
merged 2 commits into from
Nov 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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