Search in sources :

Example 6 with Variables

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

use of com.walmartlabs.concord.runtime.v2.sdk.Variables 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());
    }
}
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) HashMap(java.util.HashMap)

Example 8 with Variables

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

the class TeamsV2TaskParams method of.

public static TeamsV2TaskParams of(Variables input, Map<String, Object> defaults) {
    Variables variables = Utils.merge(input, defaults);
    Action action = new TeamsV2TaskParams(variables).action();
    switch(action) {
        case CREATECONVERSATION:
            {
                return new CreateConversationParams(variables);
            }
        case REPLYTOCONVERSATION:
            {
                return new ReplayToConversationParams(variables);
            }
        default:
            throw new IllegalArgumentException("Unsupported action type: " + action);
    }
}
Also used : Variables(com.walmartlabs.concord.runtime.v2.sdk.Variables)

Example 9 with Variables

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

the class TeamsV2TaskV2 method execute.

@Override
public TaskResult execute(Variables input) {
    Result r = delegate.execute(TeamsV2TaskParams.of(input, context.defaultVariables().toMap()));
    TaskResult.SimpleResult result = TaskResult.of(r.isOk(), r.getError()).value("data", r.getData());
    if (r.getActivityId() != null && r.getConversationId().contains(r.getActivityId())) {
        result.value("conversationId", r.getConversationId()).value("activityId", r.getActivityId());
    }
    return result;
}
Also used : TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) Result(com.walmartlabs.concord.plugins.msteams.Result)

Example 10 with Variables

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

the class TaskParams method of.

public static TaskParams of(Variables input, Map<String, Object> defaults) {
    Variables variables = merge(input, defaults);
    Action action = new TaskParams(variables).action();
    switch(action) {
        case ADDCOMMENT:
            {
                return new AddCommentParams(variables);
            }
        case CREATECOMPONENT:
            {
                return new CreateComponentParams(variables);
            }
        case CREATEISSUE:
            {
                return new CreateIssueParams(variables);
            }
        case DELETECOMPONENT:
            {
                return new DeleteComponentParams(variables);
            }
        case DELETEISSUE:
            {
                return new DeleteIssueParams(variables);
            }
        case TRANSITION:
            {
                return new TransitionParams(variables);
            }
        case UPDATEISSUE:
            {
                return new UpdateIssueParams(variables);
            }
        case CREATESUBTASK:
            {
                return new CreateSubTaskParams(variables);
            }
        case CURRENTSTATUS:
            {
                return new CurrentStatusParams(variables);
            }
        case ADDATTACHMENT:
            {
                return new AddAttachmentParams(variables);
            }
        case GETISSUES:
            {
                return new GetIssuesParams(variables);
            }
        default:
            throw new IllegalArgumentException("Unsupported action type: " + action);
    }
}
Also used : MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) Variables(com.walmartlabs.concord.runtime.v2.sdk.Variables)

Aggregations

Variables (com.walmartlabs.concord.runtime.v2.sdk.Variables)24 MapBackedVariables (com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables)16 HashMap (java.util.HashMap)7 Test (org.junit.Test)6 SimpleResult (com.walmartlabs.concord.runtime.v2.sdk.TaskResult.SimpleResult)5 Path (java.nio.file.Path)4 Map (java.util.Map)4 TaskProviders (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)3 UpdateLocalsCommand (com.walmartlabs.concord.runtime.v2.runner.vm.UpdateLocalsCommand)3 TaskResult (com.walmartlabs.concord.runtime.v2.sdk.TaskResult)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ProcessDefinition (com.walmartlabs.concord.runtime.v2.model.ProcessDefinition)2 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)2 com.walmartlabs.concord.runtime.v2.sdk (com.walmartlabs.concord.runtime.v2.sdk)2 ProcessConfiguration (com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration)2 Inject (javax.inject.Inject)2 Named (javax.inject.Named)2 Injector (com.google.inject.Injector)1 ApiClient (com.walmartlabs.concord.ApiClient)1 DependencyManager (com.walmartlabs.concord.dependencymanager.DependencyManager)1