diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2022-02-07 10:23:49 -0500 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2022-02-07 14:23:15 -0500 |
commit | 0eea6b5b713fd4a9edfebfc76094f96040028866 (patch) | |
tree | 86b05d09032000494ca3ad61548010ca40250b54 | |
parent | 21fc376d97a5f74743e2b7cf7069349e874b979e (diff) | |
download | sos-0eea6b5b713fd4a9edfebfc76094f96040028866.tar.gz |
[hostname] Reduce false positive matches
This commit aims to reduce false-positive matches by the hostname
parser/map. Do this by first removing a too-broad substring check that
is better covered by a simpler check in the `_domains` internal dict,
made possible by the previous change which explicitly checks without the
tld as part of the domain string.
Second, improve the set of extensions to strip from potential matches
that would otherwise be regarded as TLDs, but are in fact not TLDs.
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r-- | sos/cleaner/mappings/hostname_map.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/sos/cleaner/mappings/hostname_map.py b/sos/cleaner/mappings/hostname_map.py index 7a7cf6b8..4b66defb 100644 --- a/sos/cleaner/mappings/hostname_map.py +++ b/sos/cleaner/mappings/hostname_map.py @@ -40,6 +40,9 @@ class SoSHostnameMap(SoSMap): 'api' ] + strip_exts = ('.yaml', '.yml', '.crt', '.key', '.pem', '.log', '.repo', + '.rules') + host_count = 0 domain_count = 0 _domains = {} @@ -105,18 +108,16 @@ class SoSHostnameMap(SoSMap): """Check if a potential domain is in one of the domains we've loaded and should be obfuscated """ + if domain in self._domains: + return True host = domain.split('.') no_tld = '.'.join(domain.split('.')[0:-1]) if len(host) == 1: # don't block on host's shortname - return host[0] in self.hosts.keys() + return host[0] in self.hosts elif any([no_tld.endswith(_d) for _d in self._domains]): return True - else: - domain = host[0:-1] - for known_domain in self._domains: - if known_domain in domain: - return True + return False def get(self, item): @@ -136,7 +137,7 @@ class SoSHostnameMap(SoSMap): item = item[0:-1] if not self.domain_name_in_loaded_domains(item.lower()): return item - if item.endswith(('.yaml', '.yml', '.crt', '.key', '.pem', '.log')): + if item.endswith(self.strip_exts): ext = '.' + item.split('.')[-1] item = item.replace(ext, '') suffix += ext |