Skip to content

Commit

Permalink
Use new interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Feb 2, 2021
1 parent 36663d0 commit a22e4d6
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 43 deletions.
2 changes: 1 addition & 1 deletion plugins/module_utils/acme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
OpenSSLCLIBackend,
)

from ansible_collections.community.crypto.plugins.module_utils.acme.compatibility import (
from ansible_collections.community.crypto.plugins.module_utils.acme._compatibility import (
handle_standard_module_arguments,
set_crypto_backend,
HAS_CURRENT_CRYPTOGRAPHY,
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/acme/acme.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
CRYPTOGRAPHY_VERSION,
)

from ansible_collections.community.crypto.plugins.module_utils.acme.compatibility import (
from ansible_collections.community.crypto.plugins.module_utils.acme._compatibility import (
get_compatibility_backend,
handle_standard_module_arguments,
)
Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/acme_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@

from ansible.module_utils.basic import AnsibleModule

from ansible_collections.community.crypto.plugins.module_utils.acme import (
from ansible_collections.community.crypto.plugins.module_utils.acme.acme import (
ACMEAccount,
handle_standard_module_arguments,
get_default_argspec,
create_backend,
)

from ansible_collections.community.crypto.plugins.module_utils.acme.errors import ModuleFailException
Expand Down Expand Up @@ -198,7 +198,7 @@ def main():
),
supports_check_mode=True,
)
handle_standard_module_arguments(module, needs_acme_v2=True)
backend = create_backend(module, True)

if module.params['external_account_binding']:
# Make sure padding is there
Expand All @@ -213,7 +213,7 @@ def main():
module.params['external_account_binding']['key'] = key

try:
account = ACMEAccount(module)
account = ACMEAccount(module, backend)
changed = False
state = module.params.get('state')
diff_before = {}
Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/acme_account_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@

from ansible.module_utils.basic import AnsibleModule

from ansible_collections.community.crypto.plugins.module_utils.acme import (
from ansible_collections.community.crypto.plugins.module_utils.acme.acme import (
ACMEAccount,
handle_standard_module_arguments,
get_default_argspec,
create_backend,
)

from ansible_collections.community.crypto.plugins.module_utils.acme.errors import ModuleFailException
Expand Down Expand Up @@ -281,10 +281,10 @@ def main():
if module._name in ('acme_account_facts', 'community.crypto.acme_account_facts'):
module.deprecate("The 'acme_account_facts' module has been renamed to 'acme_account_info'",
version='2.0.0', collection_name='community.crypto')
handle_standard_module_arguments(module, needs_acme_v2=True)
backend = create_backend(module, True)

try:
account = ACMEAccount(module)
account = ACMEAccount(module, backend)
# Check whether account exists
created, account_data = account.setup_account(
[],
Expand Down
35 changes: 10 additions & 25 deletions plugins/modules/acme_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,14 +534,14 @@
split_pem_list,
)

from ansible_collections.community.crypto.plugins.module_utils.acme import (
from ansible_collections.community.crypto.plugins.module_utils.acme.acme import (
ACMEAccount,
cryptography_get_cert_days,
handle_standard_module_arguments,
get_default_argspec,
get_backend,
create_backend,
)

from ansible_collections.community.crypto.plugins.module_utils.acme.backend_cryptography import CryptographyBackend

from ansible_collections.community.crypto.plugins.module_utils.acme.errors import ModuleFailException

from ansible_collections.community.crypto.plugins.module_utils.acme.io import (
Expand All @@ -561,19 +561,7 @@
import cryptography.hazmat.backends
import cryptography.x509
except ImportError:
CRYPTOGRAPHY_IMP_ERR = traceback.format_exc()
CRYPTOGRAPHY_FOUND = False
else:
CRYPTOGRAPHY_FOUND = True


def get_cert_days(module, cert_file):
'''
Return the days the certificate in cert_file remains valid and -1
if the file was not found. If cert_file contains more than one
certificate, only the first one will be considered.
'''
get_backend(module).get_cert_days(cert_file)
pass


class ACMEClient(object):
Expand Down Expand Up @@ -1212,18 +1200,15 @@ def main():
),
supports_check_mode=True,
)
backend = handle_standard_module_arguments(module)
if module.params['select_chain']:
if backend != 'cryptography':
module.fail_json(msg="The 'select_chain' can only be used with the 'cryptography' backend.")
elif not CRYPTOGRAPHY_FOUND:
module.fail_json(msg=missing_required_lib('cryptography'))
backend = create_backend(module, False)
if module.params['select_chain'] and not isinstance(backend, CryptographyBackend):
module.fail_json(msg="The 'select_chain' can only be used with the 'cryptography' backend.")

try:
if module.params.get('dest'):
cert_days = get_cert_days(module, module.params['dest'])
cert_days = backend.get_cert_days(module.params['dest'])
else:
cert_days = get_cert_days(module, module.params['fullchain_dest'])
cert_days = backend.get_cert_days(module.params['fullchain_dest'])

if module.params['force'] or cert_days < module.params['remaining_days']:
# If checkmode is active, base the changed state solely on the status
Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/acme_certificate_revoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@

from ansible.module_utils.basic import AnsibleModule

from ansible_collections.community.crypto.plugins.module_utils.acme import (
from ansible_collections.community.crypto.plugins.module_utils.acme.acme import (
ACMEAccount,
handle_standard_module_arguments,
get_default_argspec,
create_backend,
)

from ansible_collections.community.crypto.plugins.module_utils.acme.errors import ModuleFailException
Expand Down Expand Up @@ -151,10 +151,10 @@ def main():
),
supports_check_mode=False,
)
handle_standard_module_arguments(module)
backend = create_backend(module, False)

try:
account = ACMEAccount(module)
account = ACMEAccount(module, backend)
# Load certificate
certificate = pem_to_der(module.params.get('certificate'))
certificate = nopad_b64(certificate)
Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/acme_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native, to_bytes, to_text

from ansible_collections.community.crypto.plugins.module_utils.acme import (
from ansible_collections.community.crypto.plugins.module_utils.acme.acme import (
ACMEAccount,
handle_standard_module_arguments,
get_default_argspec,
create_backend,
)

from ansible_collections.community.crypto.plugins.module_utils.acme.errors import ModuleFailException
Expand All @@ -274,13 +274,13 @@ def main():
['method', 'post', ['account_key_src', 'account_key_content'], True],
),
)
handle_standard_module_arguments(module)
backend = create_backend(module, False)

result = dict()
changed = False
try:
# Get hold of ACMEAccount object (includes directory)
account = ACMEAccount(module)
account = ACMEAccount(module, backend)
method = module.params['method']
result['directory'] = account.directory.directory
# Do we have to do more requests?
Expand Down

0 comments on commit a22e4d6

Please sign in to comment.