From 4c4f922ecd0c12b55300b1f07e03dad83674b12d Mon Sep 17 00:00:00 2001 From: Ben Schulz <110361904+ben-schulz-mh@users.noreply.github.com> Date: Fri, 27 Dec 2024 13:23:48 +1000 Subject: [PATCH] feat: add SHA256 encryption method to inline stream maps --- singer_sdk/mapper.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/singer_sdk/mapper.py b/singer_sdk/mapper.py index 004d0f60a..f0d9265d4 100644 --- a/singer_sdk/mapper.py +++ b/singer_sdk/mapper.py @@ -63,6 +63,12 @@ def md5(string: str) -> str: return hashlib.md5(string.encode("utf-8")).hexdigest() # noqa: S324 +def sha256(value: str) -> str: + """Digest a string using SHA256. This is a function for inline calculations.""" + + return hashlib.sha256(value.encode("utf-8")).hexdigest() + + StreamMapsDict: TypeAlias = dict[str, t.Union[str, dict, None]] @@ -307,6 +313,7 @@ def functions(self) -> dict[str, t.Callable]: """ funcs: dict[str, t.Any] = simpleeval.DEFAULT_FUNCTIONS.copy() funcs["md5"] = md5 + funcs["sha256"] = sha256 funcs["datetime"] = datetime funcs["bool"] = bool funcs["json"] = json