File indexing completed on 2026-04-10 08:39:01
0001 import sys
0002
0003 from pandacommon.pandalogger.LogWrapper import LogWrapper
0004 from pandacommon.pandalogger.PandaLogger import PandaLogger
0005 from pandacommon.pandautils.thread_utils import GenericThread
0006
0007 from pandaserver.config import panda_config
0008 from pandaserver.proxycache import panda_proxy_cache, token_cache
0009 from pandaserver.srvcore import CoreUtils
0010
0011
0012 _logger = PandaLogger().getLogger("activeusers_query")
0013
0014
0015
0016 def main(tbuf=None, **kwargs):
0017
0018 tmpLog = LogWrapper(_logger)
0019 requester_id = GenericThread().get_full_id(__name__, sys.modules[__name__].__file__)
0020
0021 tmpLog.debug("================= start ==================")
0022
0023 if tbuf is None:
0024 tmpLog.debug("Getting new connection")
0025 from pandaserver.taskbuffer.TaskBuffer import taskBuffer
0026
0027 taskBuffer.init(
0028 panda_config.dbhost,
0029 panda_config.dbpasswd,
0030 nDBConnection=1,
0031 useTimeout=True,
0032 requester=requester_id,
0033 )
0034 tmpLog.debug("Getting new connection - done")
0035 else:
0036 tmpLog.debug("Reusing connection")
0037 taskBuffer = tbuf
0038
0039
0040 my_proxy_interface_instance = panda_proxy_cache.MyProxyInterface()
0041
0042
0043 if hasattr(panda_config, "proxy_cache_roles"):
0044 roles = panda_config.proxy_cache_roles.split(",")
0045 else:
0046 roles = ["atlas", "atlas:/atlas/Role=production", "atlas:/atlas/Role=pilot"]
0047
0048
0049 sql = "select distinct DN FROM ATLAS_PANDAMETA.users WHERE GRIDPREF LIKE :patt"
0050 varMap = {}
0051 varMap[":patt"] = "%p%"
0052 tmpLog.debug("Querying users")
0053 tmpStat, tmpRes = taskBuffer.querySQLS(sql, varMap)
0054 tmpLog.debug("Querying done")
0055 for (realDN,) in tmpRes:
0056 if realDN is None:
0057 continue
0058 realDN = CoreUtils.get_bare_dn(realDN, keep_digits=False)
0059 name = CoreUtils.clean_user_id(realDN)
0060
0061 tmpLog.debug(f"check proxy cache for {name}")
0062 for role in roles:
0063 my_proxy_interface_instance.checkProxy(realDN, role=role, name=name)
0064
0065
0066 tmpLog.debug("Token Cache start")
0067 token_cacher = token_cache.TokenCache(task_buffer=taskBuffer)
0068 token_cacher.run()
0069 tmpLog.debug("Token Cache done")
0070
0071
0072 if tbuf is None:
0073 taskBuffer.cleanup(requester=requester_id)
0074 tmpLog.debug("Stopped the new connection")
0075 tmpLog.debug("done")
0076
0077
0078
0079 if __name__ == "__main__":
0080 main()