Move redis_config related classes to separate file

This commit is contained in:
Rafa de la Torre
2016-10-03 13:33:46 +02:00
parent d522083d5c
commit 275a6dc27f
4 changed files with 40 additions and 47 deletions

View File

@@ -143,7 +143,8 @@ RETURNS Geometry AS $$
from cartodb_services.mapzen.types import country_to_iso3
from cartodb_services.metrics import QuotaService
from cartodb_services.tools import Logger
from cartodb_services.refactor.storage.server_config import InDbServerConfigStorage, UserConfigStorageFactory, OrgConfigStorageFactory
from cartodb_services.refactor.storage.server_config import InDbServerConfigStorage
from cartodb_services.refactor.storage.redis_config import UserConfigStorageFactory, OrgConfigStorageFactory
from cartodb_services.refactor.tools.logger import LoggerConfigBuilder
from cartodb_services.refactor.tools.redis_mock import RedisConnectionMock
from cartodb_services.refactor.storage.redis_connection_config import RedisMetadataConnectionConfigBuilder, RedisMetricsConnectionConfigBuilder

View File

@@ -0,0 +1,38 @@
from interfaces import ConfigStorageInterface
from null_config import NullConfigStorage
class RedisConfigStorage(ConfigStorageInterface):
def __init__(self, connection, config_key):
self._connection = connection
self._config_key = config_key
self._data = None
def get(self, key):
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()

View File

@@ -1,15 +1,6 @@
from cartodb_services.refactor.config.exceptions import ConfigException
from abc import ABCMeta, abstractmethod
"""
How to use this (just a draft, WIP):
redis_connection_config = RedisConnectionConfigBuilder(server_config_storage).get()
connection = RedisConnectionBuilder(redis_connection_config)
user_config_storage = RedisConfigStorage(connection, user)
user_config_storage = UserConfigStorageFactory(environment).get()
"""
class RedisConnectionConfig(object):
"""
@@ -17,7 +8,6 @@ class RedisConnectionConfig(object):
a connection to a redis server.
"""
def __init__(self, host, port, timeout, db, sentinel_id):
self._host = host
self._port = port

View File

@@ -1,7 +1,6 @@
import json
import cartodb_services
from interfaces import ConfigStorageInterface
from null_config import NullConfigStorage
class InDbServerConfigStorage(ConfigStorageInterface):
@@ -13,38 +12,3 @@ class InDbServerConfigStorage(ConfigStorageInterface):
return json.loads(json_output)
else:
return None
# TODO move out of this file. In general this is config but either user or org config
class RedisConfigStorage(ConfigStorageInterface):
def __init__(self, connection, config_key):
self._connection = connection
self._config_key = config_key
self._data = None
def get(self, key):
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()