diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2020-06-02 13:49:42 -0400 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2020-06-17 12:11:29 -0400 |
commit | 9cc01d6d99491d626230e9526f51b22a16610528 (patch) | |
tree | 3423863139709db871c89332101c1769e797b094 | |
parent | f3666ad3c41d3a17595eef9f8ca6fd68ff078dbe (diff) | |
download | sos-9cc01d6d99491d626230e9526f51b22a16610528.tar.gz |
[cleaner] Remove comment filtering, improve obfuscation logging
First, stop filtering out comments and process them the same as any
other line.
Second, improve the logging made for obfuscating files by including the
archive name and the relative path, rather than the absolute path within
the tmpdir we use. Note that this also changed the format of files to
skip to the relative path within the archive.
-rw-r--r-- | sos/cleaner/__init__.py | 12 | ||||
-rw-r--r-- | sos/cleaner/obfuscation_archive.py | 28 |
2 files changed, 21 insertions, 19 deletions
diff --git a/sos/cleaner/__init__.py b/sos/cleaner/__init__.py index 8c07a3ea..4a4e5959 100644 --- a/sos/cleaner/__init__.py +++ b/sos/cleaner/__init__.py @@ -445,11 +445,12 @@ third party. file_list = archive.get_file_list() for fname in file_list: - short_name = fname.split(archive.archive_name)[1] + short_name = fname.split(archive.archive_name)[1].lstrip('/') if archive.should_skip_file(short_name): continue try: - count = self.obfuscate_file(fname, short_name) + count = self.obfuscate_file(fname, short_name, + archive.archive_name) if count: archive.update_sub_count(short_name, count) except Exception as err: @@ -522,12 +523,13 @@ third party. if not filename: # the requested file doesn't exist in the archive return - self.log_debug("Obfuscating %s" % filename) + self.log_debug("Obfuscating %s" % short_name or filename, + caller=arc_name) subs = 0 tfile = tempfile.NamedTemporaryFile(mode='w', dir=self.tmpdir) with open(filename, 'r') as fname: for line in fname: - if not line.strip() or line.startswith('#'): + if not line.strip(): continue try: line, count = self.obfuscate_line(line, short_name) @@ -535,7 +537,7 @@ third party. tfile.write(line) except Exception as err: self.log_debug("Unable to obfuscate %s: %s" - % (filename, err)) + % (short_name, err), caller=arc_name) tfile.seek(0) if subs: shutil.copy(tfile.name, filename) diff --git a/sos/cleaner/obfuscation_archive.py b/sos/cleaner/obfuscation_archive.py index 848b0133..283bee50 100644 --- a/sos/cleaner/obfuscation_archive.py +++ b/sos/cleaner/obfuscation_archive.py @@ -58,20 +58,20 @@ class SoSObfuscationArchive(): Returns: list of files and file regexes """ return [ - '/installed-debs', - '/installed-rpms', - '/sos_commands/dpkg', - '/sos_commands/python/pip_list', - '/sos_commands/rpm', - '/sos_commands/yum/.*list.*', - '/sos_commands/snappy/snap_list_--all', - '/sos_commands/snappy/snap_--version', - '/sos_commands/vulkan/vulkaninfo', - '/sys/firmware', - '/sys/fs', - '/sys/kernel/debug', - '/sys/module', - '/var/log/.*dnf.*', + 'installed-debs', + 'installed-rpms', + 'sos_commands/dpkg', + 'sos_commands/python/pip_list', + 'sos_commands/rpm', + 'sos_commands/yum/.*list.*', + 'sos_commands/snappy/snap_list_--all', + 'sos_commands/snappy/snap_--version', + 'sos_commands/vulkan/vulkaninfo', + 'sys/firmware', + 'sys/fs', + 'sys/kernel/debug', + 'sys/module', + 'var/log/.*dnf.*', '.*.tar.*', # TODO: support archive unpacking '.*.gz' ] |