From 384b80c2a248f05d7224484b6af3d35bfaf75d5f Mon Sep 17 00:00:00 2001 From: SimonSAMPERE <41120579+SimonSAMPERE@users.noreply.github.com> Date: Wed, 28 Jun 2023 17:55:29 +0200 Subject: [PATCH] #444 --- _user/db_connections.json | 24 +++--------------------- modules/layer/database.py | 31 +++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/_user/db_connections.json b/_user/db_connections.json index 09774a16..27d4aa43 100644 --- a/_user/db_connections.json +++ b/_user/db_connections.json @@ -1,22 +1,4 @@ { - "Oracle" : [ - { - "connection_name" : "", - "host" : "", - "port" : "", - "database" : "", - "username" : "", - "password" : "" - } - ], - "PostgreSQL" : [ - { - "connection_name" : "", - "host" : "", - "port" : "", - "database" : "", - "username" : "", - "password" : "" - } - ] -} + "Oracle": [], + "PostgreSQL": [] +} \ No newline at end of file diff --git a/modules/layer/database.py b/modules/layer/database.py index 3f010e2d..c5d6d40d 100644 --- a/modules/layer/database.py +++ b/modules/layer/database.py @@ -597,26 +597,25 @@ def build_connection_dict(self, dbms: str, skip_invalid: bool = True): user_saved = qsettings.value(dbms_prefix + connection_name + "/saveUsername") connection_service = qsettings.value(dbms_prefix + connection_name + "/service") - # For "traditionnaly" registered connections - if password_saved == "true" and user_saved == "true": - connection_dict = self.qsettings_content_parser( - dbms=dbms, connection_name=connection_name + # For connections configured using config file and service + if connection_service != "" and self.pg_configfile_path and dbms == "PostgreSQL": + connection_dict = self.config_file_parser( + self.pg_configfile_path, connection_service, connection_name ) if connection_dict[0]: connection_dict = connection_dict[1] else: logger.warning(connection_dict[1]) - - # For connections configured using config file and service - elif connection_service != "" and self.pg_configfile_path: - connection_dict = self.config_file_parser( - self.pg_configfile_path, connection_service, connection_name + continue + # For "traditionnaly" registered connections + elif password_saved == "true" and user_saved == "true": + connection_dict = self.qsettings_content_parser( + dbms=dbms, connection_name=connection_name ) if connection_dict[0]: connection_dict = connection_dict[1] else: logger.warning(connection_dict[1]) - continue else: continue @@ -670,6 +669,18 @@ def build_connection_dict(self, dbms: str, skip_invalid: bool = True): "password": conn_dict.get("password"), "connection": connection_name, } + elif all( + conn_dict.get(key, "") == "" + for key in [ + "database", + "host", + "port", + "username", + "password", + "connection_name", + ] + ): + continue else: logger.warning( "Invalid {} connection loaded from db_connections.json file : {}".format(