當前位置: 首頁>>代碼示例>>Python>>正文


Python Proxy.getUserGroupAndRoleFromProxy方法代碼示例

本文整理匯總了Python中WMCore.Credential.Proxy.Proxy.getUserGroupAndRoleFromProxy方法的典型用法代碼示例。如果您正苦於以下問題:Python Proxy.getUserGroupAndRoleFromProxy方法的具體用法?Python Proxy.getUserGroupAndRoleFromProxy怎麽用?Python Proxy.getUserGroupAndRoleFromProxy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在WMCore.Credential.Proxy.Proxy的用法示例。


在下文中一共展示了Proxy.getUserGroupAndRoleFromProxy方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: createNewVomsProxy

# 需要導入模塊: from WMCore.Credential.Proxy import Proxy [as 別名]
# 或者: from WMCore.Credential.Proxy.Proxy import getUserGroupAndRoleFromProxy [as 別名]
    def createNewVomsProxy(self, timeleftthreshold=0):
        """
        Handles the proxy creation:
           - checks if a valid proxy still exists
           - performs the creation if it is expired
        """
        ## TODO add the change to have user-cert/key defined in the config.
        userproxy = Proxy( self.defaultDelegation )
        userproxy.userDN = userproxy.getSubject()

        proxytimeleft = 0
        self.logger.debug("Getting proxy life time left")
        # does it return an integer that indicates?
        proxytimeleft = userproxy.getTimeLeft()
        self.logger.debug("Proxy is valid: %i" % proxytimeleft)

        #if it is not expired I check if role and/or group are changed
        if not proxytimeleft < timeleftthreshold and self.defaultDelegation['role']!=None and  self.defaultDelegation['group']!=None:
            group , role = userproxy.getUserGroupAndRoleFromProxy( userproxy.getProxyFilename())
            if group != self.defaultDelegation['group'] or role != self.defaultDelegation['role']:
                self.proxyChanged = True

        #if the proxy is expired, or we changed role and/or group, we need to create a new one
        if proxytimeleft < timeleftthreshold or self.proxyChanged:
            # creating the proxy
            self.logger.debug("Creating a proxy for %s hours" % self.defaultDelegation['proxyValidity'] )
            userproxy.create()
            proxytimeleft = userproxy.getTimeLeft()
            group , role = userproxy.getUserGroupAndRoleFromProxy( userproxy.getProxyFilename())

            if proxytimeleft > 0 and group == self.defaultDelegation['group'] and role == self.defaultDelegation['role']:
                self.logger.debug("Proxy created.")
            else:
                raise ProxyCreationException("Problems creating proxy.")

        return userproxy.getSubject( ), userproxy.getProxyFilename()
開發者ID:bbockelm,項目名稱:CRABClient,代碼行數:38,代碼來源:CredentialInteractions.py

示例2: ProxyTest

# 需要導入模塊: from WMCore.Credential.Proxy import Proxy [as 別名]
# 或者: from WMCore.Credential.Proxy.Proxy import getUserGroupAndRoleFromProxy [as 別名]

