diff options
author | Simo Sorce <simo@redhat.com> | 2015-04-07 15:39:48 -0400 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2015-04-07 17:15:24 -0400 |
commit | ec754903728595bd3a29fff5993dd1495506c188 (patch) | |
tree | e2bf6b851320d038d717bdf33fed766af2bf9bc6 /custodia | |
parent | 02457aaa7b1d46626fecd3560dd5259d82f4c1ee (diff) | |
download | custodia-ec754903728595bd3a29fff5993dd1495506c188.tar.gz custodia-ec754903728595bd3a29fff5993dd1495506c188.tar.xz custodia-ec754903728595bd3a29fff5993dd1495506c188.zip |
Return 201 on successful key creation
Diffstat (limited to 'custodia')
-rw-r--r-- | custodia/secrets.py | 38 |
1 files changed, 20 insertions, 18 deletions
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 |