From 8813aabaf635951a805ad53c20eab7be07c79b0d Mon Sep 17 00:00:00 2001 From: Dimitris Papagiannis Date: Wed, 20 Sep 2023 16:30:43 +0200 Subject: [PATCH] Function to censor hostnames --- db.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/db.py b/db.py index 4c27d6e..0d0cd10 100644 --- a/db.py +++ b/db.py @@ -18,6 +18,16 @@ DEFAULT_DATETIME = TZ.localize(datetime(2012, 3, 3, 10, 10, 10, 0)) +def _censor_hostname(hostname: str) -> str: + """Hide part of the hostname for safety reasons""" + var = hostname.split("-") + return ( + f"{var[0]}-{var[1]}-.." + if hostname.startswith("dqm") + else "..".join([var[0], var[-1]]) + ) + + class DQM2MirrorDB: """ DB Schema description. @@ -425,9 +435,7 @@ def format_run_data(self, data): ) = data client = self.get_short_client_name(client) # Hide part of the hostname for safety reasons - var = hostname.split("-") - hostname = "..".join([var[0], var[-1]]) - + hostname = _censor_hostname(hostname) # Timestamp is of type datetime, and is tz-aware, # as it's coming straight from the DB. td = TZ.localize(datetime.now()) - timestamp @@ -486,9 +494,7 @@ def format_table_entry(self, data: dict): _, ) = data client = self.get_short_client_name(client) - # Hide part of the hostname for safety reasons - var = hostname.split("-") - hostname = "..".join([var[0], var[-1]]) + hostname = _censor_hostname(hostname) runkey = runkey[len("runkey=") :] cmssw_path = ""