Skip to content

Commit

Permalink
Merge pull request #542 from opengisch/validity_service
Browse files Browse the repository at this point in the history
Check validity of emitted db connection parameter from layer
  • Loading branch information
signedav committed Sep 10, 2021
2 parents bf9968c + d044c79 commit 3b1329a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
5 changes: 2 additions & 3 deletions QgisModelBaker/gui/panel/dataset_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,10 @@ def set_current_layer(self, layer):
)

if not self.basket_model.schema_baskets_loaded(schema_identificator):
mode, configuration = get_configuration_from_layersource(
valid, mode, configuration = get_configuration_from_layersource(
source_name, source
)

if mode:
if valid and mode:
db_factory = self.db_simple_factory.create_factory(mode)
config_manager = db_factory.get_db_command_config_manager(configuration)
self.basket_model.reload_schema_baskets(
Expand Down
25 changes: 24 additions & 1 deletion QgisModelBaker/utils/db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ def get_authconfig_map(authconfigid):


def get_configuration_from_layersource(layer_source_name, layer_source):
"""
Determines the connection parameters from a layer source.
Returns:
valid (boolean): if the needed database connection parameters are determined
mode (DbIliMode): Kind of database like pg, gpkg or mssql
configuration (Ili2DbCommandConfiguration): config with the determined parameters
"""
mode = ""
valid = False
configuration = Ili2DbCommandConfiguration()
if layer_source_name == "postgres":
mode = DbIliMode.pg
Expand All @@ -60,17 +68,32 @@ def get_configuration_from_layersource(layer_source_name, layer_source):
configuration.dbhost = layer_source.host()
configuration.database = layer_source.database()
configuration.dbschema = layer_source.schema()
valid = bool(
configuration.dbusr()
and configuration.dbpwd()
and configuration.dbhost()
and configuration.database()
and configuration.schema()
)
elif layer_source_name == "ogr":
mode = DbIliMode.gpkg
configuration.dbfile = layer_source.uri().split("|")[0].strip()
valid = bool(configuration.dbfile)
elif layer_source_name == "mssql":
mode = DbIliMode.mssql
configuration.dbhost = layer_source.host()
configuration.dbusr = layer_source.username()
configuration.dbpwd = layer_source.password()
configuration.database = layer_source.database()
configuration.dbschema = layer_source.schema()
return mode, configuration
valid = bool(
configuration.dbusr()
and configuration.dbpwd()
and configuration.dbhost()
and configuration.database()
and configuration.schema()
)
return valid, mode, configuration


def get_db_connector(configuration):
Expand Down

0 comments on commit 3b1329a

Please sign in to comment.