Esempio n. 1
0
def cryptography_get_cert_days(module, cert_file, now=None):
    module.deprecate(
        'Please adjust your custom module/plugin to the ACME module_utils refactor '
        '(https://github.com/ansible-collections/community.crypto/pull/184). The '
        'compatibility layer will be removed in community.crypto 2.0.0, thus breaking '
        'your code',
        version='2.0.0',
        collection_name='community.crypto')
    return CryptographyBackend(module).get_cert_days(cert_filename=cert_file,
                                                     now=now)
def create_backend(module, needs_acme_v2):
    backend = module.params['select_crypto_backend']

    # Backend autodetect
    if backend == 'auto':
        backend = 'cryptography' if HAS_CURRENT_CRYPTOGRAPHY else 'openssl'

    # Create backend object
    if backend == 'cryptography':
        if not HAS_CURRENT_CRYPTOGRAPHY:
            module.fail_json(msg=missing_required_lib('cryptography'))
        module.debug('Using cryptography backend (library version {0})'.format(
            CRYPTOGRAPHY_VERSION))
        module_backend = CryptographyBackend(module)
    elif backend == 'openssl':
        module.debug('Using OpenSSL binary backend')
        module_backend = OpenSSLCLIBackend(module)
    else:
        module.fail_json(msg='Unknown crypto backend "{0}"!'.format(backend))

    # Check common module parameters
    if not module.params['validate_certs']:
        module.warn(
            'Disabling certificate validation for communications with ACME endpoint. '
            'This should only be done for testing against a local ACME server for '
            'development purposes, but *never* for production purposes.')

    if module.params['acme_version'] is None:
        module.params['acme_version'] = 1
        module.deprecate(
            "The option 'acme_version' will be required from community.crypto 2.0.0 on",
            version='2.0.0',
            collection_name='community.crypto')

    if module.params['acme_directory'] is None:
        module.params[
            'acme_directory'] = 'https://acme-staging.api.letsencrypt.org/directory'
        module.deprecate(
            "The option 'acme_directory' will be required from community.crypto 2.0.0 on",
            version='2.0.0',
            collection_name='community.crypto')

    if needs_acme_v2 and module.params['acme_version'] < 2:
        module.fail_json(msg='The {0} module requires the ACME v2 protocol!'.
                         format(module._name))

    # AnsibleModule() changes the locale, so change it back to C because we rely
    # on datetime.datetime.strptime() when parsing certificate dates.
    locale.setlocale(locale.LC_ALL, 'C')

    return module_backend
Esempio n. 3
0
def get_compatibility_backend(module):
    if HAS_CURRENT_CRYPTOGRAPHY:
        return CryptographyBackend(module)
    else:
        return OpenSSLCLIBackend(module)