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

Remove vendored copy of ipaddress #287

Merged
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
3 changes: 3 additions & 0 deletions changelogs/fragments/287-remove-ipaddress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
breaking_changes:
- "acme_* modules - removed vendored copy of the Python library ``ipaddress``. If you are using Python 2.x, please make sure to install the library (https://github.com/ansible-collections/community.crypto/pull/287)."
- "compatibility module_utils - removed vendored copy of the Python library ``ipaddress`` (https://github.com/ansible-collections/community.crypto/pull/287)."
2 changes: 1 addition & 1 deletion plugins/doc_fragments/acme.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class ModuleDocFragment(object):
principle be used with any CA providing an ACME endpoint, such as
L(Buypass Go SSL,https://www.buypass.com/ssl/products/acme)."
requirements:
- python >= 2.6
- either openssl or L(cryptography,https://cryptography.io/) >= 1.5
- ipaddress
options:
account_key_src:
description:
Expand Down
12 changes: 12 additions & 0 deletions plugins/module_utils/acme/acme.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import datetime
import json
import locale
import traceback
felixfontein marked this conversation as resolved.
Show resolved Hide resolved

from ansible.module_utils.basic import missing_required_lib
from ansible.module_utils.urls import fetch_url
Expand All @@ -38,6 +39,14 @@
nopad_b64,
)

try:
import ipaddress
except ImportError:
HAS_IPADDRESS = False
IPADDRESS_IMPORT_ERROR = traceback.format_exc()
else:
HAS_IPADDRESS = True
felixfontein marked this conversation as resolved.
Show resolved Hide resolved


def _assert_fetch_url_success(module, response, info, allow_redirect=False, allow_client_error=True, allow_server_error=True):
if info['status'] < 0:
Expand Down Expand Up @@ -327,6 +336,9 @@ def get_default_argspec():


def create_backend(module, needs_acme_v2):
if not HAS_IPADDRESS:
module.fail_json(msg=missing_required_lib('ipaddress'), exception=IPADDRESS_IMPORT_ERROR)
felixfontein marked this conversation as resolved.
Show resolved Hide resolved

backend = module.params['select_crypto_backend']

# Backend autodetect
Expand Down
7 changes: 5 additions & 2 deletions plugins/module_utils/acme/backend_openssl_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@

from ansible_collections.community.crypto.plugins.module_utils.acme.utils import nopad_b64

from ansible_collections.community.crypto.plugins.module_utils.compat import ipaddress as compat_ipaddress
try:
import ipaddress
except ImportError:
pass
felixfontein marked this conversation as resolved.
Show resolved Hide resolved


_OPENSSL_ENVIRONMENT_UPDATE = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C', LC_CTYPE='C')
Expand Down Expand Up @@ -216,7 +219,7 @@ def create_mac_key(self, alg, key):
@staticmethod
def _normalize_ip(ip):
try:
return to_native(compat_ipaddress.ip_address(to_text(ip)).compressed)
return to_native(ipaddress.ip_address(to_text(ip)).compressed)
except ValueError:
# We don't want to error out on something IPAddress() can't parse
return ip
Expand Down
9 changes: 6 additions & 3 deletions plugins/module_utils/acme/challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

from ansible.module_utils.common.text.converters import to_bytes

from ansible_collections.community.crypto.plugins.module_utils.compat import ipaddress as compat_ipaddress

from ansible_collections.community.crypto.plugins.module_utils.acme.utils import (
nopad_b64,
)
Expand All @@ -28,6 +26,11 @@
ModuleFailException,
)

try:
import ipaddress
except ImportError:
pass
felixfontein marked this conversation as resolved.
Show resolved Hide resolved


def create_key_authorization(client, token):
'''
Expand Down Expand Up @@ -110,7 +113,7 @@ def get_validation_data(self, client, identifier_type, identifier):
# https://www.rfc-editor.org/rfc/rfc8737.html#section-3
if identifier_type == 'ip':
# IPv4/IPv6 address: use reverse mapping (RFC1034, RFC3596)
resource = compat_ipaddress.ip_address(identifier).reverse_pointer
resource = ipaddress.ip_address(identifier).reverse_pointer
if not resource.endswith('.'):
resource += '.'
else:
Expand Down
Loading