diff --git a/barbicanclient/client.py b/barbicanclient/client.py index e89c1e20..2b74dbda 100644 --- a/barbicanclient/client.py +++ b/barbicanclient/client.py @@ -322,9 +322,9 @@ class Connection(object): def create_order(self, name=None, - algorithm=None, - bit_length=None, - cypher_type=None, + algorithm='aes', + bit_length=256, + cypher_type='cbc', expiration=None): """ Creates and returns an Order object with all of its metadata filled in. @@ -342,6 +342,7 @@ class Connection(object): order_dict['secret']['name'] = name order_dict['secret'][ 'payload_content_type'] = 'application/octet-stream' + order_dict['secret']['payload_content_encoding'] = 'base64' order_dict['secret']['algorithm'] = algorithm order_dict['secret']['bit_length'] = bit_length order_dict['secret']['cypher_type'] = cypher_type diff --git a/barbicanclient/keep.py b/barbicanclient/keep.py index 5c9b7693..d5c93e7b 100644 --- a/barbicanclient/keep.py +++ b/barbicanclient/keep.py @@ -4,7 +4,6 @@ from barbicanclient import client class Keep: - def __init__(self): self.parser = self.get_main_parser() self.subparsers = self.parser.add_subparsers(title='subcommands', @@ -48,17 +47,17 @@ class Keep: create_parser = self.subparsers.add_parser('create', help='Create a ' 'secret or an order') create_parser.add_argument('--name', '-n', help='a human-friendly name' - ' used only for reference') + ) create_parser.add_argument('--algorithm', '-a', default='aes', help='t' - 'he algorithm used only for reference (defa' - 'ult: %(default)s)') + 'he algorithm; used only for reference (def' + 'ault: %(default)s)') create_parser.add_argument('--bit_length', '-b', default=256, help='the bit length of the secret; used ' 'only for reference (default: %(default)s)', type=int) create_parser.add_argument('--cypher_type', '-c', default="cbc", - help='the cypher type used only for referen' - 'ce (default: %(default)s)') + help='the cypher type; used only for refere' + 'nce (default: %(default)s)') create_parser.add_argument('--payload', '-p', help='the unencrypted' ' secret; if provided, you must also provid' 'e a payload_content_type (only used for se' @@ -69,13 +68,14 @@ class Keep: 'secret data; "text/plain" is assumed to be' ' UTF-8; required when --payload is su' 'pplied (only used for secrets; orders are ' - 'assumed to be "application/octet-stream") ' - '(default: %(default)s)') + 'assumed to be of type "application/octet-s' + 'tream") (default: %(default)s)') create_parser.add_argument('--payload_content_encoding', '-d', - choices=["base64"], + default='base64', help='required if --payload_content_type is' - ' "application/octet-stream" (only used for' - ' secrets)') + ' "application/octet-stream" (default: %(de' + 'fault)s)') + create_parser.add_argument('--expiration', '-e', help='the expiration ' 'time for the secret in ISO 8601 format') create_parser.set_defaults(func=self.create) diff --git a/barbicanclient/orders.py b/barbicanclient/orders.py index 3345e458..b8cfad02 100644 --- a/barbicanclient/orders.py +++ b/barbicanclient/orders.py @@ -15,6 +15,12 @@ class Order(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('expiration') is not None: + self.expiration = parse_isotime(order_dict['expiration']) + else: + self.expiration = None + if order_dict.get('updated') is not None: self.updated = parse_isotime(order_dict['updated']) else: diff --git a/tests/client_test.py b/tests/client_test.py index 48b35197..fab2332d 100644 --- a/tests/client_test.py +++ b/tests/client_test.py @@ -104,10 +104,9 @@ class WhenTestingConnection(unittest.TestCase): endpoint=self.endpoint) def test_should_create_secret(self): - body = {'status': 'ACTIVE', - 'content_types': {'default': 'text/plain'}, + body = {'status': "ACTIVE", 'updated': '2013-06-07T16:13:38.889857', - 'cypher_type': 'CDC', + 'cypher_type': 'cbc', 'name': 'test_secret', 'algorithm': 'aes', 'created': '2013-06-07T16:13:38.889851', @@ -115,19 +114,20 @@ class WhenTestingConnection(unittest.TestCase): 'b5e-3738-408e-aaba-05a7177cade5', 'expiration': '2015-06-07T16:13:38.889851', 'bit_length': 256, - 'mime_type': 'text/plain' + 'payload_content_type': 'text/plain' } secret = client.Secret(self.connection, body) self.request.return_value.content = json.dumps(body) - created = self.connection.create_secret('text/plain', - 'Test secret', - name='test_secret', + created = self.connection.create_secret(name='test_secret', + payload='Test secret', algorithm='aes', bit_length=256, - cypher_type='CDC', + cypher_type='cbc', expiration='2015-06-07T16:13' - ':38.889851') + ':38.889851', + payload_content_type= + 'text/plain') self.assertTrue(self._are_equivalent(secret, created)) def test_should_create_order(self): @@ -137,12 +137,14 @@ class WhenTestingConnection(unittest.TestCase): "updated": "2013-06-07T19:00:37.338386", "created": "2013-06-07T19:00:37.298704", "secret": { - "cypher_type": "CDC", - "name": "test_secret", - "algorithm": "aes", - "expiration": "2015-06-07T19:00:37.298704", - "bit_length": 256, - "mime_type": "text/plain" + 'cypher_type': 'cbc', + 'name': 'test_secret', + 'algorithm': 'aes', + 'created': '2013-06-07T16:13:38.889851', + 'expiration': '2015-06-07T16:13:38.889851', + 'bit_length': 256, + 'payload_content_type': 'application/octet-stream', + 'payload_content_encoding': 'base64' }, "order_ref": "http://localhost:9311/v1/12345/orders/003f2b91-" "2f53-4c0a-a0f3-33796671efc3" @@ -150,11 +152,10 @@ class WhenTestingConnection(unittest.TestCase): order = client.Order(self.connection, body) self.request.return_value.content = json.dumps(body) - created = self.connection.create_order('text/plain', - name='test_secret', - bit_length=256, + created = self.connection.create_order(name='test_secret', algorithm='aes', - cypher_type='CDC') + bit_length=256, + cypher_type='cbc') self.assertTrue(self._are_equivalent(order, created)) def test_list_no_secrets(self):