当前位置: 首页>>代码示例>>Python>>正文


Python Proxy.delegate方法代码示例

本文整理汇总了Python中WMCore.Credential.Proxy.Proxy.delegate方法的典型用法代码示例。如果您正苦于以下问题:Python Proxy.delegate方法的具体用法?Python Proxy.delegate怎么用?Python Proxy.delegate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WMCore.Credential.Proxy.Proxy的用法示例。


在下文中一共展示了Proxy.delegate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testMyProxyEnvironment

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import delegate [as 别名]
    def testMyProxyEnvironment(self):
        """
        Test the myProxyEnvironment context manager
        In this test a new Proxy and MyProxy are initialized
        """
        myProxy = Proxy(self.dict)

        # Create the proxy
        myProxy.create()
        proxyPath = myProxy.getProxyFilename()
        userDN = myProxy.getSubject()
        self.assertTrue(os.path.exists(proxyPath))

        # Delegate and check the proxy
        myProxy.delegate(credential=proxyPath, serverRenewer=True)
        valid = myProxy.checkMyProxy()
        self.assertTrue(valid)

        # Make sure X509_USER_PROXY exists only in the context manager and corresponds to a file
        if 'X509_USER_PROXY' in os.environ:
            del os.environ['X509_USER_PROXY']
        self.assertFalse('X509_USER_PROXY' in os.environ)
        with myProxyEnvironment(userDN=userDN, serverCert=serverCert, serverKey=serverKey,
                                myproxySrv='myproxy.cern.ch', proxyDir='/tmp/', logger=self.logger):
            self.assertTrue('X509_USER_PROXY' in os.environ)
            self.assertTrue(os.path.exists(os.environ['X509_USER_PROXY']))
        self.assertFalse('X509_USER_PROXY' in os.environ)

        return
开发者ID:AndresTanasijczuk,项目名称:WMCore,代码行数:31,代码来源:MyProxy_t.py

示例2: Proxy

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import delegate [as 别名]
class Proxy(object):
    '''
    CMS uses proxies constantly. This class is a wrapper function around WMCore
    proxy handling, to allow the user to update/check/delete their proxy in
    myproxy and update/check the local proxy
    '''


    def __init__(self):
        '''
        Constructor
        '''
        self.helper = WMCoreProxy({'logger' : logging})

    def getProxyFilename(self):
        return self.helper.getProxyFilename()
            
    def initProxy(self):
        self.helper.create()
        
    def deleteProxy(self):
        self.helper.destroy()
    
    def uploadToMyproxy(self, allowedDN):
        self.helper.serverDN = allowedDN
        self.helper.delegate( None, True )
开发者ID:PerilousApricot,项目名称:CMSYAAT,代码行数:28,代码来源:Proxy.py

