Search in sources :

Example 16 with ApiClient

use of com.walmartlabs.concord.ApiClient in project concord by walmartlabs.

the class SecretServiceImpl method decryptString.

@Override
public String decryptString(Context ctx, String instanceId, String s) throws Exception {
    byte[] input;
    try {
        input = DatatypeConverter.parseBase64Binary(s);
    } catch (Exception e) {
        throw new IllegalArgumentException("Invalid encrypted string value, please verify that it was specified/copied correctly: " + e.getMessage());
    }
    ApiClient c = clientFactory.create(ctx);
    String path = "/api/v1/process/" + instanceId + "/decrypt";
    ApiResponse<byte[]> r = ClientUtils.withRetry(RETRY_COUNT, RETRY_INTERVAL, () -> {
        Type returnType = new TypeToken<byte[]>() {
        }.getType();
        return ClientUtils.postData(c, path, input, returnType);
    });
    return new String(r.getData());
}
Also used : Type(java.lang.reflect.Type) ApiClient(com.walmartlabs.concord.ApiClient) ApiException(com.walmartlabs.concord.ApiException) SecretNotFoundException(com.walmartlabs.concord.sdk.SecretNotFoundException) IOException(java.io.IOException)

Example 17 with ApiClient

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.getBaseUrl();
    String sessionToken = null;
    if (overrides.apiKey() == null) {
        sessionToken = overrides.sessionToken();
        Context ctx = overrides.context();
        if (sessionToken == null && ctx != null) {
            sessionToken = cfg.getSessionToken(ctx);
        }
    }
    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 = getTxId(overrides);
    if (txId != null) {
        client = client.setUserAgent("Concord-Runner: txId=" + txId);
    }
    return client;
}
Also used : SSLContext(javax.net.ssl.SSLContext) Context(com.walmartlabs.concord.sdk.Context) ConcordApiClient(com.walmartlabs.concord.client.ConcordApiClient) ConcordApiClient(com.walmartlabs.concord.client.ConcordApiClient) ApiClient(com.walmartlabs.concord.ApiClient) UUID(java.util.UUID)

Example 18 with ApiClient

use of com.walmartlabs.concord.ApiClient in project concord by walmartlabs.

the class Main method main.

public static void main(String[] args) throws Exception {
    RunnerConfiguration runnerCfg = readRunnerConfiguration(args);
    // create the inject with all dependencies and services available before
    // the actual process' working directory is ready. It allows us to load
    // all dependencies and have them available in "pre-fork" situations
    Injector injector = InjectorFactory.createDefault(runnerCfg);
    try {
        ProcessConfiguration processCfg = injector.getInstance(ProcessConfiguration.class);
        ApiClient apiClient = injector.getInstance(ApiClient.class);
        ProcessHeartbeat heartbeat = new ProcessHeartbeat(apiClient, processCfg.instanceId(), runnerCfg.api().maxNoHeartbeatInterval());
        heartbeat.start();
        Main main = injector.getInstance(Main.class);
        main.execute();
        System.exit(0);
    } catch (MultiException e) {
        log.error(e.getMessage());
        System.exit(1);
    } catch (Throwable t) {
        log.error("", t);
        System.exit(1);
    }
}
Also used : ProcessHeartbeat(com.walmartlabs.concord.runtime.common.ProcessHeartbeat) ProcessConfiguration(com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration) Injector(com.google.inject.Injector) RunnerConfiguration(com.walmartlabs.concord.runtime.common.cfg.RunnerConfiguration) ApiClient(com.walmartlabs.concord.ApiClient) MultiException(com.walmartlabs.concord.svm.MultiException)

Example 19 with ApiClient

use of com.walmartlabs.concord.ApiClient in project concord by walmartlabs.

the class GitHubNonOrgEventIt method githubEvent.

private void githubEvent(String eventFile, String repoName, String eventName) throws Exception {
    String event = new String(Files.readAllBytes(Paths.get(GitHubNonOrgEventIt.class.getResource(eventFile).toURI())));
    if (repoName != null) {
        event = event.replace("org-repo", repoName);
    }
    ApiClient client = getApiClient();
    client.addDefaultHeader("X-Hub-Signature", "sha1=" + GitHubUtils.sign(event));
    GitHubEventsApi gitHubEvents = new GitHubEventsApi(client);
    String result = gitHubEvents.onEvent(event, "abc", eventName);
    assertEquals("ok", result);
}
Also used : ApiClient(com.walmartlabs.concord.ApiClient)

Example 20 with ApiClient

use of com.walmartlabs.concord.ApiClient in project concord by walmartlabs.

the class InventoryQueryIT method testDifferentContentTypes.

@Test
public void testDifferentContentTypes() throws Exception {
    ApiClient client = getApiClient();
    OrganizationsApi organizationsApi = new OrganizationsApi(getApiClient());
    String orgName = "org_" + randomString();
    organizationsApi.createOrUpdate(new OrganizationEntry().setName(orgName));
    InventoriesApi inventoriesApi = new InventoriesApi(getApiClient());
    String inventoryName = "inventory_" + randomString();
    inventoriesApi.createOrUpdate(orgName, new InventoryEntry().setName(inventoryName));
    // ---
    assertQuery(client, orgName, inventoryName, "q1_" + randomString(), "text/plain");
    assertQuery(client, orgName, inventoryName, "q2_" + randomString(), "application/json");
}
Also used : ApiClient(com.walmartlabs.concord.ApiClient) Test(org.junit.jupiter.api.Test)

Aggregations

ApiClient (com.walmartlabs.concord.ApiClient)27 Test (org.junit.jupiter.api.Test)7 ITUtils.randomString (com.walmartlabs.concord.it.common.ITUtils.randomString)4 ConcordProcess (ca.ibodrov.concord.testcontainers.ConcordProcess)3 Payload (ca.ibodrov.concord.testcontainers.Payload)3 TaskResult (com.walmartlabs.concord.runtime.v2.sdk.TaskResult)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 OkHttpClient (com.squareup.okhttp.OkHttpClient)2 ApiException (com.walmartlabs.concord.ApiException)2 ConcordApiClient (com.walmartlabs.concord.client.ConcordApiClient)2 ProcessHeartbeat (com.walmartlabs.concord.runtime.common.ProcessHeartbeat)2 Path (java.nio.file.Path)2 UUID (java.util.UUID)2 WebElement (org.openqa.selenium.WebElement)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 WireMockTest (com.github.tomakehurst.wiremock.junit5.WireMockTest)1 Injector (com.google.inject.Injector)1 HttpUrl (com.squareup.okhttp.HttpUrl)1 Request (com.squareup.okhttp.Request)1