File indexing completed on 2026-04-20 07:58:58
0001 import re
0002 import subprocess
0003
0004 from pandaharvester.harvestercore import core_utils
0005
0006 from .base_cred_manager import BaseCredManager
0007
0008
0009 _logger = core_utils.setup_logger("arcproxy_cred_manager")
0010
0011
0012
0013 class ArcproxyCredManager(BaseCredManager):
0014
0015 def __init__(self, **kwarg):
0016 BaseCredManager.__init__(self, **kwarg)
0017
0018
0019 def check_credential(self):
0020
0021 mainLog = self.make_logger(_logger, method_name="check_credential")
0022
0023 comStr = f"arcproxy -i vomsACvalidityLeft -P {self.outCertFile}"
0024 mainLog.debug(comStr)
0025 try:
0026 p = subprocess.run(comStr.split(), encoding="utf-8", stdout=subprocess.PIPE, stderr=subprocess.PIPE)
0027 stdOut = p.stdout.strip()
0028 stdErr = p.stderr
0029 retCode = p.returncode
0030 except Exception:
0031 core_utils.dump_error_message(mainLog)
0032 return False
0033 mainLog.debug(f"retCode={retCode} stdOut={stdOut} stdErr={stdErr}")
0034 if retCode != 0 or not re.match(r"\d+", stdOut):
0035 mainLog.error(f"Unexpected output from arcproxy: {stdOut}")
0036 return False
0037
0038 return int(stdOut) > 3600 * 72
0039
0040
0041 def renew_credential(self):
0042
0043 mainLog = self.make_logger(_logger, method_name="renew_credential")
0044 comStr = "arcproxy -S {0} -P {1} -c validityPeriod=96h -c vomsACvalidityPeriod=96h -C {2} -K {2}".format(self.voms, self.outCertFile, self.inCertFile)
0045 mainLog.debug(comStr)
0046 try:
0047 p = subprocess.run(comStr.split(), encoding="utf-8", stdout=subprocess.PIPE, stderr=subprocess.PIPE)
0048 stdOut = p.stdout
0049 stdErr = p.stderr
0050 retCode = p.returncode
0051 mainLog.debug(f"retCode={retCode} stdOut={stdOut} stdErr={stdErr}")
0052 except Exception:
0053 stdOut = ""
0054 stdErr = core_utils.dump_error_message(mainLog)
0055 retCode = -1
0056 return retCode == 0, f"{stdOut} {stdErr}"