oscerd opened a new pull request, #28963: URL: https://github.com/apache/camel/pull/28963
Fixes [CAMEL-26253](https://issues.apache.org/jira/browse/CAMEL-26253), found while adding the catalog body types (CAMEL-24961). ## 1. createSecret without a body left an empty secret behind **Was:** `GoogleSecretManagerProducer.createSecret` first created the secret, then called `ByteString.copyFromUtf8(getBody(String.class))`, which threw a NullPointerException when there was no body. The secret stayed in Secret Manager without a version. **Now:** the value is read with `getMandatoryBody(String.class)` before the secret is created, so a message without a body fails with an `InvalidPayloadException` and nothing is created. A String, bytes, a stream or a file are still read as text, as before. ## 2. pojoRequest=true createSecret never created the secret **Was:** with `pojoRequest=true` the body had to be an `AddSecretVersionRequest`, and only `addSecretVersion` was called, so createSecret only worked for a secret that existed already. **Now:** with `pojoRequest=true`, createSecret also takes a `CreateSecretRequest`: it calls `createSecret(request)` and gives the created `Secret` as body (the request has no payload, so the secret has no version yet). An `AddSecretVersionRequest` still adds a version and gives the `SecretVersion`, as before. Another body fails with an `InvalidPayloadException` whose message says that a `CreateSecretRequest` or an `AddSecretVersionRequest` is expected. ## 3. The operations heading named the wrong component **Was:** "Google Functions component provides the following operation on the producer side". **Now:** "Google Secret Manager component provides the following operations on the producer side". ## Tests - New `GoogleSecretManagerCreateSecretTest` (6 tests) with a Mockito mock of `SecretManagerServiceClient`: no body, a String body (the secret gets automatic replication and the value is added as a version), a stream body, a `CreateSecretRequest` and an `AddSecretVersionRequest` with `pojoRequest=true`, and another body with `pojoRequest=true`. - With the `src/main` changes reverted, 3 of the 6 new tests fail, each on the bug: no body (`createSecret` was invoked although the test expects it never is), the `CreateSecretRequest` (an `InvalidPayloadException` asking for an `AddSecretVersionRequest`), and another pojo body (the message does not say a `CreateSecretRequest` is accepted). The 3 that pass are the String body, the stream body and the `AddSecretVersionRequest`, which worked before: they guard that the change keeps them. - Module tests: 12 tests, 0 failures. ## Docs and generated files Component doc: the heading fix, what createSecret reads and returns, that no body fails before the secret is created, and the two pojo requests with an example that creates a secret with a `CreateSecretRequest` and adds its value with an `AddSecretVersionRequest`. `@BodyTypes`: the input gets a `pojoRequest=true` entry (POJO), which it lacked, and says what createSecret takes with pojoRequest; the output drops the `SecretVersion` Java type, since createSecret with a `CreateSecretRequest` gives a `Secret`, and its description says so. The regenerated `google-secret-manager.json` and the doc are copied into the catalog. Upgrade guide entry: none, as both changes turn a failure into a clean failure or a working call. ## Not changed - An empty String body is still sent as an empty payload. I could not confirm from the API documentation whether Secret Manager rejects an empty payload; if it does, the secret would still be created before the version fails. **Open question:** should an empty body also fail before the secret is created? - The value is still read as text (UTF-8), so binary data is not kept byte for byte; getSecretVersion also gives the value as text. - A missing `CamelGoogleSecretManagerSecretId` header still fails inside the SDK with a NullPointerException, but before anything is created, so no secret is left behind. 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]
