From 0b7b44d8a5ec126f688db38e4669b3a763f0c14d Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Thu, 29 Sep 2016 17:46:17 +0200 Subject: [PATCH] Add a couple of factories to abstract user/org configs --- .../refactor/storage/server_config.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/server/lib/python/cartodb_services/cartodb_services/refactor/storage/server_config.py b/server/lib/python/cartodb_services/cartodb_services/refactor/storage/server_config.py index 3637e3d..7a65946 100644 --- a/server/lib/python/cartodb_services/cartodb_services/refactor/storage/server_config.py +++ b/server/lib/python/cartodb_services/cartodb_services/refactor/storage/server_config.py @@ -25,6 +25,11 @@ class InMemoryConfigStorage(ConfigStorageInterface): except KeyError: return None +class NullConfigStorage(ConfigStorageInterface): + + def get(self, key): + return None + # TODO move out of this file. In general this is config but either user or org config class RedisConfigStorage(ConfigStorageInterface): @@ -37,3 +42,24 @@ class RedisConfigStorage(ConfigStorageInterface): if not self._data: self._data = self._connection.hgetall(self._config_key) return self._data[key] + +class UserConfigStorageFactory(object): + # TODO rework to support onpremise and InDbStorage + def __init__(self, redis_connection, username): + self._redis_connection = redis_connection + self._username = username + + def get(self): + return RedisConfigStorage(self._redis_connection, 'rails:users:{0}'.format(self._username)) + +class OrgConfigStorageFactory(object): + # TODO rework to support onpremise and InDbStorage + def __init__(self, redis_connection, orgname): + self._redis_connection = redis_connection + self._orgname = orgname + + def get(self): + if self._orgname: + return RedisConfigStorage(self._redis_connection, 'rails:orgs:{0}'.format(self._orgname)) + else: + return NullConfigStorage()