From 1a14bf5890a5bac7da6891b99398a1c7eec7fab0 Mon Sep 17 00:00:00 2001 From: Massimiliano Adamo <maxadamo@gmail.com> Date: Thu, 10 Sep 2020 22:13:35 +0200 Subject: [PATCH] code refactoring --- files/cert2json.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/files/cert2json.py b/files/cert2json.py index b94e01f..e79bce6 100755 --- a/files/cert2json.py +++ b/files/cert2json.py @@ -20,6 +20,7 @@ import yaml from docopt import docopt +BASE_DIR = '/var/www/acme_web' ARGS = docopt(__doc__) PROVIDER = ARGS['--provider'] if PROVIDER not in ["letsencrypt", "sectigo_ov", "sectigo_ev", "all"]: @@ -37,8 +38,8 @@ for acme_provider in PROVIDERS: cbot_out, _ = cbot_child.communicate() devoded_output = cbot_out.decode("utf-8").split("\n") - yaml_file = "/var/www/acme_web/{}.yaml".format(acme_provider) - json_file = "/var/www/acme_web/{}.json".format(acme_provider) + yaml_file = "{}/{}.yaml".format(BASE_DIR, acme_provider) + json_file = "{}/{}.json".format(BASE_DIR, acme_provider) # open yaml for writing with open(yaml_file, "w") as yaml_out: @@ -69,10 +70,13 @@ for acme_provider in PROVIDERS: # fix permissions -os.chmod('/var/www/acme_web', 0o755) -for www_file in glob('/var/www/acme_web/*'): +os.chmod(BASE_DIR, 0o755) +for www_file in glob('{}/*'.format(BASE_DIR)): os.chmod(www_file, 0o644) +# write timestamp TIMENOW = time.strftime('%Y-%m-%d %X %Z') TIMESTAMP_JS = """var mytimestamp = "This report was generated on {}" document.getElementById("factstimestamp").innerHTML = mytimestamp;\n""".format(TIMENOW) +with open('{}/timestamp.js'.format(BASE_DIR), 'w') as timstamp_file: + timstamp_file.write(TIMESTAMP_JS) -- GitLab