Skip to content

Commit

Permalink
Run pre-commit on x509 state
Browse files Browse the repository at this point in the history
  • Loading branch information
alxwr authored and dwoz committed Sep 9, 2020
1 parent 954a000 commit 54bed4e
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions salt/states/x509.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Manage X509 Certificates
Expand Down Expand Up @@ -170,7 +169,6 @@
- backup: True
"""
from __future__ import absolute_import, print_function, unicode_literals

import copy
import datetime
Expand Down Expand Up @@ -372,7 +370,7 @@ def csr_managed(name, **kwargs):
try:
old = __salt__["x509.read_csr"](name)
except salt.exceptions.SaltInvocationError:
old = "{0} is not a valid csr.".format(name)
old = "{} is not a valid csr.".format(name)

file_args, kwargs = _get_file_args(name, **kwargs)
file_args["contents"] = __salt__["x509.create_csr"](text=True, **kwargs)
Expand Down Expand Up @@ -495,7 +493,7 @@ def _certificate_is_valid(name, days_remaining, append_certs, **cert_spec):
If False, also provide a message explaining why.
"""
if not os.path.isfile(name):
return False, "{0} does not exist".format(name), {}
return False, "{} does not exist".format(name), {}

try:
cert_info = __salt__["x509.read_certificate"](certificate=name)
Expand All @@ -504,7 +502,7 @@ def _certificate_is_valid(name, days_remaining, append_certs, **cert_spec):
)
if not isinstance(required_cert_info, dict):
raise salt.exceptions.SaltInvocationError(
"Unable to create new certificate: x509 module error: {0}".format(
"Unable to create new certificate: x509 module error: {}".format(
required_cert_info
)
)
Expand Down Expand Up @@ -532,23 +530,23 @@ def _certificate_is_valid(name, days_remaining, append_certs, **cert_spec):
if not matches:
return (
False,
"Certificate properties are different: {0}".format(", ".join(diff)),
"Certificate properties are different: {}".format(", ".join(diff)),
cert_info,
)

actual_days_remaining = _certificate_days_remaining(cert_info)
if days_remaining != 0 and actual_days_remaining < days_remaining:
return (
False,
"Certificate needs renewal: {0} days remaining but it needs to be at least {1}".format(
"Certificate needs renewal: {} days remaining but it needs to be at least {}".format(
actual_days_remaining, days_remaining
),
cert_info,
)

return True, "", cert_info
except salt.exceptions.SaltInvocationError as e:
return False, "{0} is not a valid certificate: {1}".format(name, str(e)), {}
return False, "{} is not a valid certificate: {}".format(name, str(e)), {}


def _certificate_file_managed(ret, file_args):
Expand All @@ -560,7 +558,7 @@ def _certificate_file_managed(ret, file_args):

ret["result"] = file_ret["result"]
if ret["result"]:
ret["comment"] = "Certificate {0} is valid and up to date".format(ret["name"])
ret["comment"] = "Certificate {} is valid and up to date".format(ret["name"])
else:
ret["comment"] = file_ret["comment"]

Expand Down Expand Up @@ -690,7 +688,7 @@ def certificate_managed(
ret = _certificate_file_managed(ret, file_args)

ret["result"] = None
ret["comment"] = "Certificate {0} will be created".format(name)
ret["comment"] = "Certificate {} will be created".format(name)
ret["changes"]["Status"] = {
"Old": invalid_reason,
"New": "Certificate will be valid and up to date",
Expand All @@ -705,7 +703,7 @@ def certificate_managed(
ret["result"] = False
ret[
"comment"
] = "An error occurred creating the certificate {0}. The result returned from x509.create_certificate is not a valid PEM file:\n{1}".format(
] = "An error occurred creating the certificate {}. The result returned from x509.create_certificate is not a valid PEM file:\n{}".format(
name, str(e)
)
return ret
Expand All @@ -722,7 +720,7 @@ def certificate_managed(
ret["result"] = False
ret[
"comment"
] = "{0} is not a valid certificate file, cannot append it to the certificate {1}.\nThe error returned by the x509 module was:\n{2}".format(
] = "{} is not a valid certificate file, cannot append it to the certificate {}.\nThe error returned by the x509 module was:\n{}".format(
append_file, name, str(e)
)
return ret
Expand Down Expand Up @@ -837,9 +835,9 @@ def crl_managed(
if days_remaining == 0:
days_remaining = current_days_remaining - 1
except salt.exceptions.SaltInvocationError:
current = "{0} is not a valid CRL.".format(name)
current = "{} is not a valid CRL.".format(name)
else:
current = "{0} does not exist.".format(name)
current = "{} does not exist.".format(name)

new_crl = __salt__["x509.create_crl"](
text=True,
Expand Down

0 comments on commit 54bed4e

Please sign in to comment.