diff --git a/gdeimporter/configuration.py b/gdeimporter/configuration.py index 2798fe15f5d9f11b19e6c2c2a1b5a0e696298494..9652656755e744c1cb2b76f4b458380e26f424bf 100644 --- a/gdeimporter/configuration.py +++ b/gdeimporter/configuration.py @@ -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 + config, + "database_built_up", + "test_db_built_up.env", + "GDEIMPORTER", + 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 + config, + "database_gde_tiles", + "test_db_gde_tiles.env", + "GDEIMPORTER", + force_config_over_hierarchies, ) self.data_units_surface_threshold = ConfigurationMethods.assign_float_parameter( config, "data_units_surface_threshold", True, -1e-15, 100.0 diff --git a/gdeimporter/tools/configuration_methods.py b/gdeimporter/tools/configuration_methods.py index 3e87e00a73b3875b886f64035ad829d25ea63d03..32b9d8c006a3606e5513b1bd0c9d62599f98d4e9 100644 --- a/gdeimporter/tools/configuration_methods.py +++ b/gdeimporter/tools/configuration_methods.py @@ -319,7 +319,7 @@ class ConfigurationMethods: @staticmethod 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 + pipeline. 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 ( + force_config_over_hierarchies + ): # 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 load_dotenv(env_filename) 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