Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improved custom components handling #350

Merged
merged 4 commits into from
Mar 3, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions airbyte_cdk/sources/declarative/parsers/custom_code_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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}")

Expand All @@ -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(
Expand All @@ -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

Expand Down
Loading