#.........這裏部分代碼省略.........
        Verify that the getSubject() method works correctly.
        """
        subject = self.proxy.getSubject()
        self.assertEqual(subject, self.getUserIdentity(), "Error: Wrong subject.")
        return

    @attr("integration")
    def testGetUserName(self):
        """
        _testGetUserName_
        Verify that the getUserName() method correctly determines the user's
        name.
        """
        user = self.proxy.getUserName()
        identity = self.getUserIdentity().split("/")[len(self.getUserIdentity().split("/")) - 1][3:]
        self.assertEqual(user, identity, "Error: User name is wrong: |%s|\n|%s|" % (user, identity))
        return

    @attr("integration")
    def testCheckAttribute(self):
        """
        Test if the checkAttribute  method checks correctly the attributes validity.
        """
        valid = self.proxy.checkAttribute()
        self.assertTrue(valid)

    @attr("integration")
    def testCheckTimeLeft(self):
        """
        Test if the check method checks correctly the proxy validity.
        """
        valid = self.proxy.check(self.proxyPath)
        self.assertTrue(valid)

    @attr("integration")
    def testVomsRenewal(self):
        """
        Test if vomsExtensionRenewal method renews correctly the voms-proxy.
        """
        proxyPath = self.proxy.getProxyFilename()
        time.sleep(70)
        attribute = self.proxy.prepareAttForVomsRenewal(self.proxy.getAttributeFromProxy(proxyPath))
        self.proxy.vomsExtensionRenewal(proxyPath, attribute)
        vomsTimeLeft = self.proxy.getVomsLife(proxyPath)
        self.assertEqual(int(vomsTimeLeft) / 3600, 191)

    @attr("integration")
    def testElevateAttribute(self):
        """
        Test if the vomsExtensionRenewal method elevate last attributes given.
        """
        proxyPath = self.proxy.getProxyFilename()
        attribute = self.proxy.prepareAttForVomsRenewal("/cms/Role=NULL/Capability=NULL")
        self.proxy.vomsExtensionRenewal(proxyPath, attribute)
        self.assertEqual(self.proxy.getAttributeFromProxy(proxyPath), "/cms/Role=NULL/Capability=NULL")
        # Restore the original configuration of the proxy
        self.proxy.create()

    @attr("integration")
    def testUserGroupInProxy(self):
        """
        Test if getUserAttributes method returns correctly the user group.
        """
        self.assertTrue(self.proxy.group, "No group set. Testing incomplete.")
        self.assertEqual(self.proxy.group, self.getUserAttributes().split("\n")[0].split("/")[2])

    @attr("integration")
    def testUserRoleInProxy(self):
        """
        Test if getUserAttributes method returns correctly the user role.
        """
        self.assertEqual(self.proxy.role, self.getUserAttributes().split("\n")[0].split("/")[3].split("=")[1])

    @attr("integration")
    def testGetAttributes(self):
        """
        Test getAttributeFromProxy method.
        """
        self.assertTrue(self.proxy.group, "No group set. Testing incomplete.")
        if not self.dict["role"]:
            role = "NULL"
        else:
            role = self.dict["role"]
        proxyPath = self.proxy.getProxyFilename()
        self.assertEqual(self.proxy.getAttributeFromProxy(proxyPath).split("/")[2], self.dict["group"])
        self.assertEqual(self.proxy.getAttributeFromProxy(proxyPath).split("/")[3].split("=")[1], role)

    @attr("integration")
    def testGetUserGroupAndRole(self):
        """
        Test GetUserGroupAndRoleFromProxy method.
        """
        if not self.dict["role"]:
            role = "NULL"
        else:
            role = self.dict["role"]
        proxyPath = self.proxy.getProxyFilename()
        if self.dict["group"] and self.dict["role"]:
            self.assertEqual(self.proxy.getUserGroupAndRoleFromProxy(proxyPath)[0], self.dict["group"])
            self.assertEqual(self.proxy.getUserGroupAndRoleFromProxy(proxyPath)[1], role)
開發者ID:vlimant,項目名稱:WMCore,代碼行數:104,代碼來源:Proxy_t.py

示例3: ProxyTest

# 需要導入模塊: from WMCore.Credential.Proxy import Proxy [as 別名]
# 或者: from WMCore.Credential.Proxy.Proxy import getUserGroupAndRoleFromProxy [as 別名]

#.........這裏部分代碼省略.........

    @attr("integration")
    def testCheckAttribute( self ):
        """
        Test if the checkAttribute  method checks correctly the attributes validity.
        """
        valid = self.proxy.checkAttribute( )
        self.assertTrue(valid)

    @attr("integration")
    def testCheckTimeLeft( self ):
        """
        Test if the check method checks correctly the proxy validity.
        """
        valid = self.proxy.check( self.proxyPath )
        self.assertTrue(valid)

    @attr("integration")
    def testVomsRenewal( self ):
        """
        Test if vomsExtensionRenewal method renews correctly the voms-proxy.
        """
        proxyPath = self.proxy.getProxyFilename( )
        time.sleep( 70 )
        attribute = self.proxy.prepareAttForVomsRenewal( self.proxy.getAttributeFromProxy( proxyPath ) )
        self.proxy.vomsExtensionRenewal( proxyPath, attribute )
        vomsTimeLeft = self.proxy.getVomsLife( proxyPath )
        self.assertEqual(int(vomsTimeLeft) / 3600, 191)

    @attr("integration")
    def testElevateAttribute( self ):
        """
        Test if the vomsExtensionRenewal method elevate last attributes given.
        """
        proxyPath = self.proxy.getProxyFilename( )
        attribute = self.proxy.prepareAttForVomsRenewal( '/cms/Role=NULL/Capability=NULL' )
        self.proxy.vomsExtensionRenewal( proxyPath, attribute )
        self.assertEqual(self.proxy.getAttributeFromProxy(proxyPath), '/cms/Role=NULL/Capability=NULL')
        # Restore the original configuration of the proxy
        self.proxy.create()

    @attr("integration")
    def testUserGroupInProxy( self ):
        """
        Test if getUserAttributes method returns correctly the user group.
        """
        self.assertTrue(self.proxy.group, 'No group set. Testing incomplete.')
        self.assertEqual(self.proxy.group, self.getUserAttributes().split('\n')[0].split('/')[2])

    @attr("integration")
    def testUserRoleInProxy( self ):
        """
        Test if getUserAttributes method returns correctly the user role.
        """
        self.assertEqual(self.proxy.role, self.getUserAttributes().split('\n')[0].split('/')[3].split('=')[1])

    @attr("integration")
    def testGetAttributes( self ):
        """
        Test getAttributeFromProxy method.

        Can tested this with:
            voms-proxy-init -voms cms:/cms/integration #or any group of yours
            export PROXY_GROUP=integration
            python test/python/WMCore_t/Credential_t/Proxy_t.py ProxyTest.testGetAttributes
        """
        self.assertTrue(self.proxy.group, 'No group set. Testing incomplete.')
        if not self.dict['role']:
            role = 'NULL'
        else:
            role = self.dict['role']
        proxyPath = self.proxy.getProxyFilename( )
        self.assertEqual(self.proxy.getAttributeFromProxy(proxyPath).split('/')[2], self.dict['group'])
        self.assertEqual(self.proxy.getAttributeFromProxy(proxyPath).split('/')[3].split('=')[1], role)

        #test with the allAttributes flag
        self.assertTrue(self.proxy.getAttributeFromProxy(proxyPath, allAttributes=True)>1)

    @attr("integration")
    def testGetUserGroupAndRole( self ):
        """
        Test GetUserGroupAndRoleFromProxy method.
        """
        if not self.dict['role']:
            role = 'NULL'
        else:
            role = self.dict['role']
        proxyPath = self.proxy.getProxyFilename( )
        if self.dict['group'] and self.dict['role']:
            self.assertEqual(self.proxy.getUserGroupAndRoleFromProxy(proxyPath)[0], self.dict['group'])
            self.assertEqual(self.proxy.getUserGroupAndRoleFromProxy(proxyPath)[1], role)

    @attr("integration")
    def testGetAllUserGroups( self ):
        """
        Test GetAllUserGroups method.
        """
        proxyPath = self.proxy.getProxyFilename( )
        groups = self.proxy.getAllUserGroups(proxyPath)
        print(list(groups))
開發者ID:AndresTanasijczuk,項目名稱:WMCore,代碼行數:104,代碼來源:Proxy_t.py


注:本文中的WMCore.Credential.Proxy.Proxy.getUserGroupAndRoleFromProxy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。