Search in sources :

Example 1 with HashiVaultTask

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"));
}
Also used : HashMap(java.util.HashMap) HashiVaultTask(com.walmartlabs.concord.plugins.hashivault.v1.HashiVaultTask) Test(org.junit.Test)

Example 2 with HashiVaultTask

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);
}
Also used : Context(com.walmartlabs.concord.runtime.v2.sdk.Context) MockSecretServiceV2(com.walmartlabs.concord.plugins.hashivault.model.MockSecretServiceV2) MockSecretServiceDelegate(com.walmartlabs.concord.plugins.hashivault.model.MockSecretServiceDelegate) MockContextV2(com.walmartlabs.concord.plugins.hashivault.model.MockContextV2) HashMap(java.util.HashMap) HashiVaultTask(com.walmartlabs.concord.plugins.hashivault.v2.HashiVaultTask) SecretService(com.walmartlabs.concord.runtime.v2.sdk.SecretService)

Example 3 with HashiVaultTask

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"));
}
Also used : MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) Variables(com.walmartlabs.concord.runtime.v2.sdk.Variables) MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) HashiVaultTask(com.walmartlabs.concord.plugins.hashivault.v2.HashiVaultTask) HashMap(java.util.HashMap) SimpleResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult.SimpleResult)

Example 4 with HashiVaultTask

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"));
}
Also used : HashMap(java.util.HashMap) HashiVaultTask(com.walmartlabs.concord.plugins.hashivault.v2.HashiVaultTask) Test(org.junit.Test)

Example 5 with HashiVaultTask

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"));
}
Also used : HashMap(java.util.HashMap) HashiVaultTask(com.walmartlabs.concord.plugins.hashivault.v1.HashiVaultTask) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)7 HashiVaultTask (com.walmartlabs.concord.plugins.hashivault.v2.HashiVaultTask)4 Test (org.junit.Test)4 HashiVaultTask (com.walmartlabs.concord.plugins.hashivault.v1.HashiVaultTask)3 MockContextV2 (com.walmartlabs.concord.plugins.hashivault.model.MockContextV2)1 MockSecretServiceDelegate (com.walmartlabs.concord.plugins.hashivault.model.MockSecretServiceDelegate)1 MockSecretServiceV2 (com.walmartlabs.concord.plugins.hashivault.model.MockSecretServiceV2)1 Context (com.walmartlabs.concord.runtime.v2.sdk.Context)1 MapBackedVariables (com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables)1 SecretService (com.walmartlabs.concord.runtime.v2.sdk.SecretService)1 SimpleResult (com.walmartlabs.concord.runtime.v2.sdk.TaskResult.SimpleResult)1 Variables (com.walmartlabs.concord.runtime.v2.sdk.Variables)1