def _get_proxy_info(self, key, parse=identity, cached=True): info = self._parse_proxy(cached) try: return parse(info[key]) except Exception: raise AccessTokenError( "Can't access %r in proxy information:\n%s" % (key, info))
def _parse_proxy(self, cached=True): # Return cached results if requested if cached and self._cache: return self._cache # Call voms-proxy-info and parse results proc = LocalProcess(self._proxy_info_exec, *self._get_proxy_info_arguments()) (exit_code, stdout, stderr) = proc.finish(timeout=10) if (exit_code != 0) and not self._ignore_warning: msg = ('%s output:\n%s\n%s\n' % (self._proxy_info_exec, stdout, stderr)).replace( '\n\n', '\n') msg += 'If job submission is still possible, you can set [access] ignore warnings = True\n' msg += '%s failed with return code %d' % (self._proxy_info_exec, exit_code) raise AccessTokenError(msg) self._cache = DictFormat(':').parse(stdout) if not self._cache: msg = 'Unable to parse access token information:\n\t%s\n\t%s\n' raise AccessTokenError(msg % (stdout.strip(), stderr.strip())) return self._cache
def _parse_tickets(self, cached=True): # Return cached results if requested if cached and self._cache: return self._cache # Call klist and parse results proc = LocalProcess(self._klist_exec) self._cache = {} try: for line in proc.stdout.iter(timeout=10): if line.count('@') and (line.count(':') > 1): issued_expires, principal = rsplit(line, ' ', 1) issued_expires = issued_expires.replace('/', ' ').split() assert len(issued_expires) % 2 == 0 issued_str = str.join( ' ', issued_expires[:int(len(issued_expires) / 2)]) expires_str = str.join( ' ', issued_expires[int(len(issued_expires) / 2):]) if expires_str.count(' ') == 3: if len(expires_str.split()[2]) == 2: expires = _parse_date(expires_str, '%m %d %y %H:%M:%S') elif len(expires_str.split()[2]) == 4: expires = _parse_date(expires_str, '%m %d %Y %H:%M:%S') # here else: # On NAF, we get an entirely different format now: Sep 2 12:31:34 2021 expires = _parse_date(expires_str, '%b %d %H:%M:%S %Y') elif expires_str.count( ' ') == 2: # year information is missing cur_year = int(time.strftime('%Y')) expires = _parse_date(expires_str + ' %d' % cur_year, '%b %d %H:%M:%S %Y') issued = _parse_date(issued_str + ' %d' % cur_year, '%b %d %H:%M:%S %Y') if expires < issued: # wraparound at new year expires = _parse_date( expires_str + ' %d' % (cur_year + 1), '%b %d %H:%M:%S %Y') self._cache.setdefault('tickets', {})[principal] = expires elif line.count(':') == 1: (key, value) = lmap(str.strip, line.split(':', 1)) self._cache[key.lower()] = value except Exception: raise AccessTokenError( 'Unable to parse kerberos ticket information!') proc.status_raise(timeout=0) return self._cache
def _parseProxy(self, cached=True): # Return cached results if requested if cached and self._cache: return self._cache # Call voms-proxy-info and parse results proc = LocalProcess(self._infoExec, *self._getProxyArgs()) (retCode, stdout, stderr) = proc.finish(timeout=10) if (retCode != 0) and not self._ignoreWarning: msg = ('%s output:\n%s\n%s\n' % (self._infoExec, stdout, stderr)).replace('\n\n', '\n') msg += 'If job submission is still possible, you can set [access] ignore warnings = True\n' raise AccessTokenError(msg + '%s failed with return code %d' % (self._infoExec, retCode)) self._cache = DictFormat(':').parse(stdout) return self._cache