Alex Lourie has uploaded a new change for review. Change subject: packaging: Updated fetching db params from pgpass ......................................................................
packaging: Updated fetching db params from pgpass Change-Id: Ic28e0d1da86bc1a8c7ba909aad3cd541bab80e36 Bug-Url: https://bugzilla.redhat.com/908129 Signed-off-by: Alex Lourie <[email protected]> --- M src/__main__.py 1 file changed, 18 insertions(+), 2 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-log-collector refs/changes/26/11826/1 diff --git a/src/__main__.py b/src/__main__.py index 6da9167..660a3b1 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -173,14 +173,22 @@ This method will check for /etc/ovirt-engin/.pgpass and set the values for the admin user, admin user pw, pg host, and pg port in the configuration dictionary. + + If values not found, use defaults. ''' + + self['pg_user'] = 'postgres' + self['pg_pass'] = '12345' + self['pg_dbhost'] = 'localhost' + self['pg_dbport'] = '5432' + try: tmp = None tmp = self._get_pg_var('admin') if tmp: self['pg_user'] = tmp tmp = None - tmp = self._get_pg_var('pass') + tmp = self._get_pg_var('pass', self['pg_user']) if tmp: self['pg_pass'] = tmp tmp = None @@ -195,7 +203,7 @@ except Exception, e: logging.debug(str(e)) - def _get_pg_var(self, dbconf_param): + def _get_pg_var(self, dbconf_param, user=None): ''' Provides a mechanism to extract information from .pgpass. ''' @@ -221,6 +229,14 @@ dbcreds = line.split(":", 4) return str(dbcreds[field[dbconf_param]]).strip() + # Fetch the password if needed + if dbconf_param == "pass" and user \ + and not line.startswith("#"): + dbcreds = line.split(":", 4) + if dbcreds[3] == user: + return dbcreds[field[dbconf_param]] + + def load_config_file(self): """Loads the user-supplied config file or the system default. If the user supplies a bad filename we will stop.""" -- To view, visit http://gerrit.ovirt.org/11826 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic28e0d1da86bc1a8c7ba909aad3cd541bab80e36 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-log-collector Gerrit-Branch: master Gerrit-Owner: Alex Lourie <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
