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);
}
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"));
}
}
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;
}
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);
}
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);
}
Aggregations