Skip to content

Commit

Permalink
[plugins] py311 fix for re.M
Browse files Browse the repository at this point in the history
Add a common regex for re.MULTILINE so that doesn't need to be defined
and remove the definitions where `(?m)` is being defined

Closes: #3301
Signed-off-by: Arif Ali <[email protected]>
  • Loading branch information
arif-ali authored and TurboTurtle committed Jul 19, 2023
1 parent 5bcdb79 commit d2a1442
Show file tree
Hide file tree
Showing 28 changed files with 48 additions and 46 deletions.
5 changes: 3 additions & 2 deletions sos/report/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,12 +1274,13 @@ def do_file_sub(self, srcpath, regexp, subst):
"""
try:
path = self._get_dest_for_srcpath(srcpath)
common_flags = re.IGNORECASE | re.MULTILINE
if hasattr(regexp, "pattern"):
pattern = regexp.pattern
flags = regexp.flags | re.IGNORECASE
flags = regexp.flags | common_flags
else:
pattern = regexp
flags = re.IGNORECASE
flags = common_flags
self._log_debug("substituting scrpath '%s'" % srcpath)
self._log_debug("substituting '%s' for '%s' in '%s'"
% (subst, pattern, path))
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/collectd.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def postproc(self):
"Password", "User",
"[<]*URL", "Address"
]
regexp = r"((?m)^[#]*\s*(%s)\s* \s*)(.*)" % "|".join(protect_keys)
regexp = r"(^[#]*\s*(%s)\s* \s*)(.*)" % "|".join(protect_keys)
self.do_path_regex_sub(
"/etc/collectd.d/*.conf",
regexp, r'\1"*********"'
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/grafana.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ def postproc(self):
"admin_password", "secret_key"
]

regexp = r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys)
regexp = r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys)
self.do_path_regex_sub("/etc/grafana/grafana.ini",
regexp, r"\1*********")
2 changes: 1 addition & 1 deletion sos/report/plugins/juju.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def postproc(self):
]

# Redact simple yaml style "key: value".
keys_regex = r"((?m)^\s*(%s)\s*:\s*)(.*)" % "|".join(protect_keys)
keys_regex = r"(^\s*(%s)\s*:\s*)(.*)" % "|".join(protect_keys)
sub_regex = r"\1*********"
self.do_path_regex_sub(agents_path, keys_regex, sub_regex)
# Redact certificates
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/openssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def postproc(self):
"challengePassword"
]

regexp = r"(?m)^(\s*#?\s*(%s).*=)(.*)" % "|".join(protect_keys)
regexp = r"^(\s*#?\s*(%s).*=)(.*)" % "|".join(protect_keys)

self.do_file_sub(
'/etc/ssl/openssl.cnf',
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/openstack_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def postproc(self):
"/etc/openstack_deploy/user_secrets.yml",
"/etc/rpc_deploy/user_secrets.yml"
]
regexp = r"(?m)^\s*#*([\w_]*:\s*).*"
regexp = r"^\s*#*([\w_]*:\s*).*"
for secrets_file in secrets_files:
self.do_path_regex_sub(
secrets_file,
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/openstack_aodh.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ def postproc(self):
connection_keys = ["connection", "backend_url", "transport_url"]

self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"\1*********"
)
self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
r"(^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
"|".join(connection_keys),
r"\1*********\6"
)
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/openstack_barbican.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ def postproc(self):
]
self.do_file_sub(
"/etc/barbican/barbican.conf",
r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"\1********"
)

connection_keys = ["transport_url", "sql_connection"]

self.do_path_regex_sub(
"/etc/barbican/barbican.conf",
r"((?m)^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
r"(^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
"|".join(connection_keys),
r"\1*********\6")

Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/openstack_ceilometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ def postproc(self):
connection_keys = ["connection", "backend_url", "transport_url"]

self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"\1*********"
)
self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
r"(^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
"|".join(connection_keys),
r"\1*********\6"
)
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/openstack_cinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ def postproc(self):
connection_keys = ["connection"]

self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"\1*********"
)
self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
r"(^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
"|".join(connection_keys),
r"\1*********\6"
)
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/openstack_designate.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def postproc(self):
"ssl_key_password", "ssl_client_key_password",
"memcache_secret_key"
]
regexp = r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys)
regexp = r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys)

self.do_path_regex_sub("/etc/designate/*", regexp, r"\1*********")
self.do_path_regex_sub(
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/openstack_glance.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ def postproc(self):
connection_keys = ["connection"]

self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"\1*********"
)
self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
r"(^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
"|".join(connection_keys),
r"\1*********\6"
)
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/openstack_heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ def postproc(self):
connection_keys = ["connection"]

self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"\1*********"
)
self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
r"(^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
"|".join(connection_keys),
r"\1*********\6"
)
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/openstack_horizon.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def postproc(self):
"SECRET_KEY", "EMAIL_HOST_PASSWORD"
]

regexp = r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys)
regexp = r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys)
for regpath in [r"/etc/openstack-dashboard/.*\.json",
"/etc/openstack-dashboard/local_settings$"]:
self.do_path_regex_sub(regpath, regexp, r"\1*********")
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/openstack_instack.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ def postproc(self):
"undercloud_swift_password",
"undercloud_tuskar_password",
]
regexp = r"((?m)(%s)=)(.*)" % "|".join(protected_keys)
regexp = r"((%s)=)(.*)" % "|".join(protected_keys)
self.do_file_sub("/home/stack/.instack/install-undercloud.log",
regexp, r"\1*********")
self.do_file_sub(UNDERCLOUD_CONF_PATH, regexp, r"\1*********")

protected_json_keys = ["pm_password", "ssh-key", "password"]
json_regexp = r'((?m)"(%s)": )(".*?")' % "|".join(protected_json_keys)
json_regexp = r'("(%s)": )(".*?")' % "|".join(protected_json_keys)
self.do_file_sub("/home/stack/instackenv.json", json_regexp,
r"\1*********")
self.do_file_sub('/home/stack/.tripleo/history',
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/openstack_ironic.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ def postproc(self):
connection_keys = ["connection", "sql_connection"]

self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"\1*********"
)
self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
r"(^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
"|".join(connection_keys),
r"\1*********\6"
)
Expand Down
6 changes: 3 additions & 3 deletions sos/report/plugins/openstack_keystone.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ def postproc(self):
connection_keys = ["connection"]

self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"\1*********"
)
self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
r"(^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
"|".join(connection_keys),
r"\1*********\6"
)

# obfuscate LDAP plaintext passwords in domain config dir
self.do_path_regex_sub(
self.domain_config_dir,
r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"\1********"
)

Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/openstack_manila.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ def postproc(self):
connection_keys = ["connection", "sql_connection"]

self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"\1*********"
)
self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
r"(^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
"|".join(connection_keys),
r"\1*********\6"
)
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/openstack_neutron.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ def postproc(self):
connection_keys = ["connection"]

self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"\1*********"
)
self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
r"(^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
"|".join(connection_keys),
r"\1*********\6"
)
Expand Down
5 changes: 3 additions & 2 deletions sos/report/plugins/openstack_nova.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def setup(self):
self.add_copy_spec(self.path_join(novadir, novalog))
self.add_copy_spec([
"/var/log/{}*/nova*.log".format(self.apachepkg),
"/var/log/{}*/placement*.log".format(self.apachepkg),
])

pp = ['', '_libvirt', '_metadata', '_placement']
Expand Down Expand Up @@ -154,11 +155,11 @@ def postproc(self):
connection_keys = ["connection", "sql_connection"]

self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"\1*********"
)
self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
r"(^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
"|".join(connection_keys),
r"\1*********\6"
)
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/openstack_octavia.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def postproc(self):
"connection", "transport_url", "server_certs_key_passphrase",
"memcache_secret_key"
]
regexp = r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys)
regexp = r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys)

self.do_path_regex_sub("/etc/octavia/*", regexp, r"\1*********")
self.do_path_regex_sub(
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/openstack_placement.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ def postproc(self):
connection_keys = ["database_connection", "slave_connection"]

self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"\1*********"
)
self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
r"(^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
"|".join(connection_keys),
r"\1*********\6"
)
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/openstack_sahara.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ def postproc(self):
connection_keys = ["connection"]

self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"\1*********"
)
self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
r"(^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
"|".join(connection_keys),
r"\1*********\6"
)
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/openstack_swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ def postproc(self):
connection_keys = ["connection", "sql_connection"]

self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"\1*********"
)
self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
r"(^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
"|".join(connection_keys),
r"\1*********\6"
)
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/openstack_trove.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ def postproc(self):
connection_keys = ["connection"]

self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys),
r"\1*********"
)
self.apply_regex_sub(
r"((?m)^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
r"(^\s*(%s)\s*=\s*(.*)://(\w*):)(.*)(@(.*))" %
"|".join(connection_keys),
r"\1*********\6"
)
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/ovirt.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def postproc(self):
"pool.default.ssl.truststore.password",
"config.datasource.dbpassword"
]
regexp = r"((?m)^\s*#*(%s)\s*=\s*)(.*)" % "|".join(protect_keys)
regexp = r"(^\s*#*(%s)\s*=\s*)(.*)" % "|".join(protect_keys)

self.do_path_regex_sub(r"/etc/ovirt-engine/aaa/.*\.properties", regexp,
r"\1*********")
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/salt.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setup(self):
self.add_forbidden_path("/etc/salt/pki/*/*.pem")

def postproc(self):
regexp = r'((?m)^\s+.*(pass|secret|(?<![A-z])key(?![A-z])).*:\ ).+$'
regexp = r'(^\s+.*(pass|secret|(?<![A-z])key(?![A-z])).*:\ ).+$'
subst = r'\1******'
self.do_path_regex_sub("/etc/salt/*", regexp, subst)

Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/saltmaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def setup(self):
self.add_cmd_output("salt-key --list all")

def postproc(self):
regexp = r'((?m)^\s+.*(pass|secret|(?<![A-z])key(?![A-z])).*:\ ).+$'
regexp = r'(^\s+.*(pass|secret|(?<![A-z])key(?![A-z])).*:\ ).+$'
subst = r'\1******'
self.do_path_regex_sub("/etc/salt/*", regexp, subst)

Expand Down

0 comments on commit d2a1442

Please sign in to comment.