示例3: createNewMyProxy

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import delegate [as 别名]
    def createNewMyProxy(self, timeleftthreshold=0, nokey=False):
        """
        Handles the MyProxy creation

        Let the following variables be

        timeleftthreshold: the proxy in myproxy should be delegated for at least this time (14 days)
        myproxytimeleft: current validity of your proxy in myproxy
        usercertDaysLeft: the number of days left before your user certificate expire
        myproxyDesiredValidity: delegate the proxy in myproxy for that time (30 days)

        If we need to renew the proxy in myproxy because its atributes has changed or because it is valid for
        less time than timeleftthreshold then we do it.

        Before doing that, we check when the user certificate is expiring. If it's within the timeleftthreshold (myproxytimeleft < timeleftthreshold)
        we delegate the proxy just for the time we need (checking first if we did not already do it since at some point
        usercertDaysLeft ~= myproxytimeleft and we don't need to delegate it at every command even though myproxytimeleft < timeleftthreshold).

        Note that a warning message is printed at every command it usercertDaysLeft < timeleftthreshold
        """
        myproxy = Proxy ( self.defaultDelegation )
        myproxy.userDN = myproxy.getSubjectFromCert(self.certLocation)

        myproxytimeleft = 0
        self.logger.debug("Getting myproxy life time left for %s" % self.defaultDelegation["myProxySvr"])
        # return an integer that indicates the number of seconds to the expiration of the proxy in myproxy
        myproxytimeleft = myproxy.getMyProxyTimeLeft(serverRenewer=True, nokey=nokey)
        self.logger.debug("Myproxy is valid: %i" % myproxytimeleft)

        trustRetrListChanged = myproxy.trustedRetrievers!=self.defaultDelegation['serverDN'] #list on the REST and on myproxy are different
        if myproxytimeleft < timeleftthreshold or self.proxyChanged or trustRetrListChanged:
            # checking the enddate of the user certificate
            usercertDaysLeft = myproxy.getUserCertEnddate()
            if usercertDaysLeft == 0:
                msg = "%sYOUR USER CERTIFICATE IS EXPIRED (OR WILL EXPIRE TODAY). CANNOT SUBMIT%s"\
                                        % (colors.RED, colors.NORMAL)
                raise ProxyCreationException(msg)

            #if the certificate is going to expire print a warning. This is going to bre printed at every command if
            #the myproxytimeleft is inferior to the timeleftthreshold
            if usercertDaysLeft < self.myproxyDesiredValidity:
                self.logger.info("%sYour user certificate is going to expire in %s days. Please renew it! %s"\
                                 % (colors.RED, usercertDaysLeft, colors.NORMAL) )
                #check if usercertDaysLeft ~= myproxytimeleft which means we already delegated the proxy for as long as we could
                if abs(usercertDaysLeft*60*60*24 - myproxytimeleft) < 60*60*24 and not trustRetrListChanged: #less than one day between usercertDaysLeft and myproxytimeleft
                    return
                #adjust the myproxy delegation time accordingly to the user cert validity
                self.logger.info("%sDelegating your proxy for %s days instead of %s %s"\
                                 % (colors.RED, usercertDaysLeft, self.myproxyDesiredValidity, colors.NORMAL) )
                myproxy.myproxyValidity = "%i:00" % (usercertDaysLeft*24)

            # creating the proxy
            self.logger.debug("Delegating a myproxy for %s hours" % self.defaultDelegation['myproxyValidity'] )
            try:
                myproxy.delegate(serverRenewer = True, nokey=nokey)
                self.logger.debug("My-proxy delegated.")
            except Exception, ex:
                raise ProxyCreationException("Problems delegating My-proxy. %s"%ex._message)
开发者ID:Crabclient,项目名称:CRABClient,代码行数:60,代码来源:CredentialInteractions.py

示例4: createNewMyProxy

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import delegate [as 别名]
    def createNewMyProxy(self, timeleftthreshold=0, nokey=False):
        """
        Handles the MyProxy creation
        """
        myproxy = Proxy ( self.defaultDelegation )
        myproxy.userDN = myproxy.getSubject()

        myproxytimeleft = 0
        self.logger.debug("Getting myproxy life time left for %s" % self.defaultDelegation["myProxySvr"])
        # does it return an integer that indicates?
        myproxytimeleft = myproxy.getMyProxyTimeLeft(serverRenewer=True, nokey=nokey)
        self.logger.debug("Myproxy is valid: %i" % myproxytimeleft)

        if myproxytimeleft < timeleftthreshold or self.proxyChanged:
            # creating the proxy
            self.logger.debug("Delegating a myproxy for %s hours" % self.defaultDelegation['myproxyValidity'] )
            try:
                myproxy.delegate(serverRenewer = True, nokey=nokey)
                self.logger.debug("My-proxy delegated.")
            except Exception, ex:
                raise ProxyCreationException("Problems delegating My-proxy. Problem %s"%ex)
开发者ID:bbockelm,项目名称:CRABClient,代码行数:23,代码来源:CredentialInteractions.py

