From d2a680e4813ebfbc38ffab419a533e7d84df6e55 Mon Sep 17 00:00:00 2001 From: Artem Inzhyyants Date: Fri, 14 Mar 2025 14:31:07 +0100 Subject: [PATCH 1/2] feat: add base64binascii_decode Signed-off-by: Artem Inzhyyants --- .../declarative/interpolation/filters.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/airbyte_cdk/sources/declarative/interpolation/filters.py b/airbyte_cdk/sources/declarative/interpolation/filters.py index ffebe73da..267a11c39 100644 --- a/airbyte_cdk/sources/declarative/interpolation/filters.py +++ b/airbyte_cdk/sources/declarative/interpolation/filters.py @@ -93,6 +93,24 @@ def base64decode(value: str) -> str: return base64.b64decode(value.encode("utf-8")).decode() +def base64binascii_decode(value: str) -> str: + """ + Implementation of a custom Jinja2 base64decode filter + + For example: + + OAuthAuthenticator: + $ref: "#/definitions/OAuthAuthenticator" + $parameters: + name: "client_id" + value: "{{ config['client_id'] | base64decode }}" + + :param value: value to be decoded from base64 using ascii + :return: base64 decoded string ascii + """ + return base64.standard_b64encode(value.encode("ascii")).decode("ascii") + + def string(value: Any) -> str: """ Converts the input value to a string. @@ -117,5 +135,5 @@ def regex_search(value: str, regex: str) -> str: return "" -_filters_list = [hash, base64encode, base64decode, string, regex_search] +_filters_list = [hash, base64encode, base64decode, base64binascii_decode, string, regex_search] filters = {f.__name__: f for f in _filters_list} From e73800160b0b79beaf6cecfbd990b303473f7ba8 Mon Sep 17 00:00:00 2001 From: Artem Inzhyyants Date: Fri, 14 Mar 2025 14:49:41 +0100 Subject: [PATCH 2/2] feat: fix Signed-off-by: Artem Inzhyyants --- airbyte_cdk/sources/declarative/interpolation/filters.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/airbyte_cdk/sources/declarative/interpolation/filters.py b/airbyte_cdk/sources/declarative/interpolation/filters.py index 267a11c39..b40310499 100644 --- a/airbyte_cdk/sources/declarative/interpolation/filters.py +++ b/airbyte_cdk/sources/declarative/interpolation/filters.py @@ -95,7 +95,7 @@ def base64decode(value: str) -> str: def base64binascii_decode(value: str) -> str: """ - Implementation of a custom Jinja2 base64decode filter + Implementation of a custom Jinja2 filter to decode base64 strings using ASCII encoding For example: @@ -103,7 +103,7 @@ def base64binascii_decode(value: str) -> str: $ref: "#/definitions/OAuthAuthenticator" $parameters: name: "client_id" - value: "{{ config['client_id'] | base64decode }}" + value: "{{ config['client_id'] | base64binascii_decode }}" :param value: value to be decoded from base64 using ascii :return: base64 decoded string ascii