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: Add request plugin capability #25864

Merged
merged 2 commits into from
Jan 22, 2025
Merged

feat: Add request plugin capability #25864

merged 2 commits into from
Jan 22, 2025

Conversation

pauldix
Copy link
Member

@pauldix pauldix commented Jan 18, 2025

Adds the request plugin type. Triggers can be bound to an API endpoint at /api/v3/engine/. Requests will get yielded to the plugin with the query parameters, request parameters, and request body.

I didn't implement the test endpoint for this plugin type as it seems much more natural for users to save the file and make a new request. Once #25863 is done it'll make it very easy.

Closes #25862

Adds the request plugin type. Triggers can be bound to an API endpoint at /api/v3/engine/<path>. Requests will get yielded to the plugin with the query parameters, request parameters, and request body.

I didn't implement the test endpoint for this plugin type as it seems much more natural for users to save the file and make a new request. Once #25863 is done it'll make it very easy.

Closes #25862
Copy link
Contributor

@jacksonrnewhouse jacksonrnewhouse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are inconsistencies around the python return type that I presume came up as you iterated. The example in test_request_plugin_and_trigger() returns

    return 200, {"Content-Type": "application/json"}, json.dumps({"status": "ok", "line": line_str})

While the error message in MissingProcessRequestFunction says it should be
Tuple[str, Optional[Dict[str, str]]]. And then in execute_request_trigger it'll fail if the result does not have 3 items, addressable via get_item().

Additionally, I think it might be clean to follow some of Flask's semantics in terms of what we support. The quickstart docs specify it at https://flask.palletsprojects.com/en/stable/quickstart/#about-responses. For our purpose, I'm not sure we should try and support (1) a full Response being returned or (3) a streaming response, but our tuples should be similar to what is described in (5). How hard would it be on the Rust side to convert a PyDict to JSON? It might be nice to allow that, but if it is a pain, fine to require the user to call json.dumps().

let py_headers_dict = headers_binding
.downcast::<PyDict>()
.map_err(|e| anyhow::anyhow!("Failed to downcast to PyDict: {}", e))?;
let body_binding = result.get_item(2).context("Python reqeust function didn't return a tuple of (status_code, response_headers, body)")?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let body_binding = result.get_item(2).context("Python reqeust function didn't return a tuple of (status_code, response_headers, body)")?;
let body_binding = result.get_item(2).context("Python request function didn't return a tuple of (status_code, response_headers, body)")?;

@pauldix
Copy link
Member Author

pauldix commented Jan 21, 2025

It's easy enough for us to automatically do the JSON conversion, but not every response is going to be JSON. So I left it to the user to have the response body be whatever they want it to be. I can clean up the other smaller things in a bit.

@pauldix
Copy link
Member Author

pauldix commented Jan 22, 2025

Fixed the spelling error and logged #25894 to fix in a follow on PR. For now I'd like to get this one in so you can do the refactor with it in place.

@pauldix pauldix merged commit e87f886 into main Jan 22, 2025
13 checks passed
@pauldix pauldix deleted the pd/request-plugin branch January 22, 2025 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add request plugin type
2 participants