use of com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables in project concord by walmartlabs.
the class ConcordTaskParams method of.
public static ConcordTaskParams of(Variables input, Map<String, Object> defaults) {
Map<String, Object> variablesMap = new HashMap<>(defaults != null ? defaults : Collections.emptyMap());
variablesMap.putAll(input.toMap());
Variables variables = new MapBackedVariables(variablesMap);
ConcordTaskParams p = new ConcordTaskParams(variables);
switch(p.action()) {
case START:
{
return new StartParams(variables);
}
case STARTEXTERNAL:
{
return new StartExternalParams(variables);
}
case FORK:
{
return new ForkParams(variables);
}
case KILL:
{
return new KillParams(variables);
}
default:
{
throw new IllegalArgumentException("Unsupported action type: " + p.action());
}
}
}
use of com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables in project concord by walmartlabs.
the class ConcordTaskParamsTest method testForks.
@Test
public void testForks() {
List<String> tags = Arrays.asList("x", "y", "z");
Map<String, Object> input = new HashMap<>();
input.put("action", "fork");
input.put("tags", tags);
input.put("forks", Arrays.asList(Collections.singletonMap("entryPoint", "aaa"), Collections.singletonMap("entryPoint", "bbb")));
ForkParams params = (ForkParams) ConcordTaskParams.of(new MapBackedVariables(input), Collections.emptyMap());
List<ForkStartParams> forks = params.forks();
assertEquals(2, forks.size());
ForkStartParams f1 = forks.get(0);
assertEquals("aaa", f1.entryPoint());
assertTrue(f1.tags().containsAll(tags));
ForkStartParams f2 = forks.get(1);
assertEquals("bbb", f2.entryPoint());
assertTrue(f2.tags().containsAll(tags));
System.out.println(params);
}
use of com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables in project concord-plugins by walmartlabs.
the class HashiVaultTaskV2Test method testReadTokenFromSecretV2.
@Test
public void testReadTokenFromSecretV2() throws Exception {
Map<String, Object> varMap = new HashMap<>();
Map<String, Object> secretInfo = new HashMap<>(3);
secretInfo.put("org", "my-org");
secretInfo.put("name", "my-secret");
varMap.put("apiTokenSecret", secretInfo);
varMap.put("baseUrl", getBaseUrl());
varMap.put("path", "cubbyhole/hello");
Variables vars = new MapBackedVariables(varMap);
SimpleResult result = getTask(false).execute(vars);
Assert.assertTrue(result.ok());
final Map<String, Object> data = MapUtils.assertMap(result.values(), "data");
assertEquals("cubbyVal", data.get("cubbyKey"));
}
use of com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables in project concord-plugins by walmartlabs.
the class HashiVaultTaskV2Test method testReadKvSingleV2.
@Test
public void testReadKvSingleV2() throws Exception {
Map<String, Object> varMap = new HashMap<>();
varMap.put("path", "secret/testing");
varMap.put("key", "db_password");
Variables vars = new MapBackedVariables(varMap);
SimpleResult result = getTask(true).execute(vars);
Assert.assertTrue(result.ok());
final String data = MapUtils.getString(result.values(), "data");
assertEquals("dbpassword1", data);
}
use of com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables in project concord-plugins by walmartlabs.
the class UnitTest method stringDataTest.
@Test
public void stringDataTest() {
Variables vars = new MapBackedVariables(getMap("path", "secret/mysecret", "key", "top_secret"));
TaskParams params = TaskParams.of(vars, null, exporter);
HashiVaultTaskResult result = HashiVaultTaskResult.of(true, getMap("top_secret", "value"), null, params);
try {
Map<String, Object> m = result.data();
fail("data should be String when key param is given");
} catch (ClassCastException e) {
// that's expected
}
// this should work
String s = result.data();
assertEquals("value", s);
}
Aggregations