Add ServerEnvironment and ServerEnvironmentBuilder
This commit is contained in:
parent
9e98e0794d
commit
1aec541906
@ -149,7 +149,7 @@ RETURNS Geometry AS $$
|
||||
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.core.environment import ServerEnvironmentBuilder
|
||||
from cartodb_services.refactor.backend.user_config import UserConfigBackendFactory
|
||||
from cartodb_services.refactor.backend.org_config import OrgConfigBackendFactory
|
||||
|
||||
@ -158,14 +158,14 @@ RETURNS Geometry AS $$
|
||||
logger_config = LoggerConfigBuilder(server_config_storage).get()
|
||||
logger = Logger(logger_config)
|
||||
|
||||
environment = Environment(server_config_storage).get()
|
||||
environment = ServerEnvironmentBuilder(server_config_storage).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_backend, org_config_backend, username, orgname).get()
|
||||
|
||||
# TODO encapsulate the connection creation
|
||||
if environment == 'onpremise':
|
||||
if environment.is_onpremise:
|
||||
redis_metrics_connection = RedisConnectionMock()
|
||||
else:
|
||||
redis_metrics_connection_config = RedisMetricsConnectionConfigBuilder(server_config_storage).get()
|
||||
|
@ -15,8 +15,7 @@ class OrgConfigBackendFactory(object):
|
||||
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':
|
||||
if self._environment.is_onpremise:
|
||||
org_config_backend = self._server_config_storage
|
||||
else:
|
||||
redis_metadata_connection_config = RedisMetadataConnectionConfigBuilder(self._server_config_storage).get()
|
||||
|
@ -15,8 +15,7 @@ class UserConfigBackendFactory(object):
|
||||
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':
|
||||
if self._environment.is_onpremise:
|
||||
user_config_backend = self._server_config_storage
|
||||
else:
|
||||
redis_metadata_connection_config = RedisMetadataConnectionConfigBuilder(self._server_config_storage).get()
|
||||
|
@ -1,4 +1,33 @@
|
||||
class Environment:
|
||||
class ServerEnvironment(object):
|
||||
|
||||
DEVELOPMENT = 'development'
|
||||
STAGING = 'staging'
|
||||
PRODUCTION = 'production'
|
||||
ONPREMISE = 'onpremise'
|
||||
|
||||
VALID_ENVIRONMENTS = [
|
||||
DEVELOPMENT,
|
||||
STAGING,
|
||||
PRODUCTION,
|
||||
ONPREMISE
|
||||
]
|
||||
|
||||
def __init__(self, environment_str):
|
||||
assert environment_str in self.VALID_ENVIRONMENTS
|
||||
self._environment_str = environment_str
|
||||
|
||||
def __str__(self):
|
||||
return self._environment_str
|
||||
|
||||
@property
|
||||
def is_onpremise(self):
|
||||
return self._environment_str == self.ONPREMISE
|
||||
|
||||
|
||||
class ServerEnvironmentBuilder(object):
|
||||
|
||||
DEFAULT_ENVIRONMENT = ServerEnvironment.DEVELOPMENT
|
||||
|
||||
def __init__(self, server_config_storage):
|
||||
self._server_config_storage = server_config_storage
|
||||
|
||||
@ -6,8 +35,8 @@ class Environment:
|
||||
server_config = self._server_config_storage.get('server_conf')
|
||||
|
||||
if not server_config or 'environment' not in server_config:
|
||||
environment = 'development'
|
||||
environment_str = self.DEFAULT_ENVIRONMENT
|
||||
else:
|
||||
environment = server_config['environment']
|
||||
environment_str = server_config['environment']
|
||||
|
||||
return environment
|
||||
return ServerEnvironment(environment_str)
|
||||
|
Loading…
Reference in New Issue
Block a user