brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drigod...@apache.org
Subject [1/2] brooklyn-server git commit: Useful getDataAsStringMap for VaultExternalConfigSupplier
Date Tue, 25 Jul 2017 10:11:23 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 2b7a6bcc1 -> 6881d354e


Useful getDataAsStringMap for VaultExternalConfigSupplier

`getDataAsStringMap` allows obtaining vault data with single call.


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/c9e8b22b
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/c9e8b22b
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/c9e8b22b

Branch: refs/heads/master
Commit: c9e8b22bd121ca94ff6ded324fdb8a078531fa9b
Parents: 34efce1
Author: Valentin Aitken <bostko@gmail.com>
Authored: Sat Jul 22 17:36:08 2017 +0300
Committer: Valentin Aitken <bostko@gmail.com>
Committed: Sat Jul 22 17:36:08 2017 +0300

----------------------------------------------------------------------
 .../external/vault/VaultExternalConfigSupplier.java    | 13 +++++++++++++
 1 file changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c9e8b22b/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultExternalConfigSupplier.java
----------------------------------------------------------------------
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 f58dbc5..23f5139 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
@@ -21,7 +21,10 @@ package org.apache.brooklyn.core.config.external.vault;
 import java.io.UnsupportedEncodingException;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
+import com.google.common.collect.Maps;
+import com.google.gson.JsonElement;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.core.config.external.AbstractExternalConfigSupplier;
 import org.apache.brooklyn.util.exceptions.Exceptions;
@@ -89,6 +92,16 @@ public abstract class VaultExternalConfigSupplier extends AbstractExternalConfig
         return response.getAsJsonObject("data").get(key).getAsString();
     }
 
+    /**
+     * Obtains data stored in <code>path</code>.
+     */
+    public Map<String, String> getDataAsStringMap() {
+        JsonObject response = apiGet(Urls.mergePaths("v1", path), headersWithToken);
+        Map<String, JsonElement> dataMap = response.getAsJsonObject("data").entrySet().stream()
+                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+        return Maps.transformValues(dataMap, jsonElement -> jsonElement.getAsString());
+    }
+
     protected JsonObject apiGet(String path, ImmutableMap<String, String> headers)
{
         try {
             String uri = Urls.mergePaths(endpoint, path);


Mime
View raw message