X-Git-Url: https://pwan.org/git/?p=certmaster.git;a=blobdiff_plain;f=scripts%2Fcertmaster-sync;h=ca7710ed66277dafa12d7cb9631b46e482e51917;hp=bd27af51febdd184eb4930a6c57bdecaefdb1969;hb=8513efd091ed3e2beca32436b94132cf1451b119;hpb=cd7c424c4870bdf1b93c43b9283b25fb803361eb diff --git a/scripts/certmaster-sync b/scripts/certmaster-sync index bd27af5..ca7710e 100644 --- a/scripts/certmaster-sync +++ b/scripts/certmaster-sync @@ -7,14 +7,31 @@ import os import sys -import sha +try: + import hashlib +except ImportError: + # Python-2.4.z ... gah! (or even 2.3!) + import sha + class hashlib: + @staticmethod + def new(algo): + if algo == 'sha1': + return sha.new() + raise ValueError, "Bad checksum type" + + import xmlrpclib from glob import glob from time import sleep from certmaster import certmaster as certmaster -from func.overlord.client import Client -from func.CommonErrors import Func_Client_Exception -import func.jobthing as jobthing + +func_import_failure = None +try: + from func.overlord.client import Client + from func.CommonErrors import Func_Client_Exception + import func.jobthing as jobthing +except ImportError, e: + func_import_failure = str(e) def syncable(cert_list): """ @@ -67,12 +84,13 @@ def local_certs(): results = [] for f in files: hostname = os.path.basename(f).replace('.' + cm.cfg.cert_extension, '') + dirname = os.path.dirname(f) digest = checksum(f) - results.append([hostname, digest]) + results.append([hostname, digest, dirname]) return results def checksum(f): - thissum = sha.new() + thissum = hashlib.new('sha1') if os.path.exists(f): fo = open(f, 'r') data = fo.read() @@ -107,7 +125,7 @@ def copy_updated_certs(local, remote): for cert in local: if cert not in peers: cert_name = '%s.%s' % (cert[0], cm.cfg.cert_extension) - full_path = os.path.join(cm.cfg.certroot, cert_name) + full_path = os.path.join(cert[2], cert_name) fd = open(full_path) certblob = fd.read() fd.close() @@ -124,6 +142,11 @@ def main(): if not cm.cfg.sync_certs and not forced: sys.exit(0) + # Don't complain about func not being available until you actually want it + if func_import_failure != None: + print >> sys.stderr, "errors importing func: %s" % func_import_failure + sys.exit(1) + certs = glob(os.path.join(cm.cfg.certroot, '*.%s' % cm.cfg.cert_extension)) hosts = syncable(certs)