示例5: createNewMyProxy

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import delegate [as 别名]
    def createNewMyProxy(self, timeleftthreshold=0, nokey=False):
        """
        Handles the MyProxy creation

        Let the following variables be

        timeleftthreshold: the proxy in myproxy should be delegated for at least this time (14 days)
        myproxytimeleft: current validity of your proxy in myproxy
        usercertDaysLeft: the number of days left before your user certificate expire
        myproxyDesiredValidity: delegate the proxy in myproxy for that time (30 days)

        If we need to renew the proxy in myproxy because its atributes has changed or because it is valid for
        less time than timeleftthreshold then we do it.

        Before doing that, we check when the user certificate is expiring. If it's within the timeleftthreshold (myproxytimeleft < timeleftthreshold)
        we delegate the proxy just for the time we need (checking first if we did not already do it since at some point
        usercertDaysLeft ~= myproxytimeleft and we don't need to delegate it at every command even though myproxytimeleft < timeleftthreshold).

        Note that a warning message is printed at every command it usercertDaysLeft < timeleftthreshold
        """
        myproxy = Proxy ( self.defaultDelegation )
        myproxy.userDN = myproxy.getSubjectFromCert(self.certLocation)

        myproxytimeleft = 0
        self.logger.debug("Getting myproxy life time left for %s" % self.defaultDelegation["myProxySvr"])
        # return an integer that indicates the number of seconds to the expiration of the proxy in myproxy
        # Also catch the exception in case WMCore encounters a problem with the proxy itself (one such case was #4532)
        try:
            myproxytimeleft = myproxy.getMyProxyTimeLeft(serverRenewer=True, nokey=nokey)
        except Exception as ex:
            logging.exception("Problems calculating proxy lifetime, logging stack trace and raising ProxyCreationException")
            # WMException may contain the _message attribute. Otherwise, take the exception as a string.
            msg = ex._message if hasattr(ex, "_message") else str(ex)
            raise ProxyCreationException("Problems calculating the time left until the expiration of the proxy."
                    " Please reset your environment or contact [email protected] if the problem persists.\n%s" % msg)
        self.logger.debug("Myproxy is valid: %i" % myproxytimeleft)

        trustRetrListChanged = myproxy.trustedRetrievers!=self.defaultDelegation['serverDN'] #list on the REST and on myproxy are different
        if myproxytimeleft < timeleftthreshold or self.proxyChanged or trustRetrListChanged:
            # checking the enddate of the user certificate
            usercertDaysLeft = myproxy.getUserCertEnddate()
            if usercertDaysLeft == 0:
                msg = "%sYOUR USER CERTIFICATE IS EXPIRED (OR WILL EXPIRE TODAY). YOU CANNOT USE THE CRAB3 CLIENT. PLEASE REQUEST A NEW CERTIFICATE HERE https://gridca.cern.ch/gridca/ AND SEE https://ca.cern.ch/ca/Help/?kbid=024010%s"\
                                        % (colors.RED, colors.NORMAL)
                raise ProxyCreationException(msg)

            #if the certificate is going to expire print a warning. This is going to bre printed at every command if
            #the myproxytimeleft is inferior to the timeleftthreshold
            if usercertDaysLeft < self.myproxyDesiredValidity:
                self.logger.info("%sYour user certificate is going to expire in %s days.  https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookStartingGrid#ObtainingCert %s"\
                                 % (colors.RED, usercertDaysLeft, colors.NORMAL) )
                #check if usercertDaysLeft ~= myproxytimeleft which means we already delegated the proxy for as long as we could
                if abs(usercertDaysLeft*60*60*24 - myproxytimeleft) < 60*60*24 and not trustRetrListChanged: #less than one day between usercertDaysLeft and myproxytimeleft
                    return
                #adjust the myproxy delegation time accordingly to the user cert validity
                self.logger.info("%sDelegating your proxy for %s days instead of %s %s"\
                                 % (colors.RED, usercertDaysLeft, self.myproxyDesiredValidity, colors.NORMAL) )
                myproxy.myproxyValidity = "%i:00" % (usercertDaysLeft*24)

            # creating the proxy
            self.logger.debug("Delegating a myproxy for %s hours" % myproxy.myproxyValidity )
            try:
                myproxy.delegate(serverRenewer = True, nokey=nokey)
                myproxytimeleft = myproxy.getMyProxyTimeLeft(serverRenewer=True, nokey=nokey)
                if myproxytimeleft <= 0:
                    raise ProxyCreationException("It seems your proxy has not been delegated to myproxy. Please check the logfile for the exact error "+\
                                                            "(it might simply you typed a wrong password)")
                else:
                    self.logger.debug("My-proxy delegated.")
            except Exception as ex:
                msg = ex._message if hasattr(ex, '_message') else str(ex)
                raise ProxyCreationException("Problems delegating My-proxy. %s" % msg)
