use of com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables in project concord-plugins by walmartlabs.
the class UnitTest method invalidActionTest.
@Test(expected = IllegalArgumentException.class)
public void invalidActionTest() {
Map<String, Object> vars = new HashMap<>();
vars.put("action", "not-an-action");
TaskParams.of(new MapBackedVariables(vars), null, exporter);
}
use of com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables in project concord-plugins by walmartlabs.
the class UnitTest method mapDataTest.
/**
* The data returned by the task may be either a Map containing all of the
* key/value pairs in the Vault secret OR a single String value from the
* Vault secret when a specific secret "key" is specified.
*/
@Test
public void mapDataTest() {
Variables vars = new MapBackedVariables(getMap("path", "secret/mysecret"));
TaskParams params = TaskParams.of(vars, null, exporter);
HashiVaultTaskResult result = HashiVaultTaskResult.of(true, getMap("top_secret", "value"), null, params);
try {
String s = result.data();
fail("data should be Map when key param is not given");
} catch (ClassCastException e) {
// that's expected
}
// this should work
Map<String, Object> m = result.data();
assertEquals(1, m.size());
}
use of com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables in project concord-plugins by walmartlabs.
the class TaskParams method of.
public static TaskParams of(Variables input, Map<String, Object> defaults, SecretExporter secretExporter) {
Map<String, Object> variablesMap = new HashMap<>(defaults != null ? defaults : Collections.emptyMap());
variablesMap.putAll(input.toMap());
if (variablesMap.containsKey(API_TOKEN_SECRET_KEY)) {
Map<String, Object> tokenSecret = MapUtils.assertMap(variablesMap, API_TOKEN_SECRET_KEY);
variablesMap.put(API_TOKEN_KEY, exportToken(secretExporter, tokenSecret));
}
Variables variables = new MapBackedVariables(variablesMap);
TaskParams p = new TaskParams(variables);
switch(p.action()) {
case READKV:
case WRITEKV:
return new TaskParams(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 SmtpTaskV2Test method testWithBothDefaults.
@Test
public void testWithBothDefaults() throws Exception {
Map<String, Object> policyDefaults = new HashMap<>();
policyDefaults.put("host", "badserver");
policyDefaults.put("port", -1);
// Process arg defaults override policy defaults
Map<String, Object> processArgsDefaults = new HashMap<>();
processArgsDefaults.put("host", "localhost");
processArgsDefaults.put("port", mailServer.getSmtp().getPort());
Map<String, Object> mail = new HashMap<>();
mail.put("from", "me@localhost");
mail.put("to", "you@localhost");
mail.put("message", "Default vars from process arguments.");
Context ctx = mock(Context.class);
when(ctx.workingDirectory()).thenReturn(Paths.get(System.getProperty("user.dir")));
when(ctx.variables()).thenReturn(new MapBackedVariables(Collections.singletonMap("smtpParams", processArgsDefaults)));
when(ctx.defaultVariables()).thenReturn(new MapBackedVariables(policyDefaults));
SmtpTaskV2 t = new SmtpTaskV2(ctx);
t.execute(new MapBackedVariables(Collections.singletonMap("mail", mail)));
MimeMessage[] messages = mailServer.getReceivedMessages();
assertEquals(1, messages.length);
assertEquals("Default vars from process arguments.\r\n", messages[0].getContent());
}
use of com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables in project concord by walmartlabs.
the class SmtpTaskV2Test method testWithPolicyDefaults.
@Test
public void testWithPolicyDefaults() throws Exception {
Map<String, Object> smtpParams = new HashMap<>();
smtpParams.put("host", "localhost");
smtpParams.put("port", mailServer.getSmtp().getPort());
Map<String, Object> mail = new HashMap<>();
mail.put("from", "me@localhost");
mail.put("to", "you@localhost");
mail.put("message", "Default vars from policy.");
Context ctx = mock(Context.class);
when(ctx.workingDirectory()).thenReturn(Paths.get(System.getProperty("user.dir")));
when(ctx.variables()).thenReturn(new MapBackedVariables(Collections.emptyMap()));
when(ctx.defaultVariables()).thenReturn(new MapBackedVariables(smtpParams));
SmtpTaskV2 t = new SmtpTaskV2(ctx);
t.execute(new MapBackedVariables(Collections.singletonMap("mail", mail)));
MimeMessage[] messages = mailServer.getReceivedMessages();
assertEquals(1, messages.length);
assertEquals("Default vars from policy.\r\n", messages[0].getContent());
}
Aggregations