diff --git a/server/extension/sql/20_geocode_street.sql b/server/extension/sql/20_geocode_street.sql index e65e8b5..44654a5 100644 --- a/server/extension/sql/20_geocode_street.sql +++ b/server/extension/sql/20_geocode_street.sql @@ -144,30 +144,25 @@ RETURNS Geometry AS $$ from cartodb_services.metrics import QuotaService from cartodb_services.tools import Logger from cartodb_services.refactor.storage.server_config import InDbServerConfigStorage - from cartodb_services.refactor.storage.redis_config import RedisUserConfigStorageBuilder, RedisOrgConfigStorageBuilder 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 + from cartodb_services.refactor.storage.redis_connection_config import RedisMetricsConnectionConfigBuilder from cartodb_services.refactor.storage.redis_connection import RedisConnectionBuilder from cartodb_services.refactor.service.mapzen_geocoder_config import MapzenGeocoderConfigBuilder from cartodb_services.refactor.core.environment import Environment + from cartodb_services.refactor.backend.user_config import UserConfigBackendFactory + from cartodb_services.refactor.backend.org_config import OrgConfigBackendFactory server_config_storage = InDbServerConfigStorage() logger_config = LoggerConfigBuilder(server_config_storage).get() logger = Logger(logger_config) - # TODO encapsulate construction of user_config_storage and org_config_storage environment = Environment(server_config_storage).get() - if environment == 'onpremise': - user_config_storage = org_config_storage = server_config_storage - else: - redis_metadata_connection_config = RedisMetadataConnectionConfigBuilder(server_config_storage).get() - redis_metadata_connection = RedisConnectionBuilder(redis_metadata_connection_config).get() - user_config_storage = RedisUserConfigStorageBuilder(redis_metadata_connection, username).get() - org_config_storage = RedisOrgConfigStorageBuilder(redis_metadata_connection, orgname).get() + user_config_backend = UserConfigBackendFactory(username, environment, server_config_storage).get() + org_config_backend = OrgConfigBackendFactory(orgname, environment, server_config_storage).get() - mapzen_geocoder_config = MapzenGeocoderConfigBuilder(server_config_storage, user_config_storage, org_config_storage, username, orgname).get() + mapzen_geocoder_config = MapzenGeocoderConfigBuilder(server_config_storage, user_config_backend, org_config_backend, username, orgname).get() # TODO encapsulate the connection creation if environment == 'onpremise': diff --git a/server/lib/python/cartodb_services/cartodb_services/refactor/backend/__init__.py b/server/lib/python/cartodb_services/cartodb_services/refactor/backend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/server/lib/python/cartodb_services/cartodb_services/refactor/backend/org_config.py b/server/lib/python/cartodb_services/cartodb_services/refactor/backend/org_config.py new file mode 100644 index 0000000..2aa8f3d --- /dev/null +++ b/server/lib/python/cartodb_services/cartodb_services/refactor/backend/org_config.py @@ -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 diff --git a/server/lib/python/cartodb_services/cartodb_services/refactor/backend/user_config.py b/server/lib/python/cartodb_services/cartodb_services/refactor/backend/user_config.py new file mode 100644 index 0000000..19ffbaf --- /dev/null +++ b/server/lib/python/cartodb_services/cartodb_services/refactor/backend/user_config.py @@ -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 diff --git a/server/lib/python/cartodb_services/cartodb_services/refactor/storage/redis_config.py b/server/lib/python/cartodb_services/cartodb_services/refactor/storage/redis_config.py index 35d0645..f01d492 100644 --- a/server/lib/python/cartodb_services/cartodb_services/refactor/storage/redis_config.py +++ b/server/lib/python/cartodb_services/cartodb_services/refactor/storage/redis_config.py @@ -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