开发者ID:belforte,项目名称:CRABClient,代码行数:74,代码来源:CredentialInteractions.py

示例6: MyProxyTest

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import delegate [as 别名]
class MyProxyTest(unittest.TestCase):

    def setUp(self):
        """
        Setup for unit tests
        """
        logging.basicConfig(level=logging.DEBUG,
                            format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                            datefmt='%m-%d %H:%M',
                            filename='proxy_unittests.log',
                            filemode='w')
        logger_name = 'ProxyTest'
        self.logger = logging.getLogger(logger_name)
        self.dict = {'logger': self.logger, 'vo': 'cms', 'group': group, 'role': role,
                     'myProxySvr': myProxySvr, 'proxyValidity' : '192:00', 'min_time_left' : 36000,
                     'uisource' : uiPath, 'serverDN' : serverDN}

        self.proxyPath = None
        self.proxy = Proxy( self.dict )
        self.serverDN = self.dict['serverDN']

    def tearDown(self):
        """
        _tearDown_
        """
        return

    @attr("integration")
    def testAAACreateMyProxy( self ):
        """
        Test if delegate method create correctly the MyProxy.
        """
        self.proxy.create()
        self.proxy.delegate( credential = self.proxyPath )
        valid = self.proxy.checkMyProxy( )
        self.assertTrue(valid, 'Could not create MyProxy')

    @attr("integration")
    def testDelegateServer( self ):
        """
        Test if delegate method create MyProxy and delegate
        the retrieval to the server correctly.
        """
        self.proxy.delegate( credential = self.proxyPath, serverRenewer = True )
        valid = self.proxy.checkMyProxy( checkRenewer = True )
        self.assertTrue(valid)

    @attr("integration")
    def testCheckMyProxy( self ):
        """
        Test if checkMyProxy checks correctly the MyProxy validity.
        """
        valid = self.proxy.checkMyProxy( )
        self.assertTrue(valid)

    @attr("integration")
    def testRenewMyProxy( self ):
        """
        Test if renewMyProxy method renews correctly the MyProxy.
        """
        self.proxy.renewMyProxy( proxy = self.proxyPath )
        time.sleep( 5 )
        timeLeft = self.proxy.getMyProxyTimeLeft( proxy = self.proxyPath )
        self.assertEqual(int(timeLeft) / 3600, 167)

    @attr("integration")
    def testRenewMyProxyForServer( self ):
        """
        Renew MyProxy which the retrieval is delegated to a server.
        """
        time.sleep( 70 )
        self.proxy.renewMyProxy( proxy = self.proxyPath, serverRenewer = True )
        time.sleep( 5 )
        timeLeft = self.proxy.getMyProxyTimeLeft( proxy = self.proxyPath, serverRenewer = True )
        self.assertEqual(int(timeLeft) / 3600, 167)

    @attr("integration")
    def testMyProxyEnvironment(self):
        """
        Test the myProxyEnvironment context manager
        In this test a new Proxy and MyProxy are initialized
        """
        myProxy = Proxy(self.dict)

        # Create the proxy
        myProxy.create()
        proxyPath = myProxy.getProxyFilename()
        userDN = myProxy.getSubject()
        self.assertTrue(os.path.exists(proxyPath))

        # Delegate and check the proxy
        myProxy.delegate(credential=proxyPath, serverRenewer=True)
        valid = myProxy.checkMyProxy()
        self.assertTrue(valid)

        # Make sure X509_USER_PROXY exists only in the context manager and corresponds to a file
        if 'X509_USER_PROXY' in os.environ:
            del os.environ['X509_USER_PROXY']
        self.assertFalse('X509_USER_PROXY' in os.environ)
        with myProxyEnvironment(userDN=userDN, serverCert=serverCert, serverKey=serverKey,
#.........这里部分代码省略.........
开发者ID:AndresTanasijczuk,项目名称:WMCore,代码行数:103,代码来源:MyProxy_t.py


注:本文中的WMCore.Credential.Proxy.Proxy.delegate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。