This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch CAMEL-21172
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 559e4816c46a2bad0f1632ff4dd7425aa7db5f64
Author: Andrea Cosentino <[email protected]>
AuthorDate: Thu Sep 5 15:31:30 2024 +0200

    CAMEL-21172 - Camel-Jbang Dev Console: Add Hashicorp Vault support
    
    Signed-off-by: Andrea Cosentino <[email protected]>
---
 .../apache/camel/catalog/dev-consoles.properties   |  1 +
 .../catalog/dev-consoles/hashicorp-secrets.json    | 15 +++++
 .../camel/dev-console/hashicorp-secrets.json       | 15 +++++
 .../org/apache/camel/dev-console/hashicorp-secrets |  2 +
 .../org/apache/camel/dev-consoles.properties       |  7 ++
 .../hashicorp/vault/SecretsDevConsole.java         | 76 ++++++++++++++++++++++
 .../camel/cli/connector/LocalCliConnector.java     | 10 +++
 .../dsl/jbang/core/commands/process/ListVault.java |  8 +++
 8 files changed, 134 insertions(+)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles.properties
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles.properties
index 0d11272191f..e624c627a45 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles.properties
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles.properties
@@ -13,6 +13,7 @@ event
 fault-tolerance
 gc
 gcp-secrets
+hashicorp-secrets
 health
 inflight
 java-security
diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/hashicorp-secrets.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/hashicorp-secrets.json
new file mode 100644
index 00000000000..c23a6e2ee9f
--- /dev/null
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/hashicorp-secrets.json
@@ -0,0 +1,15 @@
+{
+  "console": {
+    "kind": "console",
+    "group": "camel",
+    "name": "hashicorp-secrets",
+    "title": "Hashicorp Secrets",
+    "description": "Hashicorp Vault Secrets",
+    "deprecated": false,
+    "javaType": "org.apache.camel.component.hashicorp.vault.SecretsDevConsole",
+    "groupId": "org.apache.camel",
+    "artifactId": "camel-hashicorp-vault",
+    "version": "4.8.0-SNAPSHOT"
+  }
+}
+
diff --git 
a/components/camel-hashicorp-vault/src/generated/resources/META-INF/org/apache/camel/dev-console/hashicorp-secrets.json
 
b/components/camel-hashicorp-vault/src/generated/resources/META-INF/org/apache/camel/dev-console/hashicorp-secrets.json
new file mode 100644
index 00000000000..c23a6e2ee9f
--- /dev/null
+++ 
b/components/camel-hashicorp-vault/src/generated/resources/META-INF/org/apache/camel/dev-console/hashicorp-secrets.json
@@ -0,0 +1,15 @@
+{
+  "console": {
+    "kind": "console",
+    "group": "camel",
+    "name": "hashicorp-secrets",
+    "title": "Hashicorp Secrets",
+    "description": "Hashicorp Vault Secrets",
+    "deprecated": false,
+    "javaType": "org.apache.camel.component.hashicorp.vault.SecretsDevConsole",
+    "groupId": "org.apache.camel",
+    "artifactId": "camel-hashicorp-vault",
+    "version": "4.8.0-SNAPSHOT"
+  }
+}
+
diff --git 
a/components/camel-hashicorp-vault/src/generated/resources/META-INF/services/org/apache/camel/dev-console/hashicorp-secrets
 
b/components/camel-hashicorp-vault/src/generated/resources/META-INF/services/org/apache/camel/dev-console/hashicorp-secrets
new file mode 100644
index 00000000000..62a9f182cb0
--- /dev/null
+++ 
b/components/camel-hashicorp-vault/src/generated/resources/META-INF/services/org/apache/camel/dev-console/hashicorp-secrets
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.hashicorp.vault.SecretsDevConsole
diff --git 
a/components/camel-hashicorp-vault/src/generated/resources/META-INF/services/org/apache/camel/dev-consoles.properties
 
b/components/camel-hashicorp-vault/src/generated/resources/META-INF/services/org/apache/camel/dev-consoles.properties
new file mode 100644
index 00000000000..1639643e2fe
--- /dev/null
+++ 
b/components/camel-hashicorp-vault/src/generated/resources/META-INF/services/org/apache/camel/dev-consoles.properties
@@ -0,0 +1,7 @@
+# Generated by camel build tools - do NOT edit this file!
+dev-consoles=hashicorp-secrets
+groupId=org.apache.camel
+artifactId=camel-hashicorp-vault
+version=4.8.0-SNAPSHOT
+projectName=Camel :: Hashicorp :: Key Vault
+projectDescription=Camel Hashicorp Vault Component
diff --git 
a/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/SecretsDevConsole.java
 
