Skip to content

Commit

Permalink
Merge pull request #64 from fcharlier/get_intermediate_cert_whenever_…
Browse files Browse the repository at this point in the history
…necessary

Get the intermediate certificate whenever needed
  • Loading branch information
Spredzy authored Jan 11, 2021
2 parents 760c4f2 + 6173c49 commit 805a5aa
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lecm/certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,15 @@ def _create_filesystem(self):
utils.enforce_selinux_context(self.path)

def _get_intermediate_certificate(self):
certificate = requests.get(_INTERMEDIATE_CERTIFICATE_URL).text
certificate_name = os.path.basename(_INTERMEDIATE_CERTIFICATE_URL)

LOG.info('[global] Getting intermediate certificate PEM file: %s' %
certificate_name)
if not os.path.exists('%s/pem/%s' % (self.path, certificate_name)):
with open('%s/pem/%s' % (self.path, certificate_name), 'w') as f:
f.write(certificate)
certificate = requests.get(_INTERMEDIATE_CERTIFICATE_URL).text

LOG.info('[global] Getting intermediate certificate PEM file: %s' %
certificate_name)
if not os.path.exists('%s/pem/%s' % (self.path, certificate_name)):
with open('%s/pem/%s' % (self.path, certificate_name), 'w') as f:
f.write(certificate)

def _create_account_key(self):
account_key = crypto.PKey()
Expand Down Expand Up @@ -257,6 +258,7 @@ def _create_certificate(self):

LOG.debug('[%s] Concatenating certificate with intermediate pem: \
%s/pem/%s.pem' % (self.name, self.path, self.name))
self._get_intermediate_certificate()
pem_filename = os.path.basename(_INTERMEDIATE_CERTIFICATE_URL)
filenames = ['%s/certs/%s.crt' % (self.path, self.name),
'%s/pem/%s' % (self.path, pem_filename)]
Expand Down Expand Up @@ -287,10 +289,6 @@ def generate(self):

self._create_filesystem()

certificate_name = os.path.basename(_INTERMEDIATE_CERTIFICATE_URL)
if not os.path.exists('%s/pem/%s' % (self.path, certificate_name)):
self._get_intermediate_certificate()

# Ensure there is no left-over from previous setup
#
try:
Expand Down

0 comments on commit 805a5aa

Please sign in to comment.