From 96ad9508849b89a8e6a0451df778ec14af8f3f1b Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Tue, 3 Sep 2019 09:28:46 -0500 Subject: [PATCH] Added function to find .pem files --- copy_local_keys.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 copy_local_keys.py 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