diff --git a/copy_local_keys.py b/copy_local_keys.py new file mode 100644 index 0000000..42ebb48 --- /dev/null +++ b/copy_local_keys.py @@ -0,0 +1,21 @@ +import os + + +def mod_time(path): + return os.stat(path).st_mtime + + +def find_newest_cert(root_dir, hostname): + look_for = { + "{}.key.pem".format(hostname): None, + "{}.chain.pem".format(hostname): None, + } + for root, _, files in os.walk(root_dir): + for file in files: + if file in look_for.keys(): + fullpath = os.path.join(root, file) + if look_for[file] is None: + look_for[file] = fullpath + elif mod_time(fullpath) > mod_time(look_for[file]): + look_for[file] = fullpath + return look_for