Пример #1
0
 def test_compare_micros(self):
     zulu = timeutils.parse_isotime('2012-02-14T20:53:07.6544')
     east = timeutils.parse_isotime('2012-02-14T19:53:07.654321-01:00')
     west = timeutils.parse_isotime('2012-02-14T21:53:07.655+01:00')
     self.assertTrue(east < west)
     self.assertTrue(east < zulu)
     self.assertTrue(zulu < west)
Пример #2
0
    def __init__(self, connection, secret_dict):
        """
        Builds a secret object from a json representation. Includes the
        connection object for subtasks.
        """
        self._connection = connection
        self.secret_ref = secret_dict['secret_ref']
        self.created = parse_isotime(secret_dict['created'])
        self.status = secret_dict['status']

        self.algorithm = secret_dict.get('algorithm')
        self.bit_length = secret_dict.get('bit_length')
        self.mime_type = secret_dict.get('mime_type')
        self.name = secret_dict.get('name')
        self.cypher_type = secret_dict.get('cypher_type')

        if secret_dict.get('expiration') is not None:
            self.expiration = parse_isotime(secret_dict['expiration'])
        else:
            self.expiration = None

        if secret_dict.get('updated') is not None:
            self.updated = parse_isotime(secret_dict['updated'])
        else:
            self.updated = None

        self._id = urlparse(self.secret_ref).path.split('/').pop()
Пример #3
0
 def test_compare(self):
     zulu = timeutils.parse_isotime('2012-02-14T20:53:07')
     east = timeutils.parse_isotime('2012-02-14T20:53:07-01:00')
     west = timeutils.parse_isotime('2012-02-14T20:53:07+01:00')
     self.assertTrue(east > west)
     self.assertTrue(east > zulu)
     self.assertTrue(zulu > west)
Пример #4
0
    def __init__(self, connection, order_dict):
        """
        Builds an order object from a json representation. Includes the
        connection object for subtasks.
        """
        self.connection = connection
        self.status = order_dict.get('status')
        self.secret = order_dict.get('secret')  # TODO: store as object?
        self.secret_ref = order_dict.get('secret_ref')
        self.order_ref = order_dict.get('order_ref')
        self.created = parse_isotime(order_dict.get('created'))
        if order_dict.get('updated') is not None:
            self.updated = parse_isotime(order_dict['updated'])
        else:
            self.updated = None

        self._id = urlparse(self.order_ref).path.split('/').pop()
Пример #5
0
 def create_secret(self, name, mime_type, algorithm, bit_length, cypher_type, plain_text, expiration):
     href = "{0}/{1}".format(self._tenant, self.SECRETS_PATH)
     secret_dict = {}
     secret_dict["name"] = name
     secret_dict["mime_type"] = mime_type
     secret_dict["algorithm"] = algorithm
     secret_dict["bit_length"] = int(bit_length)
     secret_dict["cypher_type"] = cypher_type
     secret_dict["plain_text"] = plain_text
     if expiration is not None:
         secret_dict["expiration"] = parse_isotime(expiration)
     hdrs, body = self._perform_http(href=href, method="POST", request_body=json.dumps(secret_dict))
     return body["secret_ref"]
Пример #6
0
    def create_secret(self,
                      mime_type,
                      plain_text=None,
                      name=None,
                      algorithm=None,
                      bit_length=None,
                      cypher_type=None,
                      expiration=None):
        """
        Creates and returns a Secret object with all of its metadata filled in.

        arguments:
            mime_type - The MIME type of the secret
            plain_text - The unencrypted secret
            name - A friendly name for the secret
            algorithm - The algorithm the secret is used with
            bit_length - The bit length of the secret
            cypher_type - The cypher type (e.g. block cipher mode of operation)
            expiration - The expiration time for the secret in ISO 8601 format
        """
        LOG.debug(_("Creating secret of mime_type {0}").format(mime_type))
        href = "{0}/{1}".format(self._tenant, self.SECRETS_PATH)
        LOG.debug(_("href: {0}").format(href))
        secret_dict = {}
        secret_dict['mime_type'] = mime_type
        secret_dict['plain_text'] = plain_text
        secret_dict['name'] = name
        secret_dict['algorithm'] = algorithm
        secret_dict['cypher_type'] = cypher_type
        if bit_length is not None:
            secret_dict['bit_length'] = int(bit_length)
        if expiration is not None:
            secret_dict['expiration'] = parse_isotime(expiration)
        self._remove_empty_keys(secret_dict)
        LOG.debug(_("Request body: {0}").format(secret_dict))
        hdrs, body = self._perform_http(href=href,
                                        method='POST',
                                        request_body=json.dumps(secret_dict))

        LOG.debug(_("Response - headers: {0}\nbody: {1}").format(hdrs, body))

        return self.get_secret(body['secret_ref'])
