Commit 92ad14e9 authored by Cecilia Nievas's avatar Cecilia Nievas
Browse files

Made prefix of environment database variables a variable

parent 0dc2ab9f
Pipeline #42286 passed with stage
in 2 minutes and 27 seconds
......@@ -177,10 +177,18 @@ class Configuration:
config, "number_cores"
self.database_built_up = ConfigurationMethods.retrieve_database_credentials(
config, "database_built_up", "test_db_built_up.env", force_config_over_hierarchies
self.database_gde_tiles = ConfigurationMethods.retrieve_database_credentials(
config, "database_gde_tiles", "test_db_gde_tiles.env", force_config_over_hierarchies
self.data_units_surface_threshold = ConfigurationMethods.assign_float_parameter(
config, "data_units_surface_threshold", True, -1e-15, 100.0
......@@ -319,7 +319,7 @@ class ConfigurationMethods:
def retrieve_database_credentials(
config, input_parameter, env_filename, force_config_over_hierarchies
config, input_parameter, env_filename, ci_variable_name, force_config_over_hierarchies
"""This function retrieves the credentials needed to (later) connect to a specific SQL
database. If force_config_over_hierarchies is False, it does so hieararchically, by
......@@ -338,6 +338,9 @@ class ConfigurationMethods:
Name of the desired parameter, to be searched for as a primary key of config.
env_filename (str):
Name of a local .env file that will be run to load environment variables.
ci_variable_name (str):
Prefix of the name of the variables associated with the test databases in the CI
force_config_over_hierarchies (bool):
If True, the contents of the .yml configuration file specified in filepath will
take precedence over any other hierarchy (e.g. preference of environment
......@@ -366,24 +369,26 @@ class ConfigurationMethods:
if "port" in config:
db_config["port"] = int(db_config["port"])
if "GDEIMPORTER_DB_HOST" in os.environ and not (force_config_over_hierarchies):
if ("%s_DB_HOST" % (ci_variable_name)) in os.environ and not (
# Running the CI pipeline
db_config = {
"host": os.environ.get("GDEIMPORTER_DB_HOST"),
"dbname": os.environ.get("GDEIMPORTER_DB"),
"username": os.environ.get("GDEIMPORTER_USER"),
"password": os.environ.get("GDEIMPORTER_PASSWORD"),
"sourceid": os.environ.get("GDEIMPORTER_SOURCEID"),
"host": os.environ.get("%s_DB_HOST" % (ci_variable_name)),
"dbname": os.environ.get("%s_DB" % (ci_variable_name)),
"username": os.environ.get("%s_USER" % (ci_variable_name)),
"password": os.environ.get("%s_PASSWORD" % (ci_variable_name)),
"sourceid": os.environ.get("%s_SOURCEID" % (ci_variable_name)),
elif os.path.isfile(env_filename) and not (force_config_over_hierarchies):
# Testing locally with a test database
db_config = {
"host": os.environ.get("GDEIMPORTER_LOCAL_DB_HOST"),
"dbname": os.environ.get("GDEIMPORTER_LOCAL_DB"),
"username": os.environ.get("GDEIMPORTER_LOCAL_USER"),
"password": os.environ.get("GDEIMPORTER_LOCAL_PASSWORD"),
"sourceid": os.environ.get("GDEIMPORTER_LOCAL_SOURCEID"),
"host": os.environ.get("%s_LOCAL_DB_HOST" % (ci_variable_name)),
"dbname": os.environ.get("%s_LOCAL_DB" % (ci_variable_name)),
"username": os.environ.get("%s_LOCAL_USER" % (ci_variable_name)),
"password": os.environ.get("%s_LOCAL_PASSWORD" % (ci_variable_name)),
"sourceid": os.environ.get("%s_LOCAL_SOURCEID" % (ci_variable_name)),
return db_config
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment