Skip to content

Commit

Permalink
Merge f7ebf35 into 970898e
Browse files Browse the repository at this point in the history
  • Loading branch information
chicco785 authored Dec 1, 2020
2 parents 970898e + f7ebf35 commit 484a44e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/translators/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,21 @@ def lookup_backend(fiware_service: str) -> MaybeString:
config = cfg_reader.from_env_file(QL_CONFIG_ENV_VAR, defaults={})
tenant_backend = maybe_string_match(config, 'tenants', fiware_service,
'backend')
default_backend = maybe_string_match(config, 'default-backend')

env_backend = env_reader.read(StrVar(QL_DEFAULT_DB_ENV_VAR, CRATE_BACKEND))
return tenant_backend or default_backend()

return tenant_backend or env_backend or default_backend

def default_backend() -> MaybeString:
cfg_reader = YamlReader(log=log().debug)
env_reader = EnvReader(log=log().debug)

config = cfg_reader.from_env_file(QL_CONFIG_ENV_VAR, defaults={})

config_backend = maybe_string_match(config, 'default-backend')

env_backend = env_reader.read(StrVar(QL_DEFAULT_DB_ENV_VAR, None))

return env_backend or config_backend or CRATE_BACKEND


def translator_for(fiware_service: str):
Expand Down
8 changes: 8 additions & 0 deletions src/translators/tests/ql-config-timescale-default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tenants:
t1:
backend: Timescale
t2:
backend: Crate
T3:
backend: Timescale
default-backend: Timescale
10 changes: 10 additions & 0 deletions src/translators/tests/test_translator_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,13 @@ def test_os_env():
os.environ['QL_DEFAULT_DB'] = 'crate'
with translator_for(None) as t:
assert isinstance(t, CrateTranslator)
os.environ['QL_DEFAULT_DB'] = ''


def test_fix_404():
with translator_for(None) as t:
assert isinstance(t, CrateTranslator)
os.environ['QL_CONFIG'] = 'src/translators/tests/ql-config-timescale-default.yml'
with translator_for(None) as t:
assert isinstance(t, PostgresTranslator)

0 comments on commit 484a44e

Please sign in to comment.