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)
    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()
 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)
    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()
 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"]
    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'])
 def test_parse_isotime(self):
     expect = timeutils.parse_isotime(self.skynet_self_aware_time_str)
     self.assertEqual(self.skynet_self_aware_time, expect)
 def test_parse_isotime(self):
     expect = timeutils.parse_isotime(self.skynet_self_aware_time_str)
     self.assertEqual(self.skynet_self_aware_time, expect)
 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)
Example #10
0
 def expires(self):
     return timeutils.parse_isotime(self._info['expires_at'])
 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)
Example #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)
 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))
Example #14
0
 def expires(self):
     return timeutils.parse_isotime(self._info['token']['expires'])
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
 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)
 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)
 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)
 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)
Example #24
0
 def expires(self):
     return timeutils.parse_isotime(self._info['expires_at'])
 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)
Example #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)
Example #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)
 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)
Example #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)
 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)
Example #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)
 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)
Example #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)
 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)
Example #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)
 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)
Example #37
0
 def expires(self):
     return timeutils.parse_isotime(self._info['token']['expires'])