Search in sources :

Example 1 with Context

use of com.walmartlabs.concord.sdk.Context in project concord-plugins by walmartlabs.

the class PackerTaskTest method valiateDownloadingNonDefaultVersionOfPacker.

@Test
public void valiateDownloadingNonDefaultVersionOfPacker() throws Exception {
    ToolInitializer toolInitializer = new ToolInitializer(new OKHttpDownloadManager("packer"));
    Map<String, ToolCommand> commands = ImmutableMap.of("packer/version", new Version());
    PackerTask task = new PackerTask(commands, toolInitializer);
    Map<String, Object> args = Maps.newHashMap(mapBuilder().put("version", "1.5.2").put("command", "version").put("saveOutput", true).build());
    Context context = context(args);
    task.execute(context);
    String expectedCommandLine = "packer version";
    assertThat(normalizedCommandLineArguments(context)).isEqualTo(expectedCommandLine);
    // Retrieve the logs from the context and assert we retrieved an alternate version
    assertThat(varAsString(context, "logs")).contains("Packer v1.5.2");
}
Also used : Context(com.walmartlabs.concord.sdk.Context) OKHttpDownloadManager(com.walmartlabs.concord.plugins.OKHttpDownloadManager) Version(com.walmartlabs.concord.plugins.packer.commands.Version) ToolInitializer(ca.vanzyl.concord.plugins.tool.ToolInitializer) ToolCommand(ca.vanzyl.concord.plugins.tool.ToolCommand) Test(org.junit.Test)

Example 2 with Context

use of com.walmartlabs.concord.sdk.Context in project concord-plugins by walmartlabs.

the class PackerTaskTest method valiatePackerBuildCommandConstruction.

@Test
public void valiatePackerBuildCommandConstruction() throws Exception {
    ToolInitializer toolInitializer = new ToolInitializer(new OKHttpDownloadManager("packer"));
    Map<String, ToolCommand> commands = ImmutableMap.of("packer/build", new Build());
    PackerTask task = new PackerTask(commands, toolInitializer);
    Map<String, Object> args = Maps.newHashMap(mapBuilder().put("dryRun", true).put("command", "build").put("saveOutput", true).put("debug", true).put("force", true).put("except", ImmutableList.of("foo", "bar", "baz")).put("extraVars", mapBuilder().put("aws_access_key", "foo").put("aws_secret_key", "bar").build()).put("template", "packer.json").build());
    Context context = context(args);
    task.execute(context);
    // the extraVars are going to get serialized to a packer variables json file
    String expectedCommandLine = "packer build -debug -color=false -force -except=foo,bar,baz packer.json -var-file=.*\\.variables\\.json";
    assertThat(normalizedCommandLineArguments(context)).matches(expectedCommandLine);
}
Also used : Context(com.walmartlabs.concord.sdk.Context) OKHttpDownloadManager(com.walmartlabs.concord.plugins.OKHttpDownloadManager) Build(com.walmartlabs.concord.plugins.packer.commands.Build) ToolInitializer(ca.vanzyl.concord.plugins.tool.ToolInitializer) ToolCommand(ca.vanzyl.concord.plugins.tool.ToolCommand) Test(org.junit.Test)

Example 3 with Context

use of com.walmartlabs.concord.sdk.Context in project concord-plugins by walmartlabs.

the class BackendManagerTest method setUp.

@Before
public void setUp() throws Exception {
    Path tmpDir = Paths.get("/tmp/concord");
    if (!Files.exists(tmpDir)) {
        Files.createDirectories(tmpDir);
    }
    dstDir = Files.createTempDirectory(tmpDir, "test");
    Context ctx = new MockContext(Collections.singletonMap("workDir", dstDir.toAbsolutePath().toString()));
    LockService lockService = mock(LockService.class);
    ObjectStorage objectStorage = TerraformTaskTest.createObjectStorage(wireMockRule);
    backendManager = new BackendFactoryV1(ctx, lockService, objectStorage);
}
Also used : Path(java.nio.file.Path) Context(com.walmartlabs.concord.sdk.Context) MockContext(com.walmartlabs.concord.sdk.MockContext) MockContext(com.walmartlabs.concord.sdk.MockContext) LockService(com.walmartlabs.concord.sdk.LockService) ObjectStorage(com.walmartlabs.concord.sdk.ObjectStorage) Before(org.junit.Before)

Example 4 with Context

use of com.walmartlabs.concord.sdk.Context in project concord by walmartlabs.

the class SmtpTaskTest method testAttachments.

@Test
public void testAttachments() throws Exception {
    SmtpServer server = mail.getSmtp();
    Map<String, Object> smtpParams = new HashMap<>();
    smtpParams.put("host", "localhost");
    smtpParams.put("port", server.getPort());
    Map<String, Object> mailParams = new HashMap<>();
    mailParams.put("from", "my@mail.com");
    mailParams.put("to", "their@mail.com");
    mailParams.put("template", new File(ClassLoader.getSystemResource("test.mustache").toURI()).toString());
    mailParams.put("attachments", Collections.singletonList(new File(ClassLoader.getSystemResource("attahcment.txt").toURI()).toString()));
    Map<String, Object> m = new HashMap<>();
    m.put("name", "Concord");
    m.put("workDir", "/");
    m.put("smtp", smtpParams);
    m.put("mail", mailParams);
    Context ctx = new MockContext(m);
    SmtpTask t = new SmtpTask();
    t.execute(ctx);
    MimeMessage[] messages = mail.getReceivedMessages();
    assertEquals(1, messages.length);
    MimeMessage msg = messages[0];
    assertNotNull(msg.getContent());
    assertTrue(msg.getContent() instanceof MimeMultipart);
    MimeMultipart mp = (MimeMultipart) msg.getContent();
    assertEquals(2, mp.getCount());
    assertEquals("Hello, Concord!", mp.getBodyPart(0).getContent());
    assertEquals("test-attachment", mp.getBodyPart(1).getContent());
    mail.reset();
}
Also used : MockContext(com.walmartlabs.concord.sdk.MockContext) Context(com.walmartlabs.concord.sdk.Context) MockContext(com.walmartlabs.concord.sdk.MockContext) SmtpServer(com.icegreen.greenmail.smtp.SmtpServer) HashMap(java.util.HashMap) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) File(java.io.File) Test(org.junit.jupiter.api.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 5 with Context

use of com.walmartlabs.concord.sdk.Context 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)

Aggregations

Context (com.walmartlabs.concord.sdk.Context)10 Test (org.junit.Test)4 ToolCommand (ca.vanzyl.concord.plugins.tool.ToolCommand)3 ToolInitializer (ca.vanzyl.concord.plugins.tool.ToolInitializer)3 OKHttpDownloadManager (com.walmartlabs.concord.plugins.OKHttpDownloadManager)3 MockContext (com.walmartlabs.concord.sdk.MockContext)3 Path (java.nio.file.Path)3 HashMap (java.util.HashMap)3 Test (org.junit.jupiter.api.Test)3 SmtpServer (com.icegreen.greenmail.smtp.SmtpServer)2 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)2 Build (com.walmartlabs.concord.plugins.packer.commands.Build)2 File (java.io.File)2 MimeMessage (javax.mail.internet.MimeMessage)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ApiClient (com.walmartlabs.concord.ApiClient)1 ConcordApiClient (com.walmartlabs.concord.client.ConcordApiClient)1 Version (com.walmartlabs.concord.plugins.packer.commands.Version)1 InjectVariableELResolver (com.walmartlabs.concord.runner.engine.el.InjectVariableELResolver)1 Variables (com.walmartlabs.concord.runtime.v2.sdk.Variables)1