From 773b96796dfaa2e43c9d16d1a1cdbd609a520056 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Tue, 23 May 2017 04:53:10 -0300 Subject: [refactor] improve backend naming and error handling --- server/src/leap/soledad/server/_blobs.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/server/src/leap/soledad/server/_blobs.py b/server/src/leap/soledad/server/_blobs.py index 27e79736..10678360 100644 --- a/server/src/leap/soledad/server/_blobs.py +++ b/server/src/leap/soledad/server/_blobs.py @@ -149,6 +149,10 @@ class FilesystemBlobsBackend(object): return self._validate_path(path, user, blob_id) +class ImproperlyConfiguredException(Exception): + pass + + class BlobsResource(resource.Resource): isLeaf = True @@ -156,11 +160,13 @@ class BlobsResource(resource.Resource): # Allowed backend classes are defined here handlers = {"filesystem": FilesystemBlobsBackend} - def __init__(self, backend, blobs_path, **backend_args): + def __init__(self, backend, blobs_path, **backend_kwargs): resource.Resource.__init__(self) self._blobs_path = blobs_path - backend_args.update({'blobs_path': blobs_path}) - self._handler = self.handlers[backend](**backend_args) + backend_kwargs.update({'blobs_path': blobs_path}) + if backend not in self.handlers: + raise ImproperlyConfiguredException("No such backend: %s", backend) + self._handler = self.handlers[backend](**backend_kwargs) assert interfaces.IBlobsBackend.providedBy(self._handler) # TODO double check credentials, we can have then -- cgit v1.2.3