Skip to content

Commit

Permalink
Merge pull request #58 from seocam/fix_centos7_idempotency_issue
Browse files Browse the repository at this point in the history
Fix idempotence issue with python version < 3.5
  • Loading branch information
rjeffman authored Aug 18, 2020
2 parents de9178d + 2a0cc6e commit fedef6e
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions module_utils/certificate/providers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ def load_from_params(cls, module, params):
if info.get("ip"):
info["ip"] = [ipaddress.ip_address(to_text(ip)) for ip in info["ip"] if ip]

if info.get("key_usage"):
info["key_usage"] = set(info["key_usage"])

if info.get("extended_key_usage"):
info["extended_key_usage"] = [
cls._get_extended_key_usage_object_identifier(eku).dotted_string
Expand Down Expand Up @@ -317,7 +320,7 @@ def email(self):
@property
def key_usage(self):
"""Return the Key Usage in the certificate."""
return self.cert_data.get("key_usage") or []
return self.cert_data.get("key_usage") or set()

@property
def extended_key_usage(self):
Expand Down Expand Up @@ -363,18 +366,16 @@ def _get_san_values(self, san_type, san_class=None):
return san_values

def _get_key_usage(self):
if not self._key_usage_ext:
return []

key_usages = []
for attr, key_usage in self.KEY_USAGE_ATTR_MAP.items():
try:
key_usage_enabled = getattr(self._key_usage_ext.value, attr)
except ValueError:
pass
else:
if key_usage_enabled:
key_usages.append(key_usage)
key_usages = set()
if self._key_usage_ext:
for attr, key_usage in self.KEY_USAGE_ATTR_MAP.items():
try:
key_usage_enabled = getattr(self._key_usage_ext.value, attr)
except ValueError:
pass
else:
if key_usage_enabled:
key_usages.add(key_usage)
return key_usages

@classmethod
Expand Down

0 comments on commit fedef6e

Please sign in to comment.