use of com.walmartlabs.concord.plugins.hashivault.v2.HashiVaultTask in project concord-plugins by walmartlabs.
the class HashiVaultTaskV1Test method testWriteCubbyPublicMethodV1.
@Test
public void testWriteCubbyPublicMethodV1() {
String path = "cubbyhole/newSecretTaskPublicMethodV1";
Map<String, Object> kvPairs = new HashMap<>(2);
kvPairs.put("key1", "cubbyValue1");
kvPairs.put("key2", "cubbyValue2");
HashiVaultTask task = getTask(true);
task.writeKV(ctx, path, kvPairs);
// -- now get the values back
// resets context
task = getTask(true);
Map<String, Object> data = task.readKV(ctx, path);
assertEquals("cubbyValue1", MapUtils.getString(data, "key1"));
assertEquals("cubbyValue2", MapUtils.getString(data, "key2"));
}
use of com.walmartlabs.concord.plugins.hashivault.v2.HashiVaultTask in project concord-plugins by walmartlabs.
the class HashiVaultTaskV2Test method getTask.
private HashiVaultTask getTask(boolean setDefaults) {
Map<String, Object> vars = new HashMap<>();
if (setDefaults) {
Map<String, Object> defaults = new HashMap<>();
defaults.put("baseUrl", getBaseUrl());
defaults.put("apiToken", getApiToken());
vars.put("hashivaultParams", defaults);
}
Context ctx = new MockContextV2(vars, null);
SecretService s = new MockSecretServiceV2(new MockSecretServiceDelegate() {
@Override
public String exportString(String o, String n, String p) {
return getApiToken();
}
});
return new HashiVaultTask(ctx, s);
}
use of com.walmartlabs.concord.plugins.hashivault.v2.HashiVaultTask in project concord-plugins by walmartlabs.
the class HashiVaultTaskV2Test method writeAndRead.
private void writeAndRead(String path, String prefix) throws Exception {
HashiVaultTask task = getTask(true);
Map<String, Object> vars1 = new HashMap<>();
vars1.put("action", "writeKV");
vars1.put("path", path);
Map<String, Object> kvPairs = new HashMap<>(2);
kvPairs.put("key1", prefix + "Value1");
kvPairs.put("key2", prefix + "Value2");
vars1.put("kvPairs", kvPairs);
Variables input1 = new MapBackedVariables(vars1);
SimpleResult writeResult = task.execute(input1);
assertTrue(writeResult.ok());
// -- now get the values back
// resets context
task = getTask(true);
Map<String, Object> vars2 = new HashMap<>();
vars2.put("action", "readKV");
vars2.put("path", path);
Variables input2 = new MapBackedVariables(vars2);
SimpleResult readResult = task.execute(input2);
assertTrue(readResult.ok());
Map<String, Object> data = MapUtils.getMap(readResult.values(), "data", Collections.emptyMap());
assertEquals(prefix + "Value1", MapUtils.getString(data, "key1"));
assertEquals(prefix + "Value2", MapUtils.getString(data, "key2"));
}
use of com.walmartlabs.concord.plugins.hashivault.v2.HashiVaultTask in project concord-plugins by walmartlabs.
the class HashiVaultTaskV2Test method testWriteCubbyPublicMethodV2.
@Test
public void testWriteCubbyPublicMethodV2() {
String path = "cubbyhole/newSecretTaskPublicMethodV2";
Map<String, Object> kvPairs = new HashMap<>();
kvPairs.put("key1", "cubbyValue1");
kvPairs.put("key2", "cubbyValue2");
HashiVaultTask task = getTask(true);
task.writeKV(path, kvPairs);
// -- now get the values back
// resets context
task = getTask(true);
Map<String, Object> data = task.readKV(path);
assertEquals("cubbyValue1", MapUtils.getString(data, "key1"));
assertEquals("cubbyValue2", MapUtils.getString(data, "key2"));
}
use of com.walmartlabs.concord.plugins.hashivault.v2.HashiVaultTask in project concord-plugins by walmartlabs.
the class HashiVaultTaskV1Test method testWriteKvPublicMethodV1.
@Test
public void testWriteKvPublicMethodV1() {
String path = "secret/newSecretTaskPublicMethodV1";
Map<String, Object> kvPairs = new HashMap<>(2);
kvPairs.put("key1", "value1");
kvPairs.put("key2", "value2");
HashiVaultTask task = getTask(true);
task.writeKV(ctx, path, kvPairs);
// -- now get the values back
// resets context
task = getTask(true);
Map<String, Object> data = task.readKV(ctx, path);
assertEquals("value1", MapUtils.getString(data, "key1"));
assertEquals("value2", MapUtils.getString(data, "key2"));
}
Aggregations