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


Python Credential.get_expiration方法代碼示例

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


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

示例1: validate_credential

# 需要導入模塊: from sfa.trust.credential import Credential [as 別名]
# 或者: from sfa.trust.credential.Credential import get_expiration [as 別名]
 def validate_credential(self, filename):
     valid = True
     cred = Credential(filename=filename)
     # check if credential is expires
     if cred.get_expiration() < datetime.utcnow():
         valid = False
     return valid
開發者ID:nfvproject,項目名稱:SFA,代碼行數:9,代碼來源:sfaclientlib.py

示例2: get_cached_credential

# 需要導入模塊: from sfa.trust.credential import Credential [as 別名]
# 或者: from sfa.trust.credential.Credential import get_expiration [as 別名]
 def get_cached_credential(self, file):
     """
     Return a cached credential only if it hasn't expired.
     """
     if (os.path.isfile(file)):
         credential = Credential(filename=file)
         # make sure it isnt expired 
         if not credential.get_expiration or \
            datetime.datetime.today() < credential.get_expiration():
             return credential
     return None 
開發者ID:planetlab,項目名稱:sfa,代碼行數:13,代碼來源:sfi.py

示例3: call

# 需要導入模塊: from sfa.trust.credential import Credential [as 別名]
# 或者: from sfa.trust.credential.Credential import get_expiration [as 別名]
    def call(self, urns, creds, expiration_time, options):


        # Find the valid credentials
        valid_creds = self.api.auth.checkCredentialsSpeaksFor(creds, 'renewsliver', urns,
                                                              check_sliver_callback = self.api.driver.check_sliver_credentials,
                                                              options=options)
        the_credential = Credential(cred=valid_creds[0])
        actual_caller_hrn = the_credential.actual_caller_hrn()
        self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-urns: %s\texpiration:%s\tmethod-name: %s"%\
                             (self.api.interface, actual_caller_hrn, urns, expiration_time,self.name))


        # extend as long as possible : take the min of requested and now+SFA_MAX_SLICE_RENEW
        if options.get('geni_extend_alap'):
            # ignore requested time and set to max
            expiration_time = add_datetime(datetime.datetime.utcnow(), days=int(self.api.config.SFA_MAX_SLICE_RENEW))

        # Validate that the time does not go beyond the credential's expiration time
        requested_expire = utcparse(expiration_time)
        self.api.logger.info("requested_expire = %s"%requested_expire)
        credential_expire = the_credential.get_expiration()
        self.api.logger.info("credential_expire = %s"%credential_expire)
        max_renew_days = int(self.api.config.SFA_MAX_SLICE_RENEW)
        max_expire = datetime.datetime.utcnow() + datetime.timedelta (days=max_renew_days)
        if requested_expire > credential_expire:
            # used to throw an InsufficientRights exception here, this was not right
            self.api.logger.warning("Requested expiration %s, after credential expiration (%s) -> trimming to the latter/sooner"%\
                                    (requested_expire, credential_expire))
            requested_expire = credential_expire
        if requested_expire > max_expire:
            # likewise
            self.api.logger.warning("Requested expiration %s, after maximal expiration %s days (%s) -> trimming to the latter/sooner"%\
                                    (requested_expire, self.api.config.SFA_MAX_SLICE_RENEW,max_expire))
            requested_expire = max_expire

        return self.api.manager.Renew(self.api, urns, creds, requested_expire, options)
開發者ID:kongseokhwan,項目名稱:sfa,代碼行數:39,代碼來源:Renew.py

示例4: getCredential

# 需要導入模塊: from sfa.trust.credential import Credential [as 別名]
# 或者: from sfa.trust.credential.Credential import get_expiration [as 別名]
    def getCredential(self):
        """
        Return a valid credential for this interface. 
        """
        type = 'authority'
        path = self.config.SFA_DATA_DIR
        filename = ".".join([self.interface, self.hrn, type, "cred"])
        cred_filename = path + os.sep + filename
        cred = None
        if os.path.isfile(cred_filename):
            cred = Credential(filename = cred_filename)
            # make sure cred isnt expired
            if not cred.get_expiration or \
               datetime.datetime.utcnow() < cred.get_expiration():    
                return cred.save_to_string(save_parents=True)

        # get a new credential
        if self.interface in ['registry']:
            cred =  self.__getCredentialRaw()
        else:
            cred =  self.__getCredential()
        cred.save_to_file(cred_filename, save_parents=True)

        return cred.save_to_string(save_parents=True)
開發者ID:planetlab,項目名稱:sfa,代碼行數:26,代碼來源:api.py


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