use of com.walmartlabs.concord.ApiClient 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.ApiClient in project concord by walmartlabs.
the class ApiClientFactoryImpl method create.
@Override
public ApiClient create(ApiClientConfiguration overrides) {
String baseUrl = overrides.baseUrl() != null ? overrides.baseUrl() : cfg.baseUrl();
String sessionToken = null;
if (overrides.apiKey() == null) {
sessionToken = overrides.sessionToken();
}
String apiKey = overrides.apiKey();
if (apiKey != null) {
sessionToken = null;
}
if (sessionToken == null && apiKey == null) {
throw new IllegalArgumentException("Session token or an API key is required");
}
ApiClient client = new ConcordApiClient(baseUrl, httpClient).setSessionToken(sessionToken).setApiKey(apiKey).addDefaultHeader("Accept", "*/*").setTempFolderPath(tmpDir.toString());
UUID txId = instanceId.getValue();
if (txId != null) {
client = client.setUserAgent("Concord-Runner-v2: txId=" + txId);
}
return client;
}
use of com.walmartlabs.concord.ApiClient in project concord by walmartlabs.
the class SecretClientTest method testInvalidSecretType.
@Test
public void testInvalidSecretType(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {
String orgName = "org_" + System.currentTimeMillis();
String secretName = "secret_" + System.currentTimeMillis();
stubFor(post(urlEqualTo("/api/v1/org/" + orgName + "/secret/" + secretName + "/data")).willReturn(aResponse().withStatus(200).withHeader(Constants.Headers.SECRET_TYPE, SecretEntry.TypeEnum.DATA.name()).withBody("Hello!")));
ApiClient apiClient = new ConcordApiClient("http://localhost:" + wmRuntimeInfo.getHttpPort());
SecretClient secretClient = new SecretClient(apiClient);
try {
secretClient.getData(orgName, secretName, null, SecretEntry.TypeEnum.KEY_PAIR);
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("Unexpected type of " + orgName + "/" + secretName));
}
}
use of com.walmartlabs.concord.ApiClient in project concord by walmartlabs.
the class ServerClient method createClient.
private static ApiClient createClient(String baseUrl, String apiKey, String gitHubKey) {
ApiClient c = new ConcordApiClient(baseUrl, new OkHttpClient());
c.setReadTimeout(60000);
c.setConnectTimeout(10000);
c.setWriteTimeout(60000);
c.addDefaultHeader("X-Concord-Trace-Enabled", "true");
if (apiKey != null) {
c.setApiKey(apiKey);
}
if (gitHubKey != null) {
c.addDefaultHeader("X-Hub-Signature", gitHubKey);
}
return c;
}
use of com.walmartlabs.concord.ApiClient in project concord by walmartlabs.
the class ProcessMetadataIT method list.
private List<ProcessEntry> list(String orgName, String projectName, String... kv) throws Exception {
ApiClient apiClient = getApiClient();
HttpUrl.Builder b = HttpUrl.parse(apiClient.getBasePath() + "/api/v2/process").newBuilder().addQueryParameter("orgName", orgName).addQueryParameter("projectName", projectName);
for (int i = 0; i < kv.length - 1; i += 2) {
b.addQueryParameter(kv[i], kv[i + 1]);
}
Request req = new Request.Builder().url(b.build()).header("Authorization", ServerClient.DEFAULT_API_KEY).build();
OkHttpClient httpClient = apiClient.getHttpClient();
Response resp = null;
try {
resp = httpClient.newCall(req).execute();
if (!resp.isSuccessful()) {
throw new RuntimeException("Request failed: " + resp);
}
ObjectMapper om = new ObjectMapper();
// to parse timestamps
om.registerModule(new ServerCompatModule());
return om.readValue(resp.body().byteStream(), LIST_OF_PROCESS_ENTRIES);
} finally {
if (resp != null && resp.body() != null) {
resp.body().close();
}
}
}
Aggregations