Copy certificate from master to slaves
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
759 B

  1. import os
  2. from functools import partial
  3. def mod_time(path):
  4. return os.stat(path).st_mtime
  5. def find_newest_cert(root_dir, hostname):
  6. look_for = {
  7. "{}.key.pem".format(hostname): None,
  8. "{}.chain.pem".format(hostname): None,
  9. }
  10. for root, _, files in os.walk(root_dir):
  11. for file in files:
  12. if file in look_for.keys():
  13. fullpath = os.path.join(root, file)
  14. if look_for[file] is None:
  15. look_for[file] = fullpath
  16. elif mod_time(fullpath) > mod_time(look_for[file]):
  17. look_for[file] = fullpath
  18. return look_for
  19. def ensure_keys(key_dir, hostname):
  20. files = (part.format(hostname) for part in ("{}.key.pem", "{}.chain.pem"))