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

   Fixes [CAMEL-26248](https://issues.apache.org/jira/browse/CAMEL-26248), 
found while adding the catalog body types (CAMEL-24961).
   
   ## 1. deleteSecret always sets a null body
   
   **Was:** `KeyVaultProducer.deleteSecret` waited for the delete poller and 
set `SyncPoller.getFinalResult()` as the body. The poller is a 
`SyncPoller<DeletedSecret, Void>`, so the final result is always null, and the 
`DeletedSecret` (recovery id, deletion date, scheduled purge date) was lost.
   
   **Now:** the body is the value of the last poll response, 
`waitForCompletion().getValue()`: the `DeletedSecret` that Key Vault returns 
once the secret is deleted. When the poll cannot read the deleted secret, the 
SDK keeps the `DeletedSecret` of the delete request.
   
   ## 2. createSecret stores a Map or POJO body as its toString
   
   **Was:** the value of the secret was `getMandatoryBody(String.class)`, so a 
Map was stored as `{username=admin, password=s3cr3t}` and a POJO as its 
`toString()`, such as `MyPojo@1b2c3d`.
   
   **Now:** a `Map` or a `List` is stored as JSON, written with Jackson, which 
the module already uses: the `azure:` properties function reads a field of a 
JSON secret, as in `{{azure:database#username}}`. Another object that Jackson 
writes as a JSON object or array (a POJO) is stored as that JSON. Text, bytes, 
a stream and a file are read as text as before. So is a value that Jackson 
writes as a JSON scalar (a number, a UUID) or cannot serialize (an object 
without properties), so no value that worked before changes. A `Map` or a 
`List` that Jackson cannot serialize fails with an `IllegalArgumentException` 
instead of storing its `toString()`.
   
   ## Tests
   
   - New `KeyVaultProducerTest` (8 tests) runs the real `SecretClient` against 
a fake of the Key Vault REST API on a JDK `HttpServer`. The module has no 
Mockito, and `SecretClient` is a final class. The tests cover deleteSecret (the 
DeletedSecret with its name, recovery id and dates, after the DELETE and the 
poll), a Map, a POJO, a List, a Map that Jackson cannot serialize, text, a 
byte[] with non-ASCII UTF-8, an InputStream, a File, a UUID, a number and no 
body.
   - With the `src/main` changes reverted, 5 of the 8 new tests fail on their 
assertions. deleteSecret gives null. The Map, the POJO and the List are stored 
as `{username=admin, ...}`, `Credentials[...]` and `[10.0.0.1, 10.0.0.2]`. The 
Map that Jackson cannot serialize is stored instead of failing. The 3 that pass 
guard the behaviour that does not change: text, bytes, stream and file; a UUID 
and a number; no body.
   - Module: 14 tests, 0 failures, 1 skipped (it needs an Azure account); the 5 
ITs are skipped.
   
   ## Docs and generated files
   
   - Component doc: createSecret describes its body (text, or JSON for a Map, a 
List or a POJO, of which `{{azure:database#username}}` reads a field) and the 
body after it; deleteSecret says that it waits until the secret is deleted and 
gives the `DeletedSecret`.
   - `@BodyTypes`: producerIn adds map, list and pojo; producerOut of 
deleteSecret is the `DeletedSecret` (was null). The regenerated 
`azure-key-vault.json` and the doc are copied into the catalog (both copies 
were identical to the module at the base).
   - Upgrade guide entry for 4.24: the body after deleteSecret, and a Map, a 
List or a POJO stored as JSON.
   
   ## Not changed
   
   - A `byte[]` body is still decoded as text, with the charset of the 
exchange. A Key Vault secret is a string, so bytes that are not text (such as 
0xff) are not stored as they are: a route that stores binary data must encode 
it, for example as Base64.
   - The `azure:` properties function reads only the text fields of a JSON 
secret (`textValue()`), so `{{azure:db#port}}` finds nothing for a number such 
as `"port":5432` in a Map stored by createSecret. That is a limit of the 
properties function, not of this fix. **Open question:** should the function 
also read number and boolean fields?
   
   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