-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add more robust config parsing (str as json) #60
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -33,6 +33,8 @@ | |||||
|
||||||
from connector_builder_mcp._secrets import hydrate_config | ||||||
from connector_builder_mcp._util import ( | ||||||
as_bool, | ||||||
as_dict, | ||||||
filter_config_secrets, | ||||||
parse_manifest_input, | ||||||
validate_manifest_structure, | ||||||
|
@@ -92,29 +94,6 @@ class MultiStreamSmokeTest(BaseModel): | |||||
stream_results: dict[str, StreamSmokeTest] | ||||||
|
||||||
|
||||||
def _as_bool( | ||||||
val: bool | str | None, # noqa: FBT001 | ||||||
/, | ||||||
default: bool = False, # noqa: FBT001, FBT002 | ||||||
) -> bool: | ||||||
"""Convert a string, boolean, or None value to a boolean. | ||||||
|
||||||
Args: | ||||||
val: The value to convert. | ||||||
default: The default boolean value to return if the value is None. | ||||||
|
||||||
Returns: | ||||||
The converted boolean value. | ||||||
""" | ||||||
if isinstance(val, bool): | ||||||
return val | ||||||
|
||||||
if isinstance(val, str): | ||||||
return val.lower() == "true" | ||||||
|
||||||
return default | ||||||
|
||||||
|
||||||
def _calculate_record_stats( | ||||||
records_data: list[dict[str, Any]], | ||||||
) -> dict[str, Any]: | ||||||
|
@@ -319,7 +298,7 @@ def validate_manifest( | |||||
) | ||||||
|
||||||
|
||||||
def execute_stream_test_read( | ||||||
def execute_stream_test_read( # noqa: PLR0914 | ||||||
manifest: Annotated[ | ||||||
str, | ||||||
Field(description="The connector manifest. Can be raw a YAML string or path to YAML file"), | ||||||
|
@@ -329,8 +308,8 @@ def execute_stream_test_read( | |||||
Field(description="Name of the stream to test"), | ||||||
], | ||||||
config: Annotated[ | ||||||
dict[str, Any] | None, | ||||||
Field(description="Connector configuration"), | ||||||
dict[str, Any] | str | None, | ||||||
Field(description="Connector configuration dictionary."), | ||||||
] = None, | ||||||
*, | ||||||
max_records: Annotated[ | ||||||
|
@@ -354,7 +333,7 @@ def execute_stream_test_read( | |||||
), | ||||||
] = None, | ||||||
dotenv_file_uris: Annotated[ | ||||||
str | list[str] | None, | ||||||
list[str] | str | None, | ||||||
Field( | ||||||
description="Optional paths/URLs to local .env files or Privatebin.net URLs for secret hydration. Can be a single string, comma-separated string, or list of strings. Privatebin secrets may be created at privatebin.net, and must: contain text formatted as a dotenv file, use a password sent via the `PRIVATEBIN_PASSWORD` env var, and not include password text in the URL." | ||||||
), | ||||||
|
@@ -367,20 +346,20 @@ def execute_stream_test_read( | |||||
We do not attempt to sanitize record data, as it is expected to be user-defined. | ||||||
""" | ||||||
success: bool = True | ||||||
include_records_data = _as_bool( | ||||||
include_records_data = as_bool( | ||||||
include_records_data, | ||||||
default=False, | ||||||
) | ||||||
include_record_stats = _as_bool( | ||||||
include_record_stats = as_bool( | ||||||
include_record_stats, | ||||||
default=False, | ||||||
) | ||||||
include_raw_responses_data = _as_bool( | ||||||
include_raw_responses_data = as_bool( | ||||||
include_raw_responses_data, | ||||||
default=False, | ||||||
) | ||||||
logger.info(f"Testing stream read for stream: {stream_name}") | ||||||
config = config or {} | ||||||
config = as_dict(config, default={}) | ||||||
|
||||||
manifest_dict, _ = parse_manifest_input(manifest) | ||||||
|
||||||
|
@@ -455,7 +434,7 @@ def execute_stream_test_read( | |||||
records_data.extend(page.pop("records")) | ||||||
|
||||||
raw_responses_data = None | ||||||
if include_raw_responses_data is True and slices and isinstance(slices, list): | ||||||
if include_raw_responses_data is True and slices: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The explicit
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
raw_responses_data = slices | ||||||
|
||||||
record_stats = None | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
json.loads()
call can raiseJSONDecodeError
but this is not handled or documented. Consider wrapping in a try-catch block and raising a more descriptive error message that indicates the JSON parsing failed.Copilot uses AI. Check for mistakes.