Add backends for user and org configs

This commit is contained in:
Rafa de la Torre
2016-10-03 16:05:08 +02:00
parent 8fbb41742c
commit 9e98e0794d
5 changed files with 56 additions and 13 deletions

View File

@@ -0,0 +1,25 @@
from cartodb_services.refactor.storage.redis_connection_config import RedisMetadataConnectionConfigBuilder
from cartodb_services.refactor.storage.redis_connection import RedisConnectionBuilder
from cartodb_services.refactor.storage.redis_config import RedisOrgConfigStorageBuilder
class OrgConfigBackendFactory(object):
"""
This class abstracts the creation of an org configuration storage. It will return
an implementation of the ConfigStorageInterface appropriate to the org, depending
on the environment.
"""
def __init__(self, orgname, environment, server_config_storage):
self._orgname = orgname
self._environment = environment
self._server_config_storage = server_config_storage
def get(self):
# TODO rename Environment class to ServerEnvironment and add accessors instead of checking against plain str
if self._environment == 'onpremise':
org_config_backend = self._server_config_storage
else:
redis_metadata_connection_config = RedisMetadataConnectionConfigBuilder(self._server_config_storage).get()
redis_metadata_connection = RedisConnectionBuilder(redis_metadata_connection_config).get()
org_config_backend = RedisOrgConfigStorageBuilder(redis_metadata_connection, self._orgname).get()
return org_config_backend

View File

@@ -0,0 +1,25 @@
from cartodb_services.refactor.storage.redis_connection_config import RedisMetadataConnectionConfigBuilder
from cartodb_services.refactor.storage.redis_connection import RedisConnectionBuilder
from cartodb_services.refactor.storage.redis_config import RedisUserConfigStorageBuilder
class UserConfigBackendFactory(object):
"""
This class abstracts the creation of a user configuration storage. It will return
an implementation of the ConfigStorageInterface appropriate to the user, depending
on the environment.
"""
def __init__(self, username, environment, server_config_storage):
self._username = username
self._environment = environment
self._server_config_storage = server_config_storage
def get(self):
# TODO rename Environment class to ServerEnvironment and add accessors instead of checking against plain str
if self._environment == 'onpremise':
user_config_backend = self._server_config_storage
else:
redis_metadata_connection_config = RedisMetadataConnectionConfigBuilder(self._server_config_storage).get()
redis_metadata_connection = RedisConnectionBuilder(redis_metadata_connection_config).get()
user_config_backend = RedisUserConfigStorageBuilder(redis_metadata_connection, self._username).get()
return user_config_backend

View File

@@ -16,7 +16,6 @@ class RedisConfigStorage(ConfigStorageInterface):
class RedisUserConfigStorageBuilder(object):
# TODO rework to support onpremise and InDbStorage
def __init__(self, redis_connection, username):
self._redis_connection = redis_connection
self._username = username
@@ -26,7 +25,6 @@ class RedisUserConfigStorageBuilder(object):
class RedisOrgConfigStorageBuilder(object):
# TODO rework to support onpremise and InDbStorage
def __init__(self, redis_connection, orgname):
self._redis_connection = redis_connection
self._orgname = orgname