b/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/SecretsDevConsole.java
new file mode 100644
index 00000000000..686661b5e67
--- /dev/null
+++ 
b/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/SecretsDevConsole.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.hashicorp.vault;
+
+import java.util.Map;
+
+import org.apache.camel.spi.PropertiesFunction;
+import org.apache.camel.spi.annotations.DevConsole;
+import org.apache.camel.support.console.AbstractDevConsole;
+import org.apache.camel.util.json.JsonObject;
+import org.apache.camel.vault.HashicorpVaultConfiguration;
+
+@DevConsole(name = "hashicorp-secrets", displayName = "Hashicorp Secrets", 
description = "Hashicorp Vault Secrets")
+public class SecretsDevConsole extends AbstractDevConsole {
+
+    private HashicorpVaultPropertiesFunction propertiesFunction;
+
+    public SecretsDevConsole() {
+        super("camel", "hashicorp-secrets", "Hashicorp Secrets", "Hashicorp 
Vault Secrets");
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+
+        if 
(getCamelContext().getPropertiesComponent().hasPropertiesFunction("hashicorp")) 
{
+            PropertiesFunction pf = 
getCamelContext().getPropertiesComponent().getPropertiesFunction("hashicorp");
+            if (pf instanceof HashicorpVaultPropertiesFunction) {
+                propertiesFunction = (HashicorpVaultPropertiesFunction) pf;
+            }
+        }
+    }
+
+    @Override
+    protected String doCallText(Map<String, Object> options) {
+        StringBuilder sb = new StringBuilder();
+
+        HashicorpVaultConfiguration hashicorp = 
getCamelContext().getVaultConfiguration().getHashicorpVaultConfiguration();
+        sb.append("Hashicorp Vault Secrets:");
+        if (hashicorp != null) {
+            sb.append(String.format("\n    Host: %s", hashicorp.getHost()));
+            sb.append(String.format("\n    Port: %s", hashicorp.getPort()));
+            sb.append(String.format("\n    Scheme: %s", 
hashicorp.getScheme()));
+            sb.append("\n    Login: OAuth Token");
+        }
+
+        return sb.toString();
+    }
+
+    @Override
+    protected JsonObject doCallJson(Map<String, Object> options) {
+        JsonObject root = new JsonObject();
+        HashicorpVaultConfiguration hashicorp = 
getCamelContext().getVaultConfiguration().getHashicorpVaultConfiguration();
+        if (hashicorp != null) {
+            root.put("host", hashicorp.getHost());
+            root.put("port", hashicorp.getPort());
+            root.put("scheme", hashicorp.getScheme());
+            root.put("login", "OAuth Token");
+        }
+        return root;
+    }
+}
diff --git 
a/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/LocalCliConnector.java
 
b/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/LocalCliConnector.java
index 203520a614d..4e12a61fd7d 100644
--- 
a/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/LocalCliConnector.java
+++ 
b/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/LocalCliConnector.java
@@ -1239,6 +1239,16 @@ public class LocalCliConnector extends ServiceSupport 
implements CliConnector, C
                 root.put("kubernetes-secrets", json);
             }
         }
+
+        // hashicorp-secrets is optional
+        Optional<DevConsole> dcHashicorp
+                = 
PluginHelper.getDevConsoleResolver(camelContext).lookupDevConsole("hashicorp-secrets");
+        if (dcHashicorp.isPresent()) {
+            JsonObject json = (JsonObject) 
dcHashicorp.get().call(DevConsole.MediaType.JSON);
+            if (json != null) {
+                root.put("hashicorp-secrets", json);
+            }
+        }
         return root;
     }
 
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListVault.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListVault.java
index e5d679d5149..5a08c5443f8 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListVault.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListVault.java
@@ -153,6 +153,14 @@ public class ListVault extends ProcessWatchCommand {
                                     rows.add(row);
                                 }
                             }
+
+                            JsonObject hashicorp = (JsonObject) 
vaults.get("hashicorp-secrets");
+                            if (hashicorp != null) {
+                                row.vault = "Hashicorp";
+                                row.lastCheck = 
hashicorp.getLongOrDefault("startCheckTimestamp", 0);
+                                row.lastReload = 
hashicorp.getLongOrDefault("lastReloadTimestamp", 0);
+                                rows.add(row);
+                            }
                         }
                     }
                 });

Reply via email to