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