gnodet-bot commented on code in PR #29100:
URL: https://github.com/apache/camel/pull/29100#discussion_r4457971286


##########
components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/HashicorpVaultProducer.java:
##########
@@ -91,24 +96,65 @@ private void getSecret(Exchange exchange) {
     private void deleteSecret(Exchange exchange) {
         String secretPath = getSecretPath(exchange);
         VaultKeyValueOperations keyValue
-                = 
getEndpoint().getVaultTemplate().opsForKeyValue(getEndpoint().getConfiguration().getSecretsEngine(),
+                = 
getEndpoint().getVaultTemplate().opsForKeyValue(getEnginePath(),
                         
VaultKeyValueOperationsSupport.KeyValueBackend.versioned());
         keyValue.delete(secretPath);
     }
 
     private void listSecrets(Exchange exchange) {
-        List<String> secretsList = new ArrayList<>();
-        if (!getEndpoint().getConfiguration().isCloud()) {
-            secretsList = getEndpoint().getVaultTemplate()
-                    .list(getEndpoint().getConfiguration().getSecretsEngine() 
+ "/" + "metadata" + "/");
-        } else {
-            if 
(ObjectHelper.isNotEmpty(getEndpoint().getConfiguration().getNamespace())) {
-                secretsList = getEndpoint().getVaultTemplate()
-                        .list(getEndpoint().getConfiguration().getNamespace() 
+ "/"
-                              + 
getEndpoint().getConfiguration().getSecretsEngine() + "/" + "metadata" + "/");
+        List<String> secretsList = 
getEndpoint().getVaultTemplate().list(getEnginePath() + "/" + "metadata" + "/");
+        exchange.getMessage().setBody(secretsList);
+    }
+
+    /**
+     * The path of the secrets engine: in the namespace when running on 
HashiCorp Cloud with a namespace, else the
+     * engine itself (as the secret refresh task does).
+     */
+    private String getEnginePath() {
+        String engine = getConfiguration().getSecretsEngine();
+        if (getConfiguration().isCloud() && 
ObjectHelper.isNotEmpty(getConfiguration().getNamespace())) {
+            return getConfiguration().getNamespace() + "/" + engine;
+        }
+        return engine;
+    }
+
+    /**
+     * The fields of the secret to write: a Map or a POJO as is, and text, 
bytes, a stream or a file as a JSON object.
+     */
+    private static Object getSecretBody(Exchange exchange) throws 
InvalidPayloadException {
+        // no body would write a new, empty version of the secret
+        Object body = exchange.getMessage().getMandatoryBody();
+        if (body instanceof CharSequence || body instanceof byte[] || body 
instanceof InputStream
+                || body instanceof Reader || body instanceof StreamCache || 
body instanceof WrappedFile
+                || body instanceof File || body instanceof Path) {
+            String json = exchange.getMessage().getMandatoryBody(String.class);
+            Map<?, ?> fields;
+            try {
+                fields = MAPPER.readValue(json, Map.class);

Review Comment:
   💡 **Minor:** `Map.class` produces an unchecked cast warning. Using 
`TypeReference` makes the intent explicit and eliminates the warning:
   
   ```suggestion
                   fields = MAPPER.readValue(json, new 
com.fasterxml.jackson.core.type.TypeReference<Map<String, Object>>() {});
   ```



-- 
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