Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dynamic Exposure
Global Dynamic Exposure
gde-importer
Commits
92ad14e9
Commit
92ad14e9
authored
May 02, 2022
by
Cecilia Nievas
Browse files
Made prefix of environment database variables a variable
parent
0dc2ab9f
Changes
2
Hide whitespace changes
Inline
Side-by-side
gdeimporter/configuration.py
View file @
92ad14e9
...
@@ -177,10 +177,18 @@ class Configuration:
...
@@ -177,10 +177,18 @@ class Configuration:
config
,
"number_cores"
config
,
"number_cores"
)
)
self
.
database_built_up
=
ConfigurationMethods
.
retrieve_database_credentials
(
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
(
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
(
self
.
data_units_surface_threshold
=
ConfigurationMethods
.
assign_float_parameter
(
config
,
"data_units_surface_threshold"
,
True
,
-
1e-15
,
100.0
config
,
"data_units_surface_threshold"
,
True
,
-
1e-15
,
100.0
...
...
gdeimporter/tools/configuration_methods.py
View file @
92ad14e9
...
@@ -319,7 +319,7 @@ class ConfigurationMethods:
...
@@ -319,7 +319,7 @@ class ConfigurationMethods:
@
staticmethod
@
staticmethod
def
retrieve_database_credentials
(
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
"""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
database. If force_config_over_hierarchies is False, it does so hieararchically, by
...
@@ -338,6 +338,9 @@ class ConfigurationMethods:
...
@@ -338,6 +338,9 @@ class ConfigurationMethods:
Name of the desired parameter, to be searched for as a primary key of config.
Name of the desired parameter, to be searched for as a primary key of config.
env_filename (str):
env_filename (str):
Name of a local .env file that will be run to load environment variables.
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):
force_config_over_hierarchies (bool):
If True, the contents of the .yml configuration file specified in filepath will
If True, the contents of the .yml configuration file specified in filepath will
take precedence over any other hierarchy (e.g. preference of environment
take precedence over any other hierarchy (e.g. preference of environment
...
@@ -366,24 +369,26 @@ class ConfigurationMethods:
...
@@ -366,24 +369,26 @@ class ConfigurationMethods:
if
"port"
in
config
:
if
"port"
in
config
:
db_config
[
"port"
]
=
int
(
db_config
[
"port"
])
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
# Running the CI pipeline
db_config
=
{
db_config
=
{
"host"
:
os
.
environ
.
get
(
"
GDEIMPORTER_DB_HOST"
),
"host"
:
os
.
environ
.
get
(
"
%s_DB_HOST"
%
(
ci_variable_name
)
),
"dbname"
:
os
.
environ
.
get
(
"
GDEIMPORTER_DB"
),
"dbname"
:
os
.
environ
.
get
(
"
%s_DB"
%
(
ci_variable_name
)
),
"username"
:
os
.
environ
.
get
(
"
GDEIMPORTER_USER"
),
"username"
:
os
.
environ
.
get
(
"
%s_USER"
%
(
ci_variable_name
)
),
"password"
:
os
.
environ
.
get
(
"
GDEIMPORTER_PASSWORD"
),
"password"
:
os
.
environ
.
get
(
"
%s_PASSWORD"
%
(
ci_variable_name
)
),
"sourceid"
:
os
.
environ
.
get
(
"
GDEIMPORTER_SOURCEID"
),
"sourceid"
:
os
.
environ
.
get
(
"
%s_SOURCEID"
%
(
ci_variable_name
)
),
}
}
elif
os
.
path
.
isfile
(
env_filename
)
and
not
(
force_config_over_hierarchies
):
elif
os
.
path
.
isfile
(
env_filename
)
and
not
(
force_config_over_hierarchies
):
# Testing locally with a test database
# Testing locally with a test database
load_dotenv
(
env_filename
)
load_dotenv
(
env_filename
)
db_config
=
{
db_config
=
{
"host"
:
os
.
environ
.
get
(
"
GDEIMPORTER
_LOCAL_DB_HOST"
),
"host"
:
os
.
environ
.
get
(
"
%s
_LOCAL_DB_HOST"
%
(
ci_variable_name
)
),
"dbname"
:
os
.
environ
.
get
(
"
GDEIMPORTER_LOCAL_DB"
),
"dbname"
:
os
.
environ
.
get
(
"
%s_LOCAL_DB"
%
(
ci_variable_name
)
),
"username"
:
os
.
environ
.
get
(
"
GDEIMPORTER
_LOCAL_USER"
),
"username"
:
os
.
environ
.
get
(
"
%s
_LOCAL_USER"
%
(
ci_variable_name
)
),
"password"
:
os
.
environ
.
get
(
"
GDEIMPORTER
_LOCAL_PASSWORD"
),
"password"
:
os
.
environ
.
get
(
"
%s
_LOCAL_PASSWORD"
%
(
ci_variable_name
)
),
"sourceid"
:
os
.
environ
.
get
(
"
GDEIMPORTER
_LOCAL_SOURCEID"
),
"sourceid"
:
os
.
environ
.
get
(
"
%s
_LOCAL_SOURCEID"
%
(
ci_variable_name
)
),
}
}
return
db_config
return
db_config
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment