Search in sources :

Example 1 with SecretService

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

use of com.walmartlabs.concord.runtime.v2.sdk.SecretService in project concord by walmartlabs.

the class RunPlaybookTask2 method run.

private void run(Context ctx, Path workDir, Map<String, Object> args) throws Exception {
    ApiClient apiClient = apiClientFactory.create(ApiClientConfiguration.builder().context(context).build());
    AnsibleSecretServiceV1 ansibleSecretService = new AnsibleSecretServiceV1(context, secretService);
    AnsibleTask task = new AnsibleTask(apiClient, new AnsibleAuthFactory(ansibleSecretService), ansibleSecretService);
    Map<String, Object> projectInfo = getMap(context, Constants.Request.PROJECT_INFO_KEY, null);
    String orgName = projectInfo != null ? (String) projectInfo.get("orgName") : null;
    AnsibleContext context = AnsibleContext.builder().apiBaseUrl(apiClient.getBasePath()).instanceId(UUID.fromString(txId)).workDir(workDir).tmpDir(createTmpDir(workDir)).defaults(defaults != null ? defaults : Collections.emptyMap()).args(args).sessionToken(apiCfg.getSessionToken(ctx)).eventCorrelationId(ctx.getEventCorrelationId()).orgName(orgName).retryCount((Integer) ctx.getVariable(Constants.Context.CURRENT_RETRY_COUNTER)).build();
    PlaybookProcessRunner runner = new PlaybookProcessRunnerFactory(new AnsibleDockerServiceV1(ctx, dockerService), workDir).create(args);
    TaskResult.SimpleResult result = task.run(context, runner);
    result.values().forEach(ctx::setVariable);
    if (!result.ok()) {
        throw new IllegalStateException("Process finished with exit code " + result.values().get("exitCode"));
    }
}
Also used : ApiClient(com.walmartlabs.concord.ApiClient) TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult)

Example 3 with SecretService

use of com.walmartlabs.concord.runtime.v2.sdk.SecretService in project concord by walmartlabs.

the class AnsibleTaskV2 method execute.

@Override
public TaskResult execute(Variables input) throws Exception {
    Map<String, Object> in = input.toMap();
    Path workDir = context.workingDirectory();
    PlaybookProcessRunner runner = new PlaybookProcessRunnerFactory(new AnsibleDockerServiceV2(context.dockerService()), workDir).create(in);
    AnsibleSecretService secretService = new AnsibleSecretServiceV2(context.secretService());
    AnsibleTask task = new AnsibleTask(apiClient, new AnsibleAuthFactory(secretService), secretService);
    UUID instanceId = Objects.requireNonNull(context.processInstanceId());
    Path tmpDir = context.fileService().createTempDirectory("ansible");
    ProjectInfo projectInfo = context.processConfiguration().projectInfo();
    AnsibleContext ctx = AnsibleContext.builder().apiBaseUrl(apiClient.getBasePath()).instanceId(instanceId).workDir(workDir).tmpDir(tmpDir).defaults(defaults).args(in).sessionToken(context.processConfiguration().processInfo().sessionToken()).eventCorrelationId(context.execution().correlationId()).orgName(projectInfo != null ? projectInfo.orgName() : null).retryCount(ContextUtils.getCurrentRetryAttemptNumber(context)).build();
    TaskResult.SimpleResult result = task.run(ctx, runner);
    if (!result.ok()) {
        throw new IllegalStateException("Process finished with exit code " + result.values().get("exitCode"));
    }
    return result;
}
Also used : Path(java.nio.file.Path) AnsibleSecretService(com.walmartlabs.concord.plugins.ansible.secrets.AnsibleSecretService) ProjectInfo(com.walmartlabs.concord.runtime.v2.sdk.ProjectInfo) UUID(java.util.UUID)

Example 4 with SecretService

use of com.walmartlabs.concord.runtime.v2.sdk.SecretService in project concord by walmartlabs.

the class DefaultContextFactory method create.

@Override
public Context create(Runtime runtime, State state, ThreadId currentThreadId, Step currentStep, UUID correlationId) {
    ProcessDefinition pd = runtime.getService(ProcessDefinition.class);
    Compiler compiler = runtime.getService(Compiler.class);
    ExpressionEvaluator ee = runtime.getService(ExpressionEvaluator.class);
    return new ContextImpl(compiler, ee, currentThreadId, runtime, state, pd, currentStep, correlationId, workingDirectory.getValue(), processInstanceId.getValue(), fileService, dockerService, secretService, lockService, apiConfiguration, processConfiguration);
}
Also used : Compiler(com.walmartlabs.concord.runtime.v2.sdk.Compiler) ProcessDefinition(com.walmartlabs.concord.runtime.v2.model.ProcessDefinition) ExpressionEvaluator(com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)

Example 5 with SecretService

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

the class HashiVaultTask method createParams.

private TaskParams createParams(Context ctx, Map<String, Object> input) {
    final MapBackedVariables vars = new MapBackedVariables(input);
    final SecretExporterV1 exporterV1 = new SecretExporterV1(ctx, secretService);
    return TaskParams.of(vars, defaults, exporterV1);
}
Also used : MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables)

Aggregations

ApiClient (com.walmartlabs.concord.ApiClient)1 AnsibleSecretService (com.walmartlabs.concord.plugins.ansible.secrets.AnsibleSecretService)1 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 HashiVaultTask (com.walmartlabs.concord.plugins.hashivault.v2.HashiVaultTask)1 ProcessDefinition (com.walmartlabs.concord.runtime.v2.model.ProcessDefinition)1 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)1 Compiler (com.walmartlabs.concord.runtime.v2.sdk.Compiler)1 Context (com.walmartlabs.concord.runtime.v2.sdk.Context)1 MapBackedVariables (com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables)1 ProjectInfo (com.walmartlabs.concord.runtime.v2.sdk.ProjectInfo)1 SecretService (com.walmartlabs.concord.runtime.v2.sdk.SecretService)1 TaskResult (com.walmartlabs.concord.runtime.v2.sdk.TaskResult)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1