Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-20 07:59:01

0001 import logging
0002 import sys
0003 
0004 from pandaharvester.harvesterconfig import harvester_config
0005 from pandaharvester.harvestercore import core_utils
0006 from pandaharvester.harvestercore.plugin_factory import PluginFactory
0007 
0008 
0009 # Define a helper function - get list
0010 def get_list(data):
0011     if isinstance(data, list):
0012         return data
0013     else:
0014         return [data]
0015 
0016 
0017 pluginFactory = PluginFactory()
0018 
0019 # get the configuration details - from the harvester config file
0020 
0021 # get module and class names
0022 moduleNames = get_list(harvester_config.credmanager.moduleName)
0023 classNames = get_list(harvester_config.credmanager.className)
0024 # file names of original certificates
0025 if hasattr(harvester_config.credmanager, "inCertFile"):
0026     inCertFiles = get_list(harvester_config.credmanager.inCertFile)
0027 else:
0028     inCertFiles = get_list(harvester_config.credmanager.certFile)
0029 # file names of certificates to be generated
0030 if hasattr(harvester_config.credmanager, "outCertFile"):
0031     outCertFiles = get_list(harvester_config.credmanager.outCertFile)
0032 else:
0033     # use the file name of the certificate for panda connection as output name
0034     outCertFiles = get_list(harvester_config.pandacon.cert_file)
0035 # VOMS
0036 vomses = get_list(harvester_config.credmanager.voms)
0037 
0038 # direct and merged plugin configuration in json
0039 if hasattr(harvester_config.credmanager, "pluginConfigs"):
0040     pluginConfigs = harvester_config.credmanager.pluginConfigs
0041 else:
0042     pluginConfigs = []
0043 
0044 # logger
0045 _logger = core_utils.setup_logger("credManagerTest")
0046 
0047 # get plugin(s)
0048 exeCores = []
0049 for moduleName, className, inCertFile, outCertFile, voms in zip(moduleNames, classNames, inCertFiles, outCertFiles, vomses):
0050     if not moduleName:
0051         continue
0052     pluginPar = {}
0053     pluginPar["module"] = moduleName
0054     pluginPar["name"] = className
0055     pluginPar["inCertFile"] = inCertFile
0056     pluginPar["outCertFile"] = outCertFile
0057     pluginPar["voms"] = voms
0058     exeCore = pluginFactory.get_plugin(pluginPar)
0059     exeCores.append(exeCore)
0060 
0061 # from pluginConfigs
0062 for pc in pluginConfigs:
0063     try:
0064         setup_maps = pc["configs"]
0065         for setup_name, setup_map in setup_maps.items():
0066             try:
0067                 plugin_params = {"module": pc["module"], "name": pc["name"], "setup_name": setup_name}
0068                 plugin_params.update(setup_map)
0069                 exe_core = pluginFactory.get_plugin(plugin_params)
0070                 exeCores.append(exe_core)
0071             except Exception:
0072                 _logger.error(f"failed to launch credmanager in pluginConfigs for {plugin_params}")
0073                 core_utils.dump_error_message(_logger)
0074     except Exception:
0075         _logger.error(f"failed to parse pluginConfigs {pc}")
0076         core_utils.dump_error_message(_logger)
0077 
0078 
0079 # setup logger to write to screen also
0080 for loggerName, loggerObj in logging.Logger.manager.loggerDict.items():
0081     if loggerName.startswith("panda.log"):
0082         if len(loggerObj.handlers) == 0:
0083             continue
0084         if loggerName.split(".")[-1] in ["db_proxy"]:
0085             continue
0086         stdoutHandler = logging.StreamHandler(sys.stdout)
0087         stdoutHandler.setFormatter(loggerObj.handlers[0].formatter)
0088         loggerObj.addHandler(stdoutHandler)
0089 
0090 # loop over all plugins
0091 for exeCore in exeCores:
0092     # do nothing
0093     if exeCore is None:
0094         continue
0095     # make logger
0096     mainLog = core_utils.make_logger(_logger, f"{exeCore.__class__.__name__}", method_name="execute")
0097     # list the plugin name
0098     mainLog.debug(f"plugin={exeCore.__class__.__name__}")
0099     # check credential
0100     mainLog.debug("check credential")
0101     isValid = exeCore.check_credential()
0102     if isValid:
0103         mainLog.debug("valid")
0104     elif not isValid:
0105         # renew it if necessary
0106         mainLog.debug("invalid")
0107         mainLog.debug("renew credential")
0108         tmpStat, tmpOut = exeCore.renew_credential()
0109         if not tmpStat:
0110             mainLog.error(f"failed : {tmpOut}")
0111             continue
0112     mainLog.debug("done")