Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal for fixing failed fetch of crt situations #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions sucm/sucm_automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,25 @@
from .sucm_notifygroup import SucmNotifyGroup
from .sucm_settings import app_logger

def retry_failed_fetch():
certs_that_failed = SucmCertificate().get_fetch_failures()
if certs_that_failed:
for cert in certs_that_failed:
try:
cert_obj = SucmCertificate(cert_id=cert["cert_id"])
cert_obj.set_current_class_values_from_db()
cert_obj.renew_cert_with_csr()
app_logger.info(
"%s has been renewed after previous fetch failure and is now pushed to vault.",
cert["common_name"],
)
del cert_obj
except:
return

def job_function():
app_logger.info("Job started!")
retry_failed_fetch()
certs_to_renew = SucmCertificate().get_renewable_certs()
certs_to_remove = SucmCertificate().get_expired_certs()
if certs_to_renew:
Expand Down
21 changes: 18 additions & 3 deletions sucm/sucm_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@ def get_expired_certs(self):
data_list.append(details)
return data_list

def get_fetch_failures(self):
all_data = sucm_db.get_records(
"Certificate", "Status = 'Failed to fetch CRT'"
)
data_list = []
for data in all_data:
details = self._create_cert_dict(data)
data_list.append(details)
return data_list

def get_next_cert_id(self):
return sucm_db.get_next_available_id("Certificate")

Expand Down Expand Up @@ -417,11 +427,16 @@ def _split_pem_chain(pem_chain):
return pem_certificates

def renew_cert_with_csr(self):
if self.status == "New CSR":
if self.status == "New CSR" of self.status == "Failed to fetch CRT":
self._fetch_csr()

self._load_certificate_authority()
cert_data = self.cert_authority.fetch_cert(self.csr)
try:
self._load_certificate_authority()
cert_data = self.cert_authority.fetch_cert(self.csr)
except:
self.status = "Failed to fetch CRT"
self.commit_changes_to_db()
return

self.crt = cert_data[0]
self.expiry_date = cert_data[1]
Expand Down