mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-05-07 05:43:06 +00:00
Add filter module base, prepare adding filters (#553)
* Improve string handling. * Cleanup tests. * Add filter module mock.
This commit is contained in:
@@ -14,7 +14,7 @@ import re
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
from ansible.module_utils.common.text.converters import to_text, to_bytes
|
||||
from ansible.module_utils.common.text.converters import to_text, to_bytes, to_native
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlparse, urlunparse, ParseResult
|
||||
|
||||
from ._asn1 import serialize_asn1_string_as_der
|
||||
@@ -138,7 +138,7 @@ def cryptography_get_extensions_from_cert(cert):
|
||||
der = backend._ffi.buffer(data.data, data.length)[:]
|
||||
entry = dict(
|
||||
critical=(crit == 1),
|
||||
value=base64.b64encode(der),
|
||||
value=to_native(base64.b64encode(der)),
|
||||
)
|
||||
try:
|
||||
oid = obj2txt(backend._lib, backend._ffi, backend._lib.X509_EXTENSION_get_object(ext))
|
||||
@@ -155,7 +155,7 @@ def cryptography_get_extensions_from_cert(cert):
|
||||
for ext in cert.extensions:
|
||||
result[ext.oid.dotted_string] = dict(
|
||||
critical=ext.critical,
|
||||
value=base64.b64encode(ext.value.public_bytes()),
|
||||
value=to_native(base64.b64encode(ext.value.public_bytes())),
|
||||
)
|
||||
|
||||
return result
|
||||
@@ -198,7 +198,7 @@ def cryptography_get_extensions_from_csr(csr):
|
||||
der = backend._ffi.buffer(data.data, data.length)[:]
|
||||
entry = dict(
|
||||
critical=(crit == 1),
|
||||
value=base64.b64encode(der),
|
||||
value=to_native(base64.b64encode(der)),
|
||||
)
|
||||
try:
|
||||
oid = obj2txt(backend._lib, backend._ffi, backend._lib.X509_EXTENSION_get_object(ext))
|
||||
@@ -215,7 +215,7 @@ def cryptography_get_extensions_from_csr(csr):
|
||||
for ext in csr.extensions:
|
||||
result[ext.oid.dotted_string] = dict(
|
||||
critical=ext.critical,
|
||||
value=base64.b64encode(ext.value.public_bytes()),
|
||||
value=to_native(base64.b64encode(ext.value.public_bytes())),
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
@@ -171,7 +171,7 @@ class CertificateInfoRetrieval(object):
|
||||
result['not_after'] = not_after.strftime(TIMESTAMP_FORMAT)
|
||||
result['expired'] = not_after < datetime.datetime.utcnow()
|
||||
|
||||
result['public_key'] = self._get_public_key_pem()
|
||||
result['public_key'] = to_native(self._get_public_key_pem())
|
||||
|
||||
public_key_info = get_publickey_info(
|
||||
self.module,
|
||||
|
||||
@@ -133,7 +133,7 @@ class CSRInfoRetrieval(object):
|
||||
result['name_constraints_critical'],
|
||||
) = self._get_name_constraints()
|
||||
|
||||
result['public_key'] = self._get_public_key_pem()
|
||||
result['public_key'] = to_native(self._get_public_key_pem())
|
||||
|
||||
public_key_info = get_publickey_info(
|
||||
self.module,
|
||||
|
||||
@@ -214,7 +214,7 @@ class PrivateKeyInfoRetrieval(object):
|
||||
except OpenSSLObjectError as exc:
|
||||
raise PrivateKeyParseError(to_native(exc), result)
|
||||
|
||||
result['public_key'] = self._get_public_key(binary=False)
|
||||
result['public_key'] = to_native(self._get_public_key(binary=False))
|
||||
pk = self._get_public_key(binary=True)
|
||||
result['public_key_fingerprints'] = get_fingerprint_of_bytes(
|
||||
pk, prefer_one=prefer_one_fingerprint) if pk is not None else dict()
|
||||
|
||||
22
plugins/plugin_utils/filter_module.py
Normal file
22
plugins/plugin_utils/filter_module.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2022 Felix Fontein <felix@fontein.de>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# NOTE: THIS IS ONLY FOR FILTER PLUGINS!
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
|
||||
|
||||
class FilterModuleMock(object):
|
||||
def __init__(self, params):
|
||||
self.check_mode = True
|
||||
self.params = params
|
||||
self._diff = False
|
||||
|
||||
def fail_json(self, msg, **kwargs):
|
||||
raise AnsibleFilterError(msg)
|
||||
Reference in New Issue
Block a user