Skip to content

Commit

Permalink
set-certificate: skip if certificate already exists
Browse files Browse the repository at this point in the history
Don't request a certificate if an updated custom one is already present.
  • Loading branch information
Amygos committed Aug 5, 2024
1 parent 262edde commit 6d4b8df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions imageroot/actions/set-certificate/20writeconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ import sys
import os
import uuid
import yaml
from custom_certificate_manager import list_custom_certificates

# Try to parse the stdin as JSON.
# If parsing fails, output everything to stderr
data = json.load(sys.stdin)


#Don't request a certificate if it is already uploaded
for cert in list_custom_certificates():
if cert.get('fqdn') == data['fqdn']:
sys.exit(0)

agent_id = os.getenv("AGENT_ID", "")
if not agent_id:
raise Exception("AGENT_ID not found inside the environemnt")
Expand Down
8 changes: 8 additions & 0 deletions imageroot/actions/set-certificate/21waitsync
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ import sys
import time
import agent
from get_certificate import get_certificate
from custom_certificate_manager import list_custom_certificates

data = json.load(sys.stdin)
retry = 0
certificate = {}

#Don't wait if certificate it is already uploaded
for cert in list_custom_certificates():
if cert.get('fqdn') == data['fqdn']:
certificate['obtained'] = True
json.dump(certificate, fp=sys.stdout)
exit(0)

sync_timeout = data['sync_timeout'] if data.get('sync_timeout') is not None else 120

while get_certificate(data).get('fqdn') != data['fqdn'] and retry <= 10:
Expand Down

0 comments on commit 6d4b8df

Please sign in to comment.