oscerd opened a new pull request, #29082:
URL: https://github.com/apache/camel/pull/29082

   Fixes [CAMEL-26273](https://issues.apache.org/jira/browse/CAMEL-26273), 
found while adding the catalog body types (CAMEL-24961).
   
   ## 1. The database and table headers are honoured only when the endpoint 
allows it
   
   **Was:** The producer always took the `CamelClickHouseDatabase` and 
`CamelClickHouseTable` headers over the database and the table of the endpoint, 
so a message could insert into, or query, another database or table than the 
one the endpoint is configured with. An insert endpoint without a table also 
took its table from the header.
   
   **Now:** Both headers are ignored unless the endpoint sets the new 
`allowDatabaseAndTableFromHeaders=true` option, which is disabled by default. 
With the option, they work as before. An insert endpoint without a table now 
fails with the existing "A table is required for insert operations" error, 
which now says that the header needs `allowDatabaseAndTableFromHeaders=true`.
   
   The option follows the closest precedent, `allowQueryFromHeader` of 
camel-sql, which gates the `CamelSqlQuery` header the same way: the 
`allow...FromHeader` name (plural here, as it covers two headers), `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 headers are ignored without a log message. 
One option covers both headers, as the issue asks for one option, and as the 
`dynamicity` option of camel-mongodb covers its database and collection headers.
   
   ## 2. The page documents the headers that override the endpoint
   
   **Was:** The page said that the operation can be selected with the 
`CamelClickHouseOperation` header, and the header table said that the four 
headers override the endpoint, but nothing said what that lets a message do.
   
   **Now:** A new section, "Headers that override the endpoint", says that 
`CamelClickHouseOperation` and `CamelClickHouseFormat` replace the `operation` 
and `format` options, that a message which sets the operation to `query` on an 
insert endpoint chooses the SQL that runs (the body), that 
`CamelClickHouseDatabase` and `CamelClickHouseTable` are ignored unless 
`allowDatabaseAndTableFromHeaders=true`, and recommends 
`removeHeaders("CamelClickHouse*")` before the endpoint when the messages come 
from an untrusted producer through a consumer that does not filter out `Camel*` 
headers.
   
   ## Tests
   
   `ClickHouseProducerTest`, with a mocked `Client` that records the table and 
the settings of each call:
   
   - Without the option, an insert with both headers goes to the table and the 
database of the endpoint, and a query with the database header runs in the 
database of the endpoint.
   - Without the option, an insert endpoint without a table fails with the 
error that names the option, even when the table header is set, and nothing is 
inserted.
   - With `allowDatabaseAndTableFromHeaders=true`, the headers still choose the 
table and the database of an insert, and the database of a query.
   - The `CamelClickHouseFormat` header still overrides the format (split from 
the former test of the table and format headers), and the existing test of the 
`CamelClickHouseOperation` header is unchanged.
   
   Revert check: with the producer and endpoint change reverted, 5 of the 6 new 
tests fail: the insert goes to the `overridden` table instead of `events`, the 
query runs in the `other` database instead of `analytics`, the insert without a 
table takes the header instead of failing, and the 2 tests that set the option 
fail because the option does not exist. The 1 that passes is the format header 
test, which pins behaviour that does not change.
   
   Module: 29 tests (`ClickHouseProducerTest` 20, `ClickHouseComponentTest` 9), 
all pass. The integration test does not use these headers and was not run.
   
   ## Docs and generated files
   
   - The `allowDatabaseAndTableFromHeaders` option, the `table` option 
description and the `CamelClickHouseDatabase` and `CamelClickHouseTable` header 
descriptions, regenerated `clickhouse.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 headers must 
now set the option.
   
   ## Not changed
   
   - `CamelClickHouseOperation` and `CamelClickHouseFormat` still override the 
endpoint, as the issue asks to gate the database and table headers. A route may 
use one endpoint for insert and query through the operation header, which a 
gate would break. The page now says that switching an insert endpoint to 
`query` runs the body as SQL; a separate gate like the `allowOperationHeader` 
option of camel-spiffe could follow if wanted.
   - 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.
   - One option covers both headers, so a route cannot allow the table header 
without the database header; two options would be finer, but the issue asks for 
one.
   - The ignored headers are 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.
   
   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]

Reply via email to