From ec754903728595bd3a29fff5993dd1495506c188 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 7 Apr 2015 15:39:48 -0400 Subject: Return 201 on successful key creation --- custodia/secrets.py | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'custodia') diff --git a/custodia/secrets.py b/custodia/secrets.py index a8eac35..e808e19 100644 --- a/custodia/secrets.py +++ b/custodia/secrets.py @@ -82,25 +82,27 @@ class Secrets(HTTPConsumer): ns = self._namespaces(request) if len(trail) == 0 or trail[-1] == '': raise HTTPError(405) - else: - content_type = request.get('headers', - dict()).get('Content-Type', '') - if content_type.split(';')[0].strip() != 'application/json': - raise HTTPError(400, 'Invalid Content-Type') - body = request.get('body') - if body is None: - raise HTTPError(400) - value = bytes(body).decode('utf-8') - try: - self._validate(value) - except ValueError as e: - raise HTTPError(400, str(e)) - key = self._get_key(ns, trail) - try: - self.root.store.set(key, value) - except CSStoreError: - raise HTTPError(500) + content_type = request.get('headers', + dict()).get('Content-Type', '') + if content_type.split(';')[0].strip() != 'application/json': + raise HTTPError(400, 'Invalid Content-Type') + body = request.get('body') + if body is None: + raise HTTPError(400) + value = bytes(body).decode('utf-8') + try: + self._validate(value) + except ValueError as e: + raise HTTPError(400, str(e)) + + key = self._get_key(ns, trail) + try: + self.root.store.set(key, value) + except CSStoreError: + raise HTTPError(500) + + response['code'] = 201 # unit tests -- cgit