Hello! We are running our annual fundraising. Please consider making a donation if you value this freely available service or want to support people around the world working towards liberatory social change. https://riseup.net/donate.

Commit f9fbae0e authored by Victor's avatar Victor
Browse files

[refactor] make blobs resource backend configurable

- Resolves: #8804
parent 6795f5ec
......@@ -153,14 +153,14 @@ class BlobsResource(resource.Resource):
isLeaf = True
# Allowed factory classes are defined here
blobsFactoryClass = FilesystemBlobsBackend
# Allowed backend classes are defined here
handlers = {"filesystem": FilesystemBlobsBackend}
def __init__(self, blobs_path):
# TODO pass the backend as configurable option #8804
def __init__(self, backend, blobs_path, **backend_args):
resource.Resource.__init__(self)
self._blobs_path = blobs_path
self._handler = self.blobsFactoryClass(blobs_path)
backend_args.update({'blobs_path': blobs_path})
self._handler = self.handlers[backend](**backend_args)
assert interfaces.IBlobsBackend.providedBy(self._handler)
# TODO double check credentials, we can have then
......@@ -219,7 +219,7 @@ if __name__ == '__main__':
parser.add_argument('--path', default='/tmp/blobs/user')
args = parser.parse_args()
root = BlobsResource(args.path)
root = BlobsResource("filesystem", args.path)
# I picture somethink like
# BlobsResource(backend="filesystem", backend_opts={'path': '/tmp/blobs'})
......
......@@ -54,7 +54,8 @@ class SoledadRealm(object):
if conf is None:
conf = get_config()
blobs = conf['blobs']
blobs_resource = BlobsResource(conf['blobs_path']) if blobs else None
blobs_resource = BlobsResource("filesystem",
conf['blobs_path']) if blobs else None
self.anon_resource = SoledadAnonResource(
enable_blobs=blobs)
self.auth_resource = SoledadResource(
......
......@@ -43,7 +43,7 @@ class SoledadResourceTestCase(unittest.TestCase):
self.assertIsInstance(child, ServerInfo)
def test_get_blobs_enabled(self):
blobs_resource = BlobsResource('/tmp')
blobs_resource = BlobsResource("filesystem", '/tmp')
resource = SoledadResource(
blobs_resource=blobs_resource, sync_pool=_pool)
request = DummyRequest(['blobs'])
......
......@@ -27,7 +27,7 @@ class BlobServerTestCase(unittest.TestCase):
@pytest.mark.usefixtures("method_tmpdir")
def setUp(self):
self.resource = server_blobs.BlobsResource(self.tempdir)
self.resource = server_blobs.BlobsResource("filesystem", self.tempdir)
@pytest.mark.usefixtures("method_tmpdir")
def test_valid_arguments(self):
......
......@@ -33,7 +33,7 @@ from leap.soledad.client._db.blobs import BlobAlreadyExistsError
class BlobServerTestCase(unittest.TestCase):
def setUp(self):
root = server_blobs.BlobsResource(self.tempdir)
root = server_blobs.BlobsResource("filesystem", self.tempdir)
site = Site(root)
self.port = reactor.listenTCP(0, site, interface='127.0.0.1')
self.host = self.port.getHost()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment