diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2022-01-06 13:18:44 -0500 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2022-01-07 09:46:53 -0500 |
commit | e241cf33a14ecd4e848a5fd857c5d3d7d07fbd71 (patch) | |
tree | ff102e0d8b33c06652f414ead7ed8a70113e4bb6 | |
parent | f5e1298162a9393ea2d9f5c4df40dfece50f5f88 (diff) | |
download | sos-e241cf33a14ecd4e848a5fd857c5d3d7d07fbd71.tar.gz |
[cleaner] Improve parser-specific file skipping
This commit improves our handling of skipping files on a per-parser
basis, by first filtering the list of parsers that `obfuscate_line()`
will iterate over by the parser's `skip_file` class attr, rather than
relying on higher-level checks.
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r-- | sos/cleaner/__init__.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/sos/cleaner/__init__.py b/sos/cleaner/__init__.py index 3f530d44..5686e213 100644 --- a/sos/cleaner/__init__.py +++ b/sos/cleaner/__init__.py @@ -12,6 +12,7 @@ import hashlib import json import logging import os +import re import shutil import tempfile @@ -640,10 +641,16 @@ third party. self.log_debug("Obfuscating %s" % short_name or filename, caller=arc_name) tfile = tempfile.NamedTemporaryFile(mode='w', dir=self.tmpdir) + _parsers = [ + _p for _p in self.parsers if not + any([ + re.match(p, short_name) for p in _p.skip_files + ]) + ] with open(filename, 'r') as fname: for line in fname: try: - line, count = self.obfuscate_line(line) + line, count = self.obfuscate_line(line, _parsers) subs += count tfile.write(line) except Exception as err: @@ -713,7 +720,7 @@ third party. pass return string_data - def obfuscate_line(self, line): + def obfuscate_line(self, line, parsers=None): """Run a line through each of the obfuscation parsers, keeping a cumulative total of substitutions done on that particular line. @@ -721,6 +728,8 @@ third party. :param line str: The raw line as read from the file being processed + :param parsers: A list of parser objects to obfuscate + with. If None, use all. Returns the fully obfuscated line and the number of substitutions made """ @@ -729,7 +738,9 @@ third party. count = 0 if not line.strip(): return line, count - for parser in self.parsers: + if parsers is None: + parsers = self.parsers + for parser in parsers: try: line, _count = parser.parse_line(line) count += _count |