Skip to content
Snippets Groups Projects
Unverified Commit 1956f55a authored by Max Adamo's avatar Max Adamo
Browse files

increase crontab

parent 522b99d5
Branches
Tags
No related merge requests found
...@@ -46,44 +46,49 @@ if __name__ == "__main__": ...@@ -46,44 +46,49 @@ if __name__ == "__main__":
decoded_output = cbot_out.decode("utf-8").split("\n") decoded_output = cbot_out.decode("utf-8").split("\n")
provider_dir = os.path.join(BASE_DIR, acme_provider) provider_dir = os.path.join(BASE_DIR, acme_provider)
yaml_file = "{}/{}.yaml".format(provider_dir, acme_provider) YAML_FILE = "{}/{}.yaml".format(provider_dir, acme_provider)
json_file = "{}/{}.json".format(provider_dir, acme_provider) JSON_FILE = "{}/{}.json".format(provider_dir, acme_provider)
json_expired = "{}/{}_expired.json".format(provider_dir, acme_provider) JSON_EXPIRED = "{}/{}_expired.json".format(provider_dir, acme_provider)
os.chmod(provider_dir, 0o755) os.chmod(provider_dir, 0o755)
# open yaml for writing # open yaml for writing
with open(yaml_file, "w") as yaml_out: with open(YAML_FILE, "w") as yaml_out:
yaml_out.write("---\n") yaml_out.write("---\n")
for txt_line in decoded_output: for txt_line in decoded_output:
if "Certificate Name:" in txt_line: 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: 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: elif "Domains: " in txt_line:
domains = re.sub('.*Domains: ', '', txt_line).split(" ") domains = re.sub('.*Domains: ', '', txt_line).split(" ")
domains_modified = ['"' + i + '"' for i in domains] domains_modified = ['"' + i + '"' for i in domains]
domains_joined = '\n - '.join(domains_modified) DOMAINS_JOINED = '\n - '.join(domains_modified)
txt_line_out = " domains:\n - " + domains_joined TXT_LINE_OUT = " domains:\n - " + DOMAINS_JOINED
elif "Expiry Date: " in txt_line: elif "Expiry Date: " in txt_line:
txt_line_out = re.sub('.*Expiry Date: .*\(', ' expiry_date: "', txt_line) #pylint: disable=W1401 TXT_LINE_OUT = re.sub(
txt_line_out = txt_line_out.replace(')', '') + '"' '.*Expiry Date: .*\(', ' expiry_date: "', txt_line) # pylint: disable=W1401
TXT_LINE_OUT = TXT_LINE_OUT.replace(')', '') + '"'
else: else:
txt_line_out = None TXT_LINE_OUT = None
if txt_line_out: if TXT_LINE_OUT:
yaml_out.write("{}\n".format(txt_line_out)) yaml_out.write("{}\n".format(TXT_LINE_OUT))
yaml_out.close() yaml_out.close()
# open yaml for reading and json(s) for writing # open yaml for reading and json(s) for writing
with open(yaml_file, 'r') as yaml_in, \ with open(YAML_FILE, 'r') as yaml_in, \
open(json_file, "w") as json_out, \ open(JSON_FILE, "w") as json_out, \
open(json_expired, "w") as json_exp_out: open(JSON_EXPIRED, "w") as json_exp_out:
yaml_object = yaml.safe_load(yaml_in) yaml_object = yaml.safe_load(yaml_in)
json_dumped = json.dumps(yaml_object, indent=4) json_dumped = json.dumps(yaml_object, indent=4)
# sorting list of dictionaries by value: https://stackoverflow.com/a/73050/3151187 # 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_certname = sorted(ast.literal_eval(
sorted_expired = sorted(ast.literal_eval(json_dumped), key=lambda k: k['expiry_date']) 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_certname_json = json.dumps(sorted_certname, indent=4)
sorted_expired_json = json.dumps(sorted_expired, indent=4) sorted_expired_json = json.dumps(sorted_expired, indent=4)
json_out.write(sorted_certname_json) json_out.write(sorted_certname_json)
...@@ -96,7 +101,7 @@ if __name__ == "__main__": ...@@ -96,7 +101,7 @@ if __name__ == "__main__":
timestamp_file.close() timestamp_file.close()
json_out.close() json_out.close()
json_exp_out.close() json_exp_out.close()
# os.unlink(yaml_file) # os.unlink(YAML_FILE)
# fix permissions # fix permissions
os.chmod(BASE_DIR, 0o755) os.chmod(BASE_DIR, 0o755)
......
...@@ -51,7 +51,7 @@ class geant_acme::nginx ( ...@@ -51,7 +51,7 @@ class geant_acme::nginx (
ensure => present, ensure => present,
user => 'root', user => 'root',
command => '/usr/bin/flock /tmp/cert2json.lock /root/bin/cert2json.py -p all', command => '/usr/bin/flock /tmp/cert2json.lock /root/bin/cert2json.py -p all',
minute => '*/5'; minute => '*/3';
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment