Search in sources :

Example 1 with Task

use of com.walmartlabs.concord.runtime.v2.sdk.Task in project concord-plugins by walmartlabs.

the class GitTaskV2Test method test.

@Test
public void test() throws Exception {
    Map<String, Object> input = new HashMap<>();
    input.put(GitTask.ACTION_KEY, GitTask.Action.CLONE.name());
    input.put(GitTask.GIT_URL, "https://github.com/walmartlabs/concord-plugins.git");
    GitTaskV2 task = new GitTaskV2(mock(SecretService.class), new WorkingDirectory(workDir));
    TaskResult.SimpleResult result = task.execute(new MapBackedVariables(input));
    assertTrue(result.ok());
}
Also used : WorkingDirectory(com.walmartlabs.concord.runtime.v2.sdk.WorkingDirectory) MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) HashMap(java.util.HashMap) TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) SecretService(com.walmartlabs.concord.runtime.v2.sdk.SecretService) Test(org.junit.Test)

Example 2 with Task

use of com.walmartlabs.concord.runtime.v2.sdk.Task 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 3 with Task

use of com.walmartlabs.concord.runtime.v2.sdk.Task 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());
}
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) Test(org.junit.Test)

Example 4 with Task

use of com.walmartlabs.concord.runtime.v2.sdk.Task in project concord-plugins by walmartlabs.

the class PuppetTaskV2Test method testNoCertValidation.

@Test
public void testNoCertValidation() throws Exception {
    // -- Task in-vars
    variables.put("action", "pql");
    variables.put("queryString", "inventory[certname]{ limit 10 }");
    variables.put("databaseUrl", httpsRule.baseUrl());
    // Self-signed cert will fail unless we provide a cert to trust
    try {
        task.execute(input);
        fail("Task should fail when self-signed cert is used without a provided certificate to trust.");
    } catch (SSLHandshakeException expected) {
        // that's fine
        log.info("hit expected ssl exception. Not a problem");
    } catch (Exception e) {
        log.error(e.getMessage());
        throw e;
    }
    // -- Task in-vars - disable certificate verification
    variables.put("validateCerts", false);
    // -- Execute - now it should work
    TaskResult.SimpleResult result = task.execute(input);
    assertNotNull(result);
    assertTrue(result.ok());
    List data = (List) result.values().get("data");
    assertEquals(10, data.size());
}
Also used : TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) List(java.util.List) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) MissingParameterException(com.walmartlabs.concord.plugins.puppet.model.exception.MissingParameterException) Test(org.junit.Test)

Example 5 with Task

use of com.walmartlabs.concord.runtime.v2.sdk.Task in project concord-plugins by walmartlabs.

the class PuppetTaskV2Test method testSelfSignedCertWithText.

@Test
public void testSelfSignedCertWithText() throws Exception {
    // -- Task in-vars
    variables.put("action", "pql");
    variables.put("queryString", "inventory[certname]{ limit 10 }");
    variables.put("databaseUrl", httpsRule.baseUrl());
    // Self-signed cert will fail unless we provide a cert to trust
    try {
        task.execute(input);
        fail("Task should fail when self-signed cert is used without a provided certificate to trust.");
    } catch (SSLHandshakeException expected) {
        // that's fine
        log.info("hit expected ssl exception. Not a problem");
    } catch (Exception e) {
        log.error(e.getMessage());
        throw e;
    }
    // -- Task in-vars - add certificate info (text)
    Map<String, Object> certificate = new HashMap<>();
    certificate.put("text", getWiremockCertString());
    variables.put("certificate", certificate);
    // -- Execute - now it should work
    TaskResult.SimpleResult result = task.execute(input);
    assertNotNull(result);
    assertTrue(result.ok());
    List data = (List) result.values().get("data");
    assertEquals(10, data.size());
}
Also used : HashMap(java.util.HashMap) TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) List(java.util.List) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) MissingParameterException(com.walmartlabs.concord.plugins.puppet.model.exception.MissingParameterException) Test(org.junit.Test)

Aggregations

TaskResult (com.walmartlabs.concord.runtime.v2.sdk.TaskResult)7 Test (org.junit.Test)7 TaskProviders (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)6 HashMap (java.util.HashMap)5 List (java.util.List)5 MissingParameterException (com.walmartlabs.concord.plugins.puppet.model.exception.MissingParameterException)4 MapBackedVariables (com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables)4 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)4 Step (com.walmartlabs.concord.runtime.v2.model.Step)3 TaskCallInterceptor (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Test (org.junit.jupiter.api.Test)3 TaskCall (com.walmartlabs.concord.runtime.v2.model.TaskCall)2 TaskCallOptions (com.walmartlabs.concord.runtime.v2.model.TaskCallOptions)2 CallContext (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext)2 TaskException (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException)2 Task (com.walmartlabs.concord.runtime.v2.sdk.Task)2 Variables (com.walmartlabs.concord.runtime.v2.sdk.Variables)2 Frame (com.walmartlabs.concord.svm.Frame)2 AbstractModule (com.google.inject.AbstractModule)1