Пример #7
0
 def test_parse_isotime(self):
     expect = timeutils.parse_isotime(self.skynet_self_aware_time_str)
     self.assertEqual(self.skynet_self_aware_time, expect)
Пример #8
0
 def test_parse_isotime(self):
     expect = timeutils.parse_isotime(self.skynet_self_aware_time_str)
     self.assertEqual(self.skynet_self_aware_time, expect)
Пример #9
0
 def test_normalize_zulu_aware_to_naive(self):
     dt = datetime.datetime(2011, 2, 14, 20, 53, 7)
     time_str = '2011-02-14T19:53:07Z'
     aware = timeutils.parse_isotime(time_str)
     naive = timeutils.normalize_time(aware)
     self.assertTrue(naive < dt)
Пример #10
0
 def expires(self):
     return timeutils.parse_isotime(self._info['expires_at'])
Пример #11
0
 def _do_test(self, time_str, yr, mon, day, hr, minute, sec, micro, shift):
     DAY_SECONDS = 24 * 60 * 60
     timestamp = timeutils.parse_isotime(time_str)
     self._instaneous(timestamp, yr, mon, day, hr, minute, sec, micro)
     offset = timestamp.tzinfo.utcoffset(None)
     self.assertEqual(offset.seconds + offset.days * DAY_SECONDS, shift)
Пример #12
0
 def test_zulu_roundtrip(self):
     str = '2012-02-14T20:53:07Z'
     zulu = timeutils.parse_isotime(str)
     self.assertEquals(zulu.tzinfo, iso8601.iso8601.UTC)
     self.assertEquals(timeutils.isotime(zulu), str)
Пример #13
0
 def test_parse_isotime(self):
     skynet_self_aware_time_str = '1997-08-29T06:14:00Z'
     skynet_self_aware_time = datetime.datetime(1997, 8, 29, 6, 14, 0,
                                                tzinfo=iso8601.iso8601.UTC)
     self.assertEqual(skynet_self_aware_time,
                      timeutils.parse_isotime(skynet_self_aware_time_str))
Пример #14
0
 def expires(self):
     return timeutils.parse_isotime(self._info['token']['expires'])
Пример #15
0
 def test_zulu_normalize(self):
     str = '2012-02-14T20:53:07Z'
     zulu = timeutils.parse_isotime(str)
     normed = timeutils.normalize_time(zulu)
     self._instaneous(normed, 2012, 2, 14, 20, 53, 07, 0)
Пример #16
0
 def test_east_normalize(self):
     str = '2012-02-14T20:53:07-07:00'
     east = timeutils.parse_isotime(str)
     normed = timeutils.normalize_time(east)
     self._instaneous(normed, 2012, 2, 15, 03, 53, 07, 0)
Пример #17
0
 def test_now_roundtrip(self):
     str = timeutils.isotime()
     now = timeutils.parse_isotime(str)
     self.assertEquals(now.tzinfo, iso8601.iso8601.UTC)
     self.assertEquals(timeutils.isotime(now), str)
Пример #18
0
 def test_west_roundtrip(self):
     str = '2012-02-14T20:53:07+11:30'
     west = timeutils.parse_isotime(str)
     self.assertEquals(west.tzinfo.tzname(None), '+11:30')
     self.assertEquals(timeutils.isotime(west), str)
Пример #19
0
 def test_east_roundtrip(self):
     str = '2012-02-14T20:53:07-07:00'
     east = timeutils.parse_isotime(str)
     self.assertEquals(east.tzinfo.tzname(None), '-07:00')
     self.assertEquals(timeutils.isotime(east), str)
Пример #20
0
 def test_normalize_aware_to_naive(self):
     dt = datetime.datetime(2011, 2, 14, 20, 53, 07)
     str = '2011-02-14T20:53:07+21:00'
     aware = timeutils.parse_isotime(str)
     naive = timeutils.normalize_time(aware)
     self.assertTrue(naive < dt)
Пример #21
0
 def test_east_roundtrip(self):
     time_str = '2012-02-14T20:53:07-07:00'
     east = timeutils.parse_isotime(time_str)
     self.assertEqual(east.tzinfo.tzname(None), '-07:00')
     self.assertEqual(timeutils.isotime(east), time_str)
