示例#1
0
文件: _ods21.py 项目: zavarat/freeipa
 def get_keys_for_zone(self, zone_id):
     cur = self._db.execute(
         "SELECT hsmk.locator, hsmk.inception, hsmk.algorithm, "
         "hsmk.role, hsmk.state "
         "FROM hsmKey AS hsmk "
         "JOIN keyData AS kd ON hsmk.id = kd.hsmKeyId "
         "WHERE kd.zoneId = ?", (zone_id,))
     for row in cur:
         key = dict()
         key['HSMkey_id'] = row['locator']
         # The date is stored in UTC format but OpenDNSSEC 1.4 was
         # returning a local tz format
         tz = dateutil.tz.tzlocal()
         key['generate'] = ipautil.datetime_from_utctimestamp(
             row['inception'],
             units=1).astimezone(tz).replace(tzinfo=None).isoformat(
                 sep=' ', timespec='seconds')
         key['algorithm'] = row['algorithm']
         key['publish'] = key['generate']
         key['active'] = None
         key['retire'] = None
         key['dead'] = None
         if row['role'] == 2:
             key['keytype'] = 256
         elif row['role'] == 1:
             key['keytype'] = 257
         key['state'] = row['state']
         yield key
示例#2
0
 def timestamp(self, value):
     if value is None:
         self._timestamp = None
     elif isinstance(value, datetime.datetime):
         self._timestamp = value
     elif isinstance(value, (int, float)):
         self._timestamp = datetime_from_utctimestamp(value, units=1)
     elif isinstance(value, str):
         self._timestamp = Cookie.parse_datetime(value)
     else:
         raise TypeError('value must be datetime, int, long, float, basestring or None, not %s' % \
                         value.__class__.__name__)
示例#3
0
    def normalization_setup(self):
        # Force microseconds to zero because cookie timestamps only have second resolution
        self.now = datetime.datetime.now(tz=datetime.timezone.utc).replace(
            microsecond=0)
        self.now_timestamp = datetime_from_utctimestamp(
            self.now.utctimetuple(), units=1).timestamp()
        self.now_string = email.utils.formatdate(self.now_timestamp,
                                                 usegmt=True)

        self.max_age = 3600  # 1 hour
        self.age_expiration = self.now + datetime.timedelta(
            seconds=self.max_age)
        self.age_timestamp = datetime_from_utctimestamp(
            self.age_expiration.utctimetuple(), units=1).timestamp()
        self.age_string = email.utils.formatdate(self.age_timestamp,
                                                 usegmt=True)

        self.expires = self.now + datetime.timedelta(days=1)  # 1 day
        self.expires_timestamp = datetime_from_utctimestamp(
            self.expires.utctimetuple(), units=1).timestamp()
        self.expires_string = email.utils.formatdate(self.expires_timestamp,
                                                     usegmt=True)
示例#4
0
 def expires(self, value):
     if value is None:
         self._expires = None
     elif isinstance(value, datetime.datetime):
         self._expires = value
         if self._expires.tzinfo is None:
             self._expires.replace(tzinfo=datetime.timezone.utc)
     elif isinstance(value, (int, float)):
         self._expires = datetime_from_utctimestamp(value, units=1)
     elif isinstance(value, str):
         self._expires = Cookie.parse_datetime(value)
     else:
         raise TypeError('value must be datetime, int, long, float, basestring or None, not %s' % \
                         value.__class__.__name__)