From 4f59e3517e4aa7480feb7107850d76a698f58b4c Mon Sep 17 00:00:00 2001 From: Florian Pinault Date: Mon, 30 Sep 2024 13:18:28 +0200 Subject: [PATCH] fix typo (#11) * fix typo --- src/anemoi/utils/{sanetise.py => sanitise.py} | 22 ++--- tests/test_sanetise.py | 82 +++++++++---------- 2 files changed, 52 insertions(+), 52 deletions(-) rename src/anemoi/utils/{sanetise.py => sanitise.py} (86%) diff --git a/src/anemoi/utils/sanetise.py b/src/anemoi/utils/sanitise.py similarity index 86% rename from src/anemoi/utils/sanetise.py rename to src/anemoi/utils/sanitise.py index 81d2575..587134e 100644 --- a/src/anemoi/utils/sanetise.py +++ b/src/anemoi/utils/sanitise.py @@ -20,41 +20,41 @@ RE2 = re.compile(r"\(([^}]*)\)") -def sanetise(obj): - """sanetise an object: +def sanitise(obj): + """sanitise an object: - by replacing all full paths with shortened versions. - by replacing URL passwords with '***'. """ if isinstance(obj, dict): - return {sanetise(k): sanetise(v) for k, v in obj.items()} + return {sanitise(k): sanitise(v) for k, v in obj.items()} if isinstance(obj, list): - return [sanetise(v) for v in obj] + return [sanitise(v) for v in obj] if isinstance(obj, tuple): - return tuple(sanetise(v) for v in obj) + return tuple(sanitise(v) for v in obj) if isinstance(obj, str): - return _sanetise_string(obj) + return _sanitise_string(obj) return obj -def _sanetise_string(obj): +def _sanitise_string(obj): parsed = urlparse(obj, allow_fragments=True) if parsed.scheme: - return _sanetise_url(parsed) + return _sanitise_url(parsed) if obj.startswith("/") or obj.startswith("~"): - return _sanetise_path(obj) + return _sanitise_path(obj) return obj -def _sanetise_url(parsed): +def _sanitise_url(parsed): LIST = [ "pass", @@ -98,7 +98,7 @@ def _sanetise_url(parsed): return urlunparse([scheme, netloc, path, params, query, fragment]) -def _sanetise_path(path): +def _sanitise_path(path): bits = list(reversed(Path(path).parts)) result = [bits.pop(0)] for bit in bits: diff --git a/tests/test_sanetise.py b/tests/test_sanetise.py index 05b9d28..eeb940d 100644 --- a/tests/test_sanetise.py +++ b/tests/test_sanetise.py @@ -6,60 +6,60 @@ # nor does it submit to any jurisdiction. -from anemoi.utils.sanetise import sanetise +from anemoi.utils.sanitise import sanitise -def test_sanetise_urls(): - assert sanetise("http://johndoe:password@host:port/path") == "http://user:***@host:port/path" +def test_sanitise_urls(): + assert sanitise("http://johndoe:password@host:port/path") == "http://user:***@host:port/path" - assert sanetise("http://www.example.com/path?pass=secret") == "http://www.example.com/path?pass=hidden" - assert sanetise("http://www.example.com/path?password=secret") == "http://www.example.com/path?password=hidden" - assert sanetise("http://www.example.com/path?token=secret") == "http://www.example.com/path?token=hidden" - assert sanetise("http://www.example.com/path?user=secret") == "http://www.example.com/path?user=hidden" - assert sanetise("http://www.example.com/path?key=secret") == "http://www.example.com/path?key=hidden" - assert sanetise("http://www.example.com/path?pwd=secret") == "http://www.example.com/path?pwd=hidden" - assert sanetise("http://www.example.com/path?_key=secret") == "http://www.example.com/path?_key=hidden" - assert sanetise("http://www.example.com/path?_token=secret") == "http://www.example.com/path?_token=hidden" - assert sanetise("http://www.example.com/path?apikey=secret") == "http://www.example.com/path?apikey=hidden" - assert sanetise("http://www.example.com/path?api_key=secret") == "http://www.example.com/path?api_key=hidden" - assert sanetise("http://www.example.com/path?api_token=secret") == "http://www.example.com/path?api_token=hidden" - assert sanetise("http://www.example.com/path?_api_token=secret") == "http://www.example.com/path?_api_token=hidden" - assert sanetise("http://www.example.com/path?_api_key=secret") == "http://www.example.com/path?_api_key=hidden" - assert sanetise("http://www.example.com/path?username=secret") == "http://www.example.com/path?username=hidden" - assert sanetise("http://www.example.com/path?login=secret") == "http://www.example.com/path?login=hidden" + assert sanitise("http://www.example.com/path?pass=secret") == "http://www.example.com/path?pass=hidden" + assert sanitise("http://www.example.com/path?password=secret") == "http://www.example.com/path?password=hidden" + assert sanitise("http://www.example.com/path?token=secret") == "http://www.example.com/path?token=hidden" + assert sanitise("http://www.example.com/path?user=secret") == "http://www.example.com/path?user=hidden" + assert sanitise("http://www.example.com/path?key=secret") == "http://www.example.com/path?key=hidden" + assert sanitise("http://www.example.com/path?pwd=secret") == "http://www.example.com/path?pwd=hidden" + assert sanitise("http://www.example.com/path?_key=secret") == "http://www.example.com/path?_key=hidden" + assert sanitise("http://www.example.com/path?_token=secret") == "http://www.example.com/path?_token=hidden" + assert sanitise("http://www.example.com/path?apikey=secret") == "http://www.example.com/path?apikey=hidden" + assert sanitise("http://www.example.com/path?api_key=secret") == "http://www.example.com/path?api_key=hidden" + assert sanitise("http://www.example.com/path?api_token=secret") == "http://www.example.com/path?api_token=hidden" + assert sanitise("http://www.example.com/path?_api_token=secret") == "http://www.example.com/path?_api_token=hidden" + assert sanitise("http://www.example.com/path?_api_key=secret") == "http://www.example.com/path?_api_key=hidden" + assert sanitise("http://www.example.com/path?username=secret") == "http://www.example.com/path?username=hidden" + assert sanitise("http://www.example.com/path?login=secret") == "http://www.example.com/path?login=hidden" - assert sanetise("http://www.example.com/path;pass=secret") == "http://www.example.com/path;pass=hidden" - assert sanetise("http://www.example.com/path;password=secret") == "http://www.example.com/path;password=hidden" - assert sanetise("http://www.example.com/path;token=secret") == "http://www.example.com/path;token=hidden" - assert sanetise("http://www.example.com/path;user=secret") == "http://www.example.com/path;user=hidden" - assert sanetise("http://www.example.com/path;key=secret") == "http://www.example.com/path;key=hidden" - assert sanetise("http://www.example.com/path;pwd=secret") == "http://www.example.com/path;pwd=hidden" - assert sanetise("http://www.example.com/path;_key=secret") == "http://www.example.com/path;_key=hidden" - assert sanetise("http://www.example.com/path;_token=secret") == "http://www.example.com/path;_token=hidden" - assert sanetise("http://www.example.com/path;apikey=secret") == "http://www.example.com/path;apikey=hidden" - assert sanetise("http://www.example.com/path;api_key=secret") == "http://www.example.com/path;api_key=hidden" - assert sanetise("http://www.example.com/path;api_token=secret") == "http://www.example.com/path;api_token=hidden" - assert sanetise("http://www.example.com/path;_api_token=secret") == "http://www.example.com/path;_api_token=hidden" - assert sanetise("http://www.example.com/path;_api_key=secret") == "http://www.example.com/path;_api_key=hidden" - assert sanetise("http://www.example.com/path;username=secret") == "http://www.example.com/path;username=hidden" - assert sanetise("http://www.example.com/path;login=secret") == "http://www.example.com/path;login=hidden" + assert sanitise("http://www.example.com/path;pass=secret") == "http://www.example.com/path;pass=hidden" + assert sanitise("http://www.example.com/path;password=secret") == "http://www.example.com/path;password=hidden" + assert sanitise("http://www.example.com/path;token=secret") == "http://www.example.com/path;token=hidden" + assert sanitise("http://www.example.com/path;user=secret") == "http://www.example.com/path;user=hidden" + assert sanitise("http://www.example.com/path;key=secret") == "http://www.example.com/path;key=hidden" + assert sanitise("http://www.example.com/path;pwd=secret") == "http://www.example.com/path;pwd=hidden" + assert sanitise("http://www.example.com/path;_key=secret") == "http://www.example.com/path;_key=hidden" + assert sanitise("http://www.example.com/path;_token=secret") == "http://www.example.com/path;_token=hidden" + assert sanitise("http://www.example.com/path;apikey=secret") == "http://www.example.com/path;apikey=hidden" + assert sanitise("http://www.example.com/path;api_key=secret") == "http://www.example.com/path;api_key=hidden" + assert sanitise("http://www.example.com/path;api_token=secret") == "http://www.example.com/path;api_token=hidden" + assert sanitise("http://www.example.com/path;_api_token=secret") == "http://www.example.com/path;_api_token=hidden" + assert sanitise("http://www.example.com/path;_api_key=secret") == "http://www.example.com/path;_api_key=hidden" + assert sanitise("http://www.example.com/path;username=secret") == "http://www.example.com/path;username=hidden" + assert sanitise("http://www.example.com/path;login=secret") == "http://www.example.com/path;login=hidden" -def test_sanetise_paths(): +def test_sanitise_paths(): # We want to keep earthkit-data's url and path pattern - assert sanetise("/home/johndoe/.ssh/id_rsa") == "/.../id_rsa" + assert sanitise("/home/johndoe/.ssh/id_rsa") == "/.../id_rsa" assert ( - sanetise("/data/model/{date:strftime(%Y)}/{date:strftime(%m)}/{date:strftime(%d)}/analysis.grib") + sanitise("/data/model/{date:strftime(%Y)}/{date:strftime(%m)}/{date:strftime(%d)}/analysis.grib") == "/.../{date:strftime(%Y)}/{date:strftime(%m)}/{date:strftime(%d)}/analysis.grib" ) - assert sanetise("test.grib") == "test.grib" - assert sanetise("../test.grib") == "../test.grib" - assert sanetise("./test.grib") == "./test.grib" - assert sanetise("sub/folder/test.grib") == "sub/folder/test.grib" - assert sanetise("./folder/test.grib") == "./folder/test.grib" + assert sanitise("test.grib") == "test.grib" + assert sanitise("../test.grib") == "../test.grib" + assert sanitise("./test.grib") == "./test.grib" + assert sanitise("sub/folder/test.grib") == "sub/folder/test.grib" + assert sanitise("./folder/test.grib") == "./folder/test.grib" if __name__ == "__main__":