Пример #22
0
 def test_normalize_zulu_aware_to_naive(self):
     dt = datetime.datetime(2011, 2, 14, 20, 53, 07)
     str = '2011-02-14T19:53:07Z'
     aware = timeutils.parse_isotime(str)
     naive = timeutils.normalize_time(aware)
     self.assertTrue(naive < dt)
Пример #23
0
 def test_now_roundtrip(self):
     time_str = timeutils.isotime()
     now = timeutils.parse_isotime(time_str)
     self.assertEqual(now.tzinfo, iso8601.iso8601.UTC)
     self.assertEqual(timeutils.isotime(now), time_str)
Пример #24
0
 def expires(self):
     return timeutils.parse_isotime(self._info['expires_at'])
Пример #25
0
 def test_east_normalize(self):
     time_str = '2012-02-14T20:53:07-07:00'
     east = timeutils.parse_isotime(time_str)
     normed = timeutils.normalize_time(east)
     self._instaneous(normed, 2012, 2, 15, 3, 53, 7, 0)
Пример #26
0
 def test_west_normalize(self):
     str = '2012-02-14T20:53:07+21:00'
     west = timeutils.parse_isotime(str)
     normed = timeutils.normalize_time(west)
     self._instaneous(normed, 2012, 2, 13, 23, 53, 07, 0)
Пример #27
0
 def _do_test(self, str, yr, mon, day, hr, min, sec, micro, shift):
     DAY_SECONDS = 24 * 60 * 60
     timestamp = timeutils.parse_isotime(str)
     self._instaneous(timestamp, yr, mon, day, hr, min, sec, micro)
     offset = timestamp.tzinfo.utcoffset(None)
     self.assertEqual(offset.seconds + offset.days * DAY_SECONDS, shift)
Пример #28
0
 def test_zulu_roundtrip(self):
     time_str = '2012-02-14T20:53:07Z'
     zulu = timeutils.parse_isotime(time_str)
     self.assertEqual(zulu.tzinfo, iso8601.iso8601.UTC)
     self.assertEqual(timeutils.isotime(zulu), time_str)
Пример #29
0
 def test_zulu_roundtrip(self):
     str = "2012-02-14T20:53:07Z"
     zulu = timeutils.parse_isotime(str)
     self.assertEquals(zulu.tzinfo, iso8601.iso8601.UTC)
     self.assertEquals(timeutils.isotime(zulu), str)
Пример #30
0
 def test_west_roundtrip(self):
     time_str = '2012-02-14T20:53:07+11:30'
     west = timeutils.parse_isotime(time_str)
     self.assertEqual(west.tzinfo.tzname(None), '+11:30')
     self.assertEqual(timeutils.isotime(west), time_str)
Пример #31
0
 def test_east_normalize(self):
     str = "2012-02-14T20:53:07-07:00"
     east = timeutils.parse_isotime(str)
     normed = timeutils.normalize_time(east)
     self._instaneous(normed, 2012, 2, 15, 03, 53, 07, 0)
Пример #32
0
 def test_zulu_normalize(self):
     time_str = '2012-02-14T20:53:07Z'
     zulu = timeutils.parse_isotime(time_str)
     normed = timeutils.normalize_time(zulu)
     self._instaneous(normed, 2012, 2, 14, 20, 53, 7, 0)
Пример #33
0
 def test_east_roundtrip(self):
     str = "2012-02-14T20:53:07-07:00"
     east = timeutils.parse_isotime(str)
     self.assertEqual(east.tzinfo.tzname(None), "-07:00")
     self.assertEqual(timeutils.isotime(east), str)
Пример #34
0
 def test_west_normalize(self):
     time_str = '2012-02-14T20:53:07+21:00'
     west = timeutils.parse_isotime(time_str)
     normed = timeutils.normalize_time(west)
     self._instaneous(normed, 2012, 2, 13, 23, 53, 7, 0)
Пример #35
0
 def test_west_roundtrip(self):
     str = "2012-02-14T20:53:07+11:30"
     west = timeutils.parse_isotime(str)
     self.assertEqual(west.tzinfo.tzname(None), "+11:30")
     self.assertEqual(timeutils.isotime(west), str)
Пример #36
0
 def test_parse_isotime_micro_second_precision(self):
     expect = timeutils.parse_isotime(self.skynet_self_aware_time_ms_str)
     skynet_self_aware_time_ms_utc = self.skynet_self_aware_ms_time.replace(
         tzinfo=iso8601.iso8601.UTC)
     self.assertEqual(skynet_self_aware_time_ms_utc, expect)
Пример #37
0
 def expires(self):
     return timeutils.parse_isotime(self._info['token']['expires'])