oscerd opened a new pull request, #29081: URL: https://github.com/apache/camel/pull/29081
Fixes [CAMEL-26272](https://issues.apache.org/jira/browse/CAMEL-26272), found while adding the catalog body types (CAMEL-24961). ## 1. The CamelDuckDbDatabasePath header is honoured only when the endpoint allows it **Was:** The producer read the `CamelDuckDbDatabasePath` header on every message and, when it was set, opened a short-lived connection to the DuckDB file at that path instead of using the `databasePath`, `jdbcUrl` or `DataSource` of the endpoint. DuckDB created the file when it did not exist, so a message could move the endpoint to another database file, or create a new one. **Now:** The header is ignored unless the endpoint sets the new `allowDatabasePathFromHeader=true` option, which is disabled by default. With the option, the header works as before. The option follows the closest precedent, `allowQueryFromHeader` of camel-sql, which gates the `CamelSqlQuery` header the same way: the `allow...FromHeader` name (also used by `allowTemplateFromHeader` of sql-stored and the template components), `label = "producer,security"`, `security = "insecure:dev"` with `insecureValue = "true"`, and a description that says to enable it only when the header source is trusted. Like that option, the header is ignored without a log message. ## 2. The page documents the headers that override the endpoint **Was:** The page said that the SQL of `execute` and `query` comes from the `CamelDuckDbQuery` header first, and that the `CamelDuckDbDatabasePath` header opens a connection to another database file, but did not say which headers override the endpoint as a whole. **Now:** A new section, "Headers that override the endpoint", lists `CamelDuckDbOperation` (replaces the `operation` option), `CamelDuckDbQuery` (replaces the `query` option and the message body as the SQL) and `CamelDuckDbTable` (replaces the `table` option of `insert` and `copy`), says that `CamelDuckDbDatabasePath` is ignored unless `allowDatabasePathFromHeader=true`, and recommends `removeHeaders("CamelDuckDb*")` before the endpoint when the messages come from an untrusted producer through a consumer that does not filter out `Camel*` headers. ## Tests `DuckDbProducerTest`, against DuckDB database files in a temporary directory: - Without the option, a query with the header runs on the database of the endpoint, not on the file that the header names. - Without the option, a header that names a file that does not exist does not create it, and the statement runs on the database of the endpoint (the issue's reproducer). - With `allowDatabasePathFromHeader=true`, the header still moves the query to the file it names (the existing test, which now sets the option). - The `CamelDuckDbOperation` and `CamelDuckDbTable` headers still override the operation and the table of the endpoint, as the page now says. The `CamelDuckDbQuery` header was already covered. Revert check: with the producer and endpoint change reverted, 3 of the 5 new or changed tests fail: the query reads `header-db` from the file that the header names instead of `endpoint-db`, the header creates `created-by-header.db`, and the test that sets the option fails because the option does not exist. The 2 that pass are the operation and table header tests, which pin behaviour that does not change. Module: 29 tests (`DuckDbProducerTest` 16, `DuckDbComponentTest` 6, `DuckDbJdbcSupportTest` 7), all pass. The integration test does not use the `CamelDuckDbDatabasePath` header and was not run. ## Docs and generated files - The `allowDatabasePathFromHeader` option and the `CamelDuckDbDatabasePath` header description on the endpoint and in `DuckDbConstants`, regenerated `duckdb.json`, and the catalog copies of the JSON and the page. - The component page section described above. - Upgrade guide entry for 4.24, as a route that relies on the header must now set the option. ## Not changed - `CamelDuckDbOperation`, `CamelDuckDbQuery` and `CamelDuckDbTable` still override the endpoint, as the issue proposes to document them only. With the default `execute` operation the message body is already run as SQL, so gating these headers would not keep a message from choosing the SQL that runs. - The option name is `allowDatabasePathFromHeader` rather than the `allowDatabasePathHeader` example of the issue, to match `allowQueryFromHeader` and `allowTemplateFromHeader`. - The option is on the endpoint only, as the issue asks. camel-sql also has a component-level `allowQueryFromHeader` that sets the default for all endpoints; it can be added here later if wanted. - The ignored header is not logged, as in camel-sql, sql-stored, spiffe and the template components. camel-exec instead logs a warning once per endpoint for its ignored control headers. - With the option enabled, the header still bypasses the `jdbcUrl` or `DataSource` of the endpoint and creates the file when it does not exist, and `readOnly` still applies to its connection, as before. Note for merging: CAMEL-26272 (camel-duckdb) and CAMEL-26273 (camel-clickhouse) each add an option with a `security` marker, so both regenerate `core/camel-util/.../SecurityUtils.java` and add their key at the same place. Whichever of the two PRs is merged second needs a rebase and the regeneration of that file. Main only, as the other fixes of the CAMEL-24961 follow-ups. _Claude Code on behalf of Andrea Cosentino (oscerd)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
