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

duncangrant pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git


The following commit(s) were added to refs/heads/master by this push:
     new 7d15614  Support newer versions of Hashicorp Vault
     new 1b8ddc6  Merge pull request #1136 from rdowner/hashicorp-vault-updates
7d15614 is described below

commit 7d156145f53ada08bfd86d4590e5179fe312d04d
Author: Richard Downer <rich...@apache.org>
AuthorDate: Wed Jan 13 22:48:03 2021 +0000

    Support newer versions of Hashicorp Vault
    
    Tested with Vault version 1.6.0.
---
 .../vault/VaultExternalConfigSupplier.java         | 25 ++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git 
a/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultExternalConfigSupplier.java
 
b/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultExternalConfigSupplier.java
index f610e01..864574c 100644
--- 
a/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultExternalConfigSupplier.java
+++ 
b/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultExternalConfigSupplier.java
@@ -55,6 +55,8 @@ public abstract class VaultExternalConfigSupplier extends 
AbstractExternalConfig
     protected final Gson gson;
     protected final String endpoint;
     protected final String path;
+    protected final String mountPoint;
+    protected final int version;
     protected final String token;
     protected final ImmutableMap<String, String> headersWithToken;
 
@@ -70,6 +72,18 @@ public abstract class VaultExternalConfigSupplier extends 
AbstractExternalConfig
         if (Strings.isBlank(endpoint)) errors.add("missing configuration 
'endpoint'");
         path = config.get("path");
         if (Strings.isBlank(path)) errors.add("missing configuration 'path'");
+        String version = config.get("kv-api-version");
+        if (Strings.isBlank(version) || "1".equals(version)) {
+            this.version = 1;
+        } else if ("2".equals(version)) {
+            this.version = 2;
+        } else {
+            this.version = -1; // satisfy the static analysis :)
+            errors.add("'kv-api-version' must be either 1 or 2");
+        }
+        mountPoint = config.get("mountPoint");
+        if (Strings.isBlank(mountPoint) && this.version == 2) 
errors.add("missing configuration 'mountPoint'");
+        if (!Strings.isBlank(mountPoint) && this.version == 1) 
errors.add("'mountPoint' is only applicable when kv-api-version=2");
         if (!errors.isEmpty()) {
             String message = String.format("Problem configuration Vault 
external config supplier '%s': %s",
                     name, Joiner.on(System.lineSeparator()).join(errors));
@@ -87,8 +101,15 @@ public abstract class VaultExternalConfigSupplier extends 
AbstractExternalConfig
 
     @Override
     public String get(String key) {
-        JsonObject response = apiGet(Urls.mergePaths("v1", path), 
headersWithToken);
-        return response.getAsJsonObject("data").get(key).getAsString();
+        String urlPath = (version == 1)
+            ? Urls.mergePaths("v1", path)
+            : Urls.mergePaths("v1", mountPoint, "data", path);
+        JsonObject response = apiGet(urlPath, headersWithToken);
+        JsonElement jsonElement = (version == 1)
+            ? response.getAsJsonObject("data").get(key)
+            : 
response.getAsJsonObject("data").getAsJsonObject("data").get(key);
+        String asString = jsonElement.getAsString();
+        return asString;
     }
 
     /**

Reply via email to