diff --git a/files/cert2json.py b/files/cert2json.py index c90e2c6686df931b40fe4de7071f0f087a680956..8ecf364241d33d2193858b06bc7123ce2570f75b 100755 --- a/files/cert2json.py +++ b/files/cert2json.py @@ -46,44 +46,49 @@ if __name__ == "__main__": decoded_output = cbot_out.decode("utf-8").split("\n") provider_dir = os.path.join(BASE_DIR, acme_provider) - yaml_file = "{}/{}.yaml".format(provider_dir, acme_provider) - json_file = "{}/{}.json".format(provider_dir, acme_provider) - json_expired = "{}/{}_expired.json".format(provider_dir, acme_provider) + YAML_FILE = "{}/{}.yaml".format(provider_dir, acme_provider) + JSON_FILE = "{}/{}.json".format(provider_dir, acme_provider) + JSON_EXPIRED = "{}/{}_expired.json".format(provider_dir, acme_provider) os.chmod(provider_dir, 0o755) # open yaml for writing - with open(yaml_file, "w") as yaml_out: + with open(YAML_FILE, "w") as yaml_out: yaml_out.write("---\n") for txt_line in decoded_output: if "Certificate Name:" in txt_line: - txt_line_out = re.sub('.*Certificate Name: ', '- certname: ', txt_line) + TXT_LINE_OUT = re.sub( + '.*Certificate Name: ', '- certname: ', txt_line) elif "Serial Number: " in txt_line: - txt_line_out = re.sub('.*Serial Number: ', ' serial_number: ', txt_line) + TXT_LINE_OUT = re.sub( + '.*Serial Number: ', ' serial_number: ', txt_line) elif "Domains: " in txt_line: domains = re.sub('.*Domains: ', '', txt_line).split(" ") domains_modified = ['"' + i + '"' for i in domains] - domains_joined = '\n - '.join(domains_modified) - txt_line_out = " domains:\n - " + domains_joined + DOMAINS_JOINED = '\n - '.join(domains_modified) + TXT_LINE_OUT = " domains:\n - " + DOMAINS_JOINED elif "Expiry Date: " in txt_line: - txt_line_out = re.sub('.*Expiry Date: .*\(', ' expiry_date: "', txt_line) #pylint: disable=W1401 - txt_line_out = txt_line_out.replace(')', '') + '"' + TXT_LINE_OUT = re.sub( + '.*Expiry Date: .*\(', ' expiry_date: "', txt_line) # pylint: disable=W1401 + TXT_LINE_OUT = TXT_LINE_OUT.replace(')', '') + '"' else: - txt_line_out = None + TXT_LINE_OUT = None - if txt_line_out: - yaml_out.write("{}\n".format(txt_line_out)) + if TXT_LINE_OUT: + yaml_out.write("{}\n".format(TXT_LINE_OUT)) yaml_out.close() # open yaml for reading and json(s) for writing - with open(yaml_file, 'r') as yaml_in, \ - open(json_file, "w") as json_out, \ - open(json_expired, "w") as json_exp_out: + with open(YAML_FILE, 'r') as yaml_in, \ + open(JSON_FILE, "w") as json_out, \ + open(JSON_EXPIRED, "w") as json_exp_out: yaml_object = yaml.safe_load(yaml_in) json_dumped = json.dumps(yaml_object, indent=4) # sorting list of dictionaries by value: https://stackoverflow.com/a/73050/3151187 - sorted_certname = sorted(ast.literal_eval(json_dumped), key=lambda k: k['certname']) - sorted_expired = sorted(ast.literal_eval(json_dumped), key=lambda k: k['expiry_date']) + sorted_certname = sorted(ast.literal_eval( + json_dumped), key=lambda k: k['certname']) + sorted_expired = sorted(ast.literal_eval( + json_dumped), key=lambda k: k['expiry_date']) sorted_certname_json = json.dumps(sorted_certname, indent=4) sorted_expired_json = json.dumps(sorted_expired, indent=4) json_out.write(sorted_certname_json) @@ -96,7 +101,7 @@ if __name__ == "__main__": timestamp_file.close() json_out.close() json_exp_out.close() - # os.unlink(yaml_file) + # os.unlink(YAML_FILE) # fix permissions os.chmod(BASE_DIR, 0o755) diff --git a/manifests/nginx.pp b/manifests/nginx.pp index b0d74267a17c430777acf8613615a421b877aed1..a02d9a2092bcb7b64335a7412d88cf6df06e6905 100644 --- a/manifests/nginx.pp +++ b/manifests/nginx.pp @@ -51,7 +51,7 @@ class geant_acme::nginx ( ensure => present, user => 'root', command => '/usr/bin/flock /tmp/cert2json.lock /root/bin/cert2json.py -p all', - minute => '*/5'; + minute => '*/3'; } }