Yedidyah Bar David has uploaded a new change for review. Change subject: packaging: setup: Use ovirt engine configfile ......................................................................
packaging: setup: Use ovirt engine configfile Use configfile from ovirt-engine-lib and (a copy of) escape from ovirt-engine-setup to parse db credential files. Bug-Url: https://bugzilla.redhat.com/1070339 Related-To: https://bugzilla.redhat.com/1065781 Change-Id: I44ae8c9c7cfe10977b05ee8eb7fe9a4ba00becdf Signed-off-by: Yedidyah Bar David <d...@redhat.com> --- M packaging/common_utils.py M packaging/ovirt-engine-dwh-setup.py 2 files changed, 30 insertions(+), 26 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-dwh refs/changes/52/25252/1 diff --git a/packaging/common_utils.py b/packaging/common_utils.py index 7efb11d..bd08b79 100755 --- a/packaging/common_utils.py +++ b/packaging/common_utils.py @@ -20,6 +20,10 @@ import random import string + +from ovirt_engine import configfile + + #text colors RED = "\033[0;31m" GREEN = "\033[92m" @@ -320,10 +324,13 @@ self.data = [] self.sep = sep - def open(self): + def open(self, useconfigfile=False): fd = file(self.filepath) self.data = fd.readlines() fd.close() + self._useconfigfile = useconfigfile + if self._useconfigfile: + self._configfile = configfile.ConfigFile([self.filepath]) def close(self): fd = file(self.filepath, 'w') @@ -333,11 +340,14 @@ def getParam(self, param): value = None - for line in self.data: - if not re.match("\s*#", line): - found = re.match("\s*%s\s*\%s\s*(.+)$" % (param, self.sep), line) - if found: - value = found.group(1) + if self._useconfigfile: + value = self._configfile.get(param) + else: + for line in self.data: + if not re.match("\s*#", line): + found = re.match("\s*%s\s*\%s\s*(.+)$" % (param, self.sep), line) + if found: + value = found.group(1) return value def editParam(self, param, value): @@ -700,7 +710,7 @@ Use default settings if file is not found. """ file_handler = TextConfigFileHandler(FILE_DB_CONN) - file_handler.open() + file_handler.open(useconfigfile=True) return file_handler.getParam('ENGINE_DB_USER') or DB_ADMIN def getDbHostName(): @@ -709,7 +719,7 @@ Use default settings if file is not found, or '*' was used. """ file_handler = TextConfigFileHandler(FILE_DB_CONN) - file_handler.open() + file_handler.open(useconfigfile=True) return file_handler.getParam('ENGINE_DB_HOST') or DB_HOST def getDbPort(): @@ -717,7 +727,7 @@ Retrieve DB port number from .pgpass file on the system. """ file_handler = TextConfigFileHandler(FILE_DB_CONN) - file_handler.open() + file_handler.open(useconfigfile=True) return file_handler.getParam('ENGINE_DB_PORT') or DB_PORT def getPassFromFile(): @@ -725,7 +735,7 @@ get the DB password ''' file_handler = TextConfigFileHandler(FILE_DB_CONN) - file_handler.open() + file_handler.open(useconfigfile=True) return file_handler.getParam('ENGINE_DB_PASSWORD') def dropDB(db_dict): @@ -1498,16 +1508,23 @@ stdIn=stdIn, ) +def escape(s, chars): + ret = '' + for c in s: + if c in chars: + ret += '\\' + ret += c + return ret def saveConfig(configFile, username, password, dbname, readonly, uid, gid, perms): with open(configFile, 'w') as fdwh: content = ( 'DWH_DB_USER={user}\n' - 'DWH_DB_PASSWORD={password}\n' + 'DWH_DB_PASSWORD="{password}"\n' 'DWH_DB_DATABASE={database}\n' ).format( user=username, - password=password, + password=escape(password,'"\\$'), database=dbname, ) if readonly is not None: diff --git a/packaging/ovirt-engine-dwh-setup.py b/packaging/ovirt-engine-dwh-setup.py index c792b4b..e7b6036 100755 --- a/packaging/ovirt-engine-dwh-setup.py +++ b/packaging/ovirt-engine-dwh-setup.py @@ -264,7 +264,7 @@ if os.path.exists(file): handler = utils.TextConfigFileHandler(file) - handler.open() + handler.open(useconfigfile=True) for k, v in ( ('dbname', 'DWH_DB_DATABASE'), @@ -279,19 +279,6 @@ ): s = handler.getParam(v) if s is not None: - if s[0]=='"' and s[-1]=='"': - s = s[1:-1] - for c in INVALID_PASSWORD_CHARS: - if c in s: - logging.debug( - 'invalid chars: {file}:{param}'.format( - file=file, - param=v, - ) - ) - msg = 'invalid character found in db credentials' - print msg - raise RuntimeError(msg) db_dict[k] = s handler.close() -- To view, visit http://gerrit.ovirt.org/25252 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I44ae8c9c7cfe10977b05ee8eb7fe9a4ba00becdf Gerrit-PatchSet: 1 Gerrit-Project: ovirt-dwh Gerrit-Branch: ovirt-3.3 Gerrit-Owner: Yedidyah Bar David <d...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches