def vomsInfoAvailable( self ): """ Is voms info available? """ if not Os.which("voms-proxy-info"): return S_ERROR("Missing voms-proxy-info") cmd = 'voms-proxy-info -h' result = shellCall( self._secCmdTimeout, cmd ) if not result['OK']: return False status, _output, _error = result['Value'] if status: return False return True
def vomsInfoAvailable(self): """ Is voms info available? """ if not Os.which("voms-proxy-info"): return S_ERROR(DErrno.EVOMS, "Missing voms-proxy-info") cmd = 'voms-proxy-info -h' result = shellCall(self._secCmdTimeout, cmd) if not result['OK']: return False status, _output, _error = result['Value'] if status: return False return True
def vomsInfoAvailable(self): """ Is voms info available? """ vpInfoCmd = '' for vpInfo in ('voms-proxy-info', 'voms-proxy-info2'): if Os.which(vpInfo): vpInfoCmd = vpInfo if not vpInfoCmd: return S_ERROR(DErrno.EVOMS, "Missing voms-proxy-info") cmd = '%s -h' % vpInfoCmd result = shellCall(self._secCmdTimeout, cmd) if not result['OK']: return False status, _output, _error = result['Value'] if status: return False return True
def vomsInfoAvailable(self): """ Is voms info available? """ vpInfoCmd = "" for vpInfo in ("voms-proxy-info", "voms-proxy-info2"): if Os.which(vpInfo): vpInfoCmd = vpInfo if not vpInfoCmd: return S_ERROR(DErrno.EVOMS, "Missing voms-proxy-info") cmd = "%s -h" % vpInfoCmd result = shellCall(self._secCmdTimeout, cmd) if not result["OK"]: return False status, _output, _error = result["Value"] if status: return False return True
def vomsInfoAvailable(self): """ Is voms info available? """ vpInfoCmd = '' for vpInfo in ('voms-proxy-info', 'voms-proxy-info2'): if Os.which(vpInfo): vpInfoCmd = vpInfo if not vpInfoCmd: return S_ERROR(DErrno.EVOMS, "Missing voms-proxy-info") cmd = '%s -h' % vpInfoCmd result = shellCall(self._secCmdTimeout, cmd) if not result['OK']: return False status, _output, _error = result['Value'] if status: return False return True
def setVOMSAttributes(self, proxy, attribute=None, vo=None): """ Sets voms attributes to a proxy """ if not vo: return S_ERROR(DErrno.EVOMS, "No vo specified, and can't get default in the configuration") retVal = multiProxyArgument(proxy) if not retVal['OK']: return retVal proxyDict = retVal['Value'] chain = proxyDict['chain'] proxyLocation = proxyDict['file'] secs = chain.getRemainingSecs()['Value'] - 300 if secs < 0: return S_ERROR(DErrno.EVOMS, "Proxy length is less that 300 secs") hours = int(secs / 3600) mins = int((secs - hours * 3600) / 60) retVal = self._generateTemporalFile() if not retVal['OK']: deleteMultiProxy(proxyDict) return retVal newProxyLocation = retVal['Value'] cmdArgs = [] if chain.isLimitedProxy()['Value']: cmdArgs.append('-limited') cmdArgs.append('-cert "%s"' % proxyLocation) cmdArgs.append('-key "%s"' % proxyLocation) cmdArgs.append('-out "%s"' % newProxyLocation) if attribute and attribute != 'NoRole': cmdArgs.append('-voms "%s:%s"' % (vo, attribute)) else: cmdArgs.append('-voms "%s"' % vo) cmdArgs.append('-valid "%s:%s"' % (hours, mins)) tmpDir = False vomsesPath = self.getVOMSESLocation() if vomsesPath: cmdArgs.append('-vomses "%s"' % vomsesPath) if chain.isRFC().get('Value'): cmdArgs.append("-r") cmdArgs.append('-timeout %u' % self._servTimeout) vpInitCmd = '' for vpInit in ('voms-proxy-init', 'voms-proxy-init2'): if Os.which(vpInit): vpInitCmd = vpInit if not vpInitCmd: return S_ERROR(DErrno.EVOMS, "Missing voms-proxy-init") cmd = '%s %s' % (vpInitCmd, " ".join(cmdArgs)) result = shellCall(self._secCmdTimeout, cmd) if tmpDir: shutil.rmtree(tmpDir) deleteMultiProxy(proxyDict) if not result['OK']: self._unlinkFiles(newProxyLocation) return S_ERROR(DErrno.EVOMS, 'Failed to call voms-proxy-init: %s' % result['Message']) status, output, error = result['Value'] if status: self._unlinkFiles(newProxyLocation) return S_ERROR( DErrno.EVOMS, 'Failed to set VOMS attributes. Command: %s; StdOut: %s; StdErr: %s' % (cmd, output, error)) newChain = X509Chain() retVal = newChain.loadProxyFromFile(newProxyLocation) self._unlinkFiles(newProxyLocation) if not retVal['OK']: return S_ERROR(DErrno.EVOMS, "Can't load new proxy: %s" % retVal['Message']) return S_OK(newChain)
def getVOMSProxyInfo( self, proxy, option = False ): """ Returns information about a proxy certificate (both grid and voms). Available information is: 1. Full (grid)voms-proxy-info output 2. Proxy Certificate Timeleft in seconds (the output is an int) 3. DN 4. voms group (if any) @type proxy: a string @param proxy: the proxy certificate location. @type option: a string @param option: None is the default value. Other option available are: - timeleft - actimeleft - identity - fqan - all @rtype: tuple @return: status, output, error, pyerror. """ validOptions = ['actimeleft', 'timeleft', 'identity', 'fqan', 'all'] if option: if option not in validOptions: S_ERROR( 'Non valid option %s' % option ) retVal = File.multiProxyArgument( proxy ) if not retVal[ 'OK' ]: return retVal proxyDict = retVal[ 'Value' ] # chain = proxyDict[ 'chain' ] proxyLocation = proxyDict[ 'file' ] if not Os.which("voms-proxy-info"): return S_ERROR("Missing voms-proxy-info") cmd = 'voms-proxy-info -file %s' % proxyLocation if option: cmd += ' -%s' % option result = shellCall( self._secCmdTimeout, cmd ) if proxyDict[ 'tempFile' ]: self._unlinkFiles( proxyLocation ) if not result['OK']: return S_ERROR( 'Failed to call voms-proxy-info' ) status, output, error = result['Value'] # FIXME: if the local copy of the voms server certificate is not up to date the command returns 0. # the stdout needs to be parsed. if status: gLogger.warn( 'Failed to execute:', cmd ) gLogger.warn( 'Exit code:', status ) gLogger.warn( 'StdOut' , output ) gLogger.warn( 'StdErr' , error ) if error.find( 'VOMS extension not found' ) == -1 and \ not error.find( 'WARNING: Unable to verify signature! Server certificate possibly not installed.' ) == 0: return S_ERROR( 'Failed to get proxy info. Command: %s; StdOut: %s; StdErr: %s' % ( cmd, output, error ) ) if option == 'fqan': if output: output = output.split( '/Role' )[0] else: output = '/lhcb' return S_OK( output )
def getVOMSProxyInfo(self, proxy, option=False): """ Returns information about a proxy certificate (both grid and voms). Available information is: 1. Full (grid)voms-proxy-info output 2. Proxy Certificate Timeleft in seconds (the output is an int) 3. DN 4. voms group (if any) @type proxy: a string @param proxy: the proxy certificate location. @type option: a string @param option: None is the default value. Other option available are: - timeleft - actimeleft - identity - fqan - all @rtype: tuple @return: status, output, error, pyerror. """ validOptions = ['actimeleft', 'timeleft', 'identity', 'fqan', 'all'] if option: if option not in validOptions: S_ERROR('Non valid option %s' % option) retVal = File.multiProxyArgument(proxy) if not retVal['OK']: return retVal proxyDict = retVal['Value'] # chain = proxyDict[ 'chain' ] proxyLocation = proxyDict['file'] if not Os.which("voms-proxy-info"): return S_ERROR("Missing voms-proxy-info") cmd = 'voms-proxy-info -file %s' % proxyLocation if option: cmd += ' -%s' % option result = shellCall(self._secCmdTimeout, cmd) if proxyDict['tempFile']: self._unlinkFiles(proxyLocation) if not result['OK']: return S_ERROR('Failed to call voms-proxy-info') status, output, error = result['Value'] # FIXME: if the local copy of the voms server certificate is not up to date the command returns 0. # the stdout needs to be parsed. if status: gLogger.warn('Failed to execute:', cmd) gLogger.warn('Exit code:', status) gLogger.warn('StdOut', output) gLogger.warn('StdErr', error) if error.find( 'VOMS extension not found' ) == -1 and \ not error.find( 'WARNING: Unable to verify signature! Server certificate possibly not installed.' ) == 0: return S_ERROR( 'Failed to get proxy info. Command: %s; StdOut: %s; StdErr: %s' % (cmd, output, error)) if option == 'fqan': if output: output = output.split('/Role')[0] else: output = '/lhcb' return S_OK(output)