From 2a2cdd24d72b66da1601e11c96c2d8c84bae81cd Mon Sep 17 00:00:00 2001 From: Aaron Steers Date: Wed, 19 Feb 2025 15:16:55 -0800 Subject: [PATCH 1/3] feat: improved custom components handling --- .../parsers/custom_code_compiler.py | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/airbyte_cdk/sources/declarative/parsers/custom_code_compiler.py b/airbyte_cdk/sources/declarative/parsers/custom_code_compiler.py index 8a6638fad..143fedb4b 100644 --- a/airbyte_cdk/sources/declarative/parsers/custom_code_compiler.py +++ b/airbyte_cdk/sources/declarative/parsers/custom_code_compiler.py @@ -45,7 +45,7 @@ def __init__(self) -> None: def _hash_text(input_text: str, hash_type: str = "md5") -> str: """Return the hash of the input text using the specified hash type.""" if not input_text: - raise ValueError("Input text cannot be empty.") + raise ValueError("Hash input text cannot be empty.") hash_object = CHECKSUM_FUNCTIONS[hash_type]() hash_object.update(input_text.encode()) @@ -68,6 +68,10 @@ def validate_python_code( Currently we fail if no checksums are provided, although this may change in the future. """ + if not code_text: + # No code provided, nothing to validate. + return + if not checksums: raise ValueError(f"A checksum is required to validate the code. Received: {checksums}") @@ -77,8 +81,18 @@ def validate_python_code( f"Unsupported checksum type: {checksum_type}. Supported checksum types are: {CHECKSUM_FUNCTIONS.keys()}" ) - if _hash_text(code_text, checksum_type) != checksum: - raise AirbyteCodeTamperedError(f"{checksum_type} checksum does not match.") + calculated_checksum = _hash_text(code_text, checksum_type) + if calculated_checksum != checksum: + raise AirbyteCodeTamperedError( + f"{checksum_type} checksum does not match." + + str( + { + "expected_checksum": checksum, + "actual_checksum": calculated_checksum, + "code_text": code_text, + } + ), + ) def get_registered_components_module( @@ -94,7 +108,10 @@ def get_registered_components_module( Returns `None` if no components is provided and the `components` module is not found. """ - if config and INJECTED_COMPONENTS_PY in config: + if INJECTED_MANIFEST not in config: + raise RuntimeError(f"Expected {INJECTED_MANIFEST} to be in config.") + + if config and config.get(INJECTED_COMPONENTS_PY, None): if not custom_code_execution_permitted(): raise AirbyteCustomCodeNotPermittedError From cf22c9507f2674337bc4c2c87e54aded6e348050 Mon Sep 17 00:00:00 2001 From: Aaron Steers Date: Fri, 28 Feb 2025 15:31:38 -0800 Subject: [PATCH 2/3] fix mypy issue --- airbyte_cdk/sources/declarative/parsers/custom_code_compiler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airbyte_cdk/sources/declarative/parsers/custom_code_compiler.py b/airbyte_cdk/sources/declarative/parsers/custom_code_compiler.py index 143fedb4b..6e0370dec 100644 --- a/airbyte_cdk/sources/declarative/parsers/custom_code_compiler.py +++ b/airbyte_cdk/sources/declarative/parsers/custom_code_compiler.py @@ -108,7 +108,7 @@ def get_registered_components_module( Returns `None` if no components is provided and the `components` module is not found. """ - if INJECTED_MANIFEST not in config: + if config and INJECTED_MANIFEST not in config: raise RuntimeError(f"Expected {INJECTED_MANIFEST} to be in config.") if config and config.get(INJECTED_COMPONENTS_PY, None): From 1a34aaccd778fcd07d53d7b3d2b6281be990718d Mon Sep 17 00:00:00 2001 From: Aaron Steers Date: Fri, 28 Feb 2025 15:33:22 -0800 Subject: [PATCH 3/3] remove requirement for manifest --- .../sources/declarative/parsers/custom_code_compiler.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/airbyte_cdk/sources/declarative/parsers/custom_code_compiler.py b/airbyte_cdk/sources/declarative/parsers/custom_code_compiler.py index 6e0370dec..608861135 100644 --- a/airbyte_cdk/sources/declarative/parsers/custom_code_compiler.py +++ b/airbyte_cdk/sources/declarative/parsers/custom_code_compiler.py @@ -108,9 +108,6 @@ def get_registered_components_module( Returns `None` if no components is provided and the `components` module is not found. """ - if config and INJECTED_MANIFEST not in config: - raise RuntimeError(f"Expected {INJECTED_MANIFEST} to be in config.") - if config and config.get(INJECTED_COMPONENTS_PY, None): if not custom_code_execution_permitted(): raise AirbyteCustomCodeNotPermittedError