Search in sources :

Example 26 with ApiClient

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

the class CustomFormsIT method test.

@SuppressWarnings("unchecked")
@Test
public void test() throws Exception {
    ApiClient client = serverRule.getClient();
    // ---
    String gitUrl = ITUtils.createGitRepo(CustomFormsIT.class, "customForm");
    // ---
    String orgName = "org_" + ITUtils.randomString();
    OrganizationsApi organizationsApi = new OrganizationsApi(client);
    organizationsApi.createOrUpdate(new OrganizationEntry().setName(orgName));
    String projectName = "project_" + ITUtils.randomString();
    String repoName = "test";
    ProjectsApi projectsApi = new ProjectsApi(client);
    projectsApi.createOrUpdate(orgName, new ProjectEntry().setName(projectName).setRepositories(Collections.singletonMap(repoName, new RepositoryEntry().setUrl(gitUrl).setBranch("master"))));
    // ---
    consoleRule.login(Concord.ADMIN_API_KEY);
    // ---
    String testValue = "test_" + ITUtils.randomString();
    String url = "/api/v1/org/" + orgName + "/project/" + projectName + "/repo/" + repoName + "/start/default?testValue=" + testValue;
    consoleRule.navigateToRelative(url);
    By selector = By.id("testValue");
    WebElement element = consoleRule.waitFor(selector);
    assertEquals(testValue, element.getText());
    Map<String, Object> formFields = (Map<String, Object>) consoleRule.executeJavaScript("return data.definitions");
    Map<String, Object> fieldX = (Map<String, Object>) formFields.get("x");
    List<Object> allowedValues = (List<Object>) fieldX.get("allow");
    assertEquals(2, allowedValues.size(), "Expression object should have added two allowed values");
}
Also used : ApiClient(com.walmartlabs.concord.ApiClient) WebElement(org.openqa.selenium.WebElement) By(org.openqa.selenium.By) List(java.util.List) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 27 with ApiClient

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

the class TerraformTaskV2 method execute.

@Override
public TaskResult execute(Variables input) throws Exception {
    Path workDir = ctx.workingDirectory();
    Map<String, Object> cfg = createCfg(workDir, input, ctx.defaultVariables());
    boolean debug = MapUtils.get(cfg, TaskConstants.DEBUG_KEY, false, Boolean.class);
    Action action = getAction(cfg);
    // configure the state backend and populate the environment with necessary parameters
    Backend backend = new BackendFactoryV2(ctx, apiClient, lockService).getBackend(cfg);
    Map<String, String> env = getEnv(cfg, backend);
    // configure the environment to support Terraform's git modules using Concord Secrets for authentication
    GitSshWrapper.SecretProvider secretProvider = (orgName, secretName, password) -> {
        SecretService.KeyPair result = secretService.exportKeyAsFile(orgName, secretName, password);
        return result.privateKey();
    };
    GitSshWrapper gitSshWrapper = GitSshWrapper.createFrom(secretProvider, workDir, cfg, debug);
    Map<String, String> baseEnv = gitSshWrapper.updateEnv(workDir, new HashMap<>());
    // configure the Terraform's binary
    TerraformBinaryResolver binaryResolver = new TerraformBinaryResolver(cfg, workDir, debug, url -> dependencyManager.resolve(URI.create(url)));
    Terraform terraform = new Terraform(binaryResolver, debug, baseEnv);
    if (debug) {
        terraform.exec(workDir, "version", "version");
    }
    try {
        TerraformActionResult result = TerraformTaskCommon.execute(terraform, action, backend, workDir, cfg, env);
        return convertResult(result);
    } finally {
        gitSshWrapper.cleanup();
    }
}
Also used : Path(java.nio.file.Path) MapUtils(com.walmartlabs.concord.sdk.MapUtils) BackendFactoryV2(com.walmartlabs.concord.plugins.terraform.backend.BackendFactoryV2) TerraformTaskCommon.getAction(com.walmartlabs.concord.plugins.terraform.TerraformTaskCommon.getAction) HashMap(java.util.HashMap) ApiClient(com.walmartlabs.concord.ApiClient) com.walmartlabs.concord.runtime.v2.sdk(com.walmartlabs.concord.runtime.v2.sdk) Inject(javax.inject.Inject) TerraformTaskCommon.getEnv(com.walmartlabs.concord.plugins.terraform.TerraformTaskCommon.getEnv) Map(java.util.Map) TerraformActionResult(com.walmartlabs.concord.plugins.terraform.actions.TerraformActionResult) Named(javax.inject.Named) URI(java.net.URI) Path(java.nio.file.Path) Collections(java.util.Collections) Backend(com.walmartlabs.concord.plugins.terraform.backend.Backend) TerraformTaskCommon.getAction(com.walmartlabs.concord.plugins.terraform.TerraformTaskCommon.getAction) Backend(com.walmartlabs.concord.plugins.terraform.backend.Backend) TerraformActionResult(com.walmartlabs.concord.plugins.terraform.actions.TerraformActionResult) BackendFactoryV2(com.walmartlabs.concord.plugins.terraform.backend.BackendFactoryV2)

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