Proxy
Utilities to execute one or more functions with a given proxy.
executeWithUserProxy()
decorator example usage:
@executeWithUserProxy
def testFcn(x, i, kw='qwerty'):
print "args", x, i
print "kwargs", kw
print os.environ.get('X509_USER_PROXY')
return S_OK()
...
result = testFcn( 1.0, 1, kw = 'asdfghj', proxyUserName = 'atsareg', proxyUserGroup = 'biomed_user' )
executeWithUserProxy()
function wrapper example:
def undecoratedFunction(foo='bar'):
print foo, os.environ.get('X509_USER_PROXY')
return S_OK()
executeWithUserProxy(testFcn)(foo='baz', proxyUserName='atsareg', proxyUserGroup='biomed_user')
UserProxy
context manager example:
with UserProxy(proxyUserName='user', proxyUserGroup='group') as proxyResult:
if proxyResult['OK']:
functionThatNeedsAProxy()
anotherFunction()
- class DIRAC.Core.Utilities.Proxy.UserProxy(proxyUserName=None, proxyUserGroup=None, proxyUserDN=None, proxyWithVOMS=True, proxyFilePath=None, executionLock=False)
Bases:
object
Implement a context manager to execute functions with a user proxy.
- __init__(proxyUserName=None, proxyUserGroup=None, proxyUserDN=None, proxyWithVOMS=True, proxyFilePath=None, executionLock=False)
Construct the context manager for a user proxy.
- Parameters:
proxyUserName (str) – the user name of the proxy to be used
proxyUserGroup (str) – the user group of the proxy to be used
proxyUserDN (str) – the user DN of the proxy to be used
proxyWithVOMS (bool) – optional flag to dress or not the user proxy with VOMS extension ( default True )
proxyFilePath (str) – optional file location for the temporary proxy
executionLock (bool) – flag to execute with a lock for the time of user proxy application ( default False )
- DIRAC.Core.Utilities.Proxy.executeWithUserProxy(fcn)
Decorator function to execute with a temporary user proxy
- Parameters:
fcn – function to be decorated
- Returns:
the result of the fcn execution
In order to be executed with a user proxy, the function must be called with the following parameters:
- Parameters:
proxyUserName (str) – the user name of the proxy to be used
proxyUserGroup (str) – the user group of the proxy to be used
proxyUserDN (str) – the user DN of the proxy to be used
proxyWithVOMS (str) – optional flag to dress or not the user proxy with VOMS extension ( default True )
proxyFilePath (str) – optional file location for the temporary proxy
executionLock (bool) – flag to execute with a lock for the time of user proxy application ( default False )
- DIRAC.Core.Utilities.Proxy.executeWithoutServerCertificate(fcn)
Decorator function to execute a call without the server certificate. This shows useful in Agents when we want to call a DIRAC service and use the shifter proxy (for example Write calls to the DFC).
The method does not fetch any proxy, it assumes it is already set up in the environment. Note that because it modifies the configuration for all thread, it uses a lock (the same as ExecuteWithUserProxy)
- Potential problem:
there is a lock for this particular method, but any other method changing the UseServerCertificate value can clash with this.
- Parameters:
fcn – function to be decorated
- Returns:
the result of the fcn execution
- DIRAC.Core.Utilities.Proxy.getProxy(userDNs, userGroup, vomsAttr, proxyFilePath)
do the actual download of the proxy, trying the different DNs