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

   Fixes [CAMEL-26254](https://issues.apache.org/jira/browse/CAMEL-26254), 
found while adding the catalog body types (CAMEL-24961).
   
   Fixes [CAMEL-26254](https://issues.apache.org/jira/browse/CAMEL-26254).
   
   ## 1. getSecret and updateSecret failed for the other secret types
   
   **Was:** `getSecret` handled `arbitrary`, `kv` and `service_credentials` 
only, and threw "Unsupported secret type" for `username_password`, 
`iam_credentials`, `imported_cert`, `public_cert`, `private_cert` and 
`custom_credentials`. `updateSecret` handled `arbitrary` and `kv` only, which 
the docs did not say.
   
   **Now:** `getSecret` gives the payload text of an arbitrary secret and the 
`Map` of a kv secret, as before, and the `Secret` of the IBM SDK for every 
other type, as it did for `service_credentials`. Its getters return the fields 
of the type, such as `getUsername()` and `getPassword()`, `getApiKey()` or 
`getCertificate()`. A missing `secret_type` no longer gives a 
`NullPointerException` from the `switch`. `updateSecret` still supports 
arbitrary and kv secrets: the docs say so now, and the error for another type 
says which types it supports.
   
   ## 2. createKVSecret did not accept JSON text
   
   **Was:** `createKVSecret` read the body with `getBody(Map.class)`, and there 
is no String to Map conversion, so a JSON object as text failed with "Secret 
data must be provided as a Map".
   
   **Now:** a body that is not a `Map` is read as text and parsed as a JSON 
object with Jackson, which the module already uses. So JSON text, bytes, a 
stream or a file work. The kv body of `updateSecret` is read the same way. A 
body that is not a JSON object fails with an `IllegalArgumentException` that 
says so. The parser exception is not kept as the cause, because its message can 
quote the text, which would put the secret in the log.
   
   ## 3. A Map or a POJO body was stored as its toString() in an arbitrary 
secret
   
   **Was:** `createArbitrarySecret`, and `updateSecret` for an arbitrary 
secret, read the payload with `getBody(String.class)`, so a `Map` was stored as 
`{username=admin}` and a POJO as its `toString()`.
   
   **Now:** a `Map`, a `List` or another object is marshalled to JSON with 
Jackson. Text, bytes, a stream, a file (also a GenericFile), a number, a 
boolean, a character or an enum is read as text, as before. An object that 
Jackson cannot marshal fails with an `IllegalArgumentException` that says to 
convert it to text first.
   
   ## Tests
   
   - New `IBMSecretsManagerProducerBodyTest` (25 tests): the real IBM Secrets 
Manager SDK, with `NoAuthAuthenticator`, against a JDK `HttpServer` that plays 
the service and records the requests. It covers getSecret for all nine secret 
types (with the fields of username_password, iam_credentials and 
imported_cert), updateSecret of a username_password secret, createKVSecret with 
JSON text, bytes, a stream, a Map, a JSON array and plain text (the error must 
not quote it), updateSecret of a kv secret with JSON text, 
createArbitrarySecret with a Map, a POJO, a List, text, bytes, a stream, a 
number and no body, and updateSecret of an arbitrary secret with a Map.
   - With the `src/main` changes reverted, 20 of the 25 new tests fail on their 
assertions: "Unsupported secret type" for the other types, "Secret data must be 
provided as a Map" for the JSON bodies, the old message for the update of a 
username_password secret, and payloads such as `{username=admin, port=5432}` 
that are not JSON. The 5 that pass are getSecret of a service_credentials 
secret, getSecret of an arbitrary and a kv secret, createKVSecret with a Map, 
text, bytes, a stream and a number for createArbitrarySecret, and no body for 
createArbitrarySecret.
   - Module: 31 unit tests, 0 failures (the ITs need an IBM Cloud account and 
are skipped).
   
   ## Docs and generated files
   
   - The component doc says how the payload of an arbitrary secret and the data 
of a kv secret are read, what getSecret gives per secret type, and that 
updateSecret supports arbitrary and kv secrets. The kv example has Java, XML 
and YAML tabs with a JSON body, as it no longer needs a processor to build a 
Map; the Map example is kept.
   - `@BodyTypes`: createArbitrarySecret and updateSecret also take a Map, a 
List or a POJO, createKVSecret takes a Map or JSON as text, bytes, a stream or 
a file, and getSecret gives the Secret for the other types. The regenerated 
`ibm-secrets-manager.json` and the doc are copied into the catalog.
   - Upgrade guide entry for 4.24: a Map or a POJO body is stored as JSON in an 
arbitrary secret, not as its `toString()`.
   
   ## Not changed
   
   - updateSecret does not create versions of the other secret types 
(username_password, iam_credentials, certificates and so on): each needs its 
own version prototype of the IBM SDK. **Open question:** add them, starting 
with a new password for username_password?
   - A POJO body for createKVSecret still fails (its `toString()` is not JSON). 
It could be converted to a Map with Jackson, as an arbitrary secret now stores 
it as JSON.
   - The `CamelIbmSecretsManagerSecretPayload` and 
`CamelIbmSecretsManagerSecretData` headers are read as before, as a String and 
a Map.
   
   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