Add ServerEnvironment and ServerEnvironmentBuilder

This commit is contained in:
Rafa de la Torre
2016-10-03 16:21:28 +02:00
parent 9e98e0794d
commit 1aec541906
4 changed files with 38 additions and 11 deletions

View File

@@ -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()

View File

@@ -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()

View File

@@ -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)