Skip to content

Commit

Permalink
sync with default branch, resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
benbroadaway committed Sep 24, 2024
2 parents 77060bc + a3b23a9 commit bd3ec77
Show file tree
Hide file tree
Showing 79 changed files with 5,749 additions and 292 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change log

## [2.5.0] - 2024-08-19

### Changed

- gremlin: remove okhttp and gson dependencies
([#162](https://github.com/walmartlabs/concord-plugins/pull/162));
- msteams: remove apache httpclient dependency, add unit and integration tests
([#163](https://github.com/walmartlabs/concord-plugins/pull/163));
- jira: remove okhttp2 dependency
([#171](https://github.com/walmartlabs/concord-plugins/pull/171)).

## [2.4.0] - 2024-07-19

### Changed
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>com.walmartlabs.concord.plugins</groupId>
<artifactId>concord-plugins-parent</artifactId>
<version>2.4.1-SNAPSHOT</version>
<version>2.5.1-SNAPSHOT</version>

<packaging>pom</packaging>

Expand Down
2 changes: 1 addition & 1 deletion tasks/akeyless/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.walmartlabs.concord.plugins</groupId>
<artifactId>concord-plugins-parent</artifactId>
<version>2.4.1-SNAPSHOT</version>
<version>2.5.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion tasks/argocd/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.walmartlabs.concord.plugins</groupId>
<artifactId>concord-plugins-parent</artifactId>
<version>2.4.1-SNAPSHOT</version>
<version>2.5.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>argocd-task</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion tasks/aws/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.walmartlabs.concord.plugins</groupId>
<artifactId>concord-plugins-parent</artifactId>
<version>2.4.1-SNAPSHOT</version>
<version>2.5.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.ecr.EcrClient;
import software.amazon.awssdk.services.ecr.model.DescribeImagesRequest;
import software.amazon.awssdk.services.ecr.model.ImageDetail;
import software.amazon.awssdk.services.ecr.model.*;

import javax.inject.Inject;
import javax.inject.Named;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static java.util.Objects.requireNonNull;
Expand All @@ -62,6 +63,8 @@ public TaskResult execute(Variables input) {
var action = input.assertString("action");
if ("describe-images".equals(action)) {
return describeImages(input);
} if ("delete-images".equals(action)) {
return deleteImage(input);
}
throw new IllegalArgumentException("Unsupported action: " + action);
}
Expand Down Expand Up @@ -103,8 +106,90 @@ private TaskResult describeImages(Variables input) {
}
}


private TaskResult deleteImage(Variables input) {
var region = assertRegion(input, "region");
var repositoryName = input.assertString("repositoryName");
var imageIds = assertImageIds(input);
var debug = input.getBoolean("debug", context.processConfiguration().debug());

try (var client = EcrClient.builder()
.region(region)
.build()) {

List<ImageFailure> failures = new ArrayList<>();
for (var ids : partitions(imageIds, 100)) {
var request = BatchDeleteImageRequest.builder()
.repositoryName(repositoryName)
.imageIds(ids)
.build();

var response = client.batchDeleteImage(request);
if (response.hasFailures()) {
failures.addAll(response.failures());
}

if (debug) {
log.info("Processed {}/{}, failures: {}", ids.size(), imageIds.size(), failures.size());
}
}

if (!failures.isEmpty()) {
return TaskResult.fail("Failures in response")
.values(Map.of("failures", serialize(failures)));
}

return TaskResult.success();
}
}

private static List<Map<String, Object>> serialize(List<ImageFailure> failures) {
List<Map<String, Object>> result = new ArrayList<>();
for (var failure : failures) {
result.add(Map.of("imageId", serialize(failure.imageId()),
"failureCode", failure.failureCode(),
"failureReason", failure.failureReason()));
}

return result;
}

private static String serialize(ImageIdentifier imageIdentifier) {
if (imageIdentifier == null) {
return null;
}
if (imageIdentifier.imageTag() != null) {
return imageIdentifier.imageTag();
}
return imageIdentifier.imageDigest();
}

private static Region assertRegion(Variables input, String key) {
String region = input.assertString(key);
return Region.of(region);
}

private static List<ImageIdentifier> assertImageIds(Variables input) {
String imageTag = input.getString("imageTag");
if (imageTag != null) {
return List.of(ImageIdentifier.builder().imageTag(imageTag).build());
}

List<String> imageTags = input.getList("imageTags", List.of());
if (!imageTags.isEmpty()) {
return imageTags.stream().map(i -> ImageIdentifier.builder().imageTag(i).build()).toList();
}

throw new IllegalArgumentException("Missing 'imageTags' or 'imageTags' in the input variable");
}

private static <T> List<List<T>> partitions(List<T> list, int size) {
List<List<T>> parts = new ArrayList<>();
for (int i = 0; i < list.size(); i += size) {
parts.add(new ArrayList<>(
list.subList(i, Math.min(list.size(), i + size)))
);
}
return parts;
}
}
2 changes: 1 addition & 1 deletion tasks/confluence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.walmartlabs.concord.plugins</groupId>
<artifactId>concord-plugins-parent</artifactId>
<version>2.4.1-SNAPSHOT</version>
<version>2.5.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
7 changes: 6 additions & 1 deletion tasks/git/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.walmartlabs.concord.plugins</groupId>
<artifactId>concord-plugins-parent</artifactId>
<version>2.4.1-SNAPSHOT</version>
<version>2.5.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -97,6 +97,11 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -598,7 +599,7 @@ private static Map<String, Object> forkRepo(Map<String, Object> in, String gitHu

return Collections.emptyMap();
} catch (Exception e) {
throw new RuntimeException("Error occured during fork: " + e.getMessage());
throw new RuntimeException("Error occurred during fork: " + e.getMessage());
}
}

Expand Down Expand Up @@ -628,7 +629,7 @@ private static Map<String, Object> getBranchList(Map<String, Object> in, String

return result;
} catch (Exception e) {
throw new RuntimeException("Error occured while getting branch list: " + e.getMessage());
throw new RuntimeException("Error occurred while getting branch list: " + e.getMessage());
}
}

Expand Down Expand Up @@ -658,7 +659,7 @@ private static Map<String, Object> getTagList(Map<String, Object> in, String git

return result;
} catch (Exception e) {
throw new RuntimeException("Error occured while getting tag list: " + e.getMessage());
throw new RuntimeException("Error occurred while getting tag list: " + e.getMessage());
}
}

Expand Down Expand Up @@ -797,7 +798,7 @@ private static Map<String, Object> createRepo(Map<String, Object> in, String git
result.put("scmUrl", repo.getUrl());
return result;
} catch (Exception e) {
throw new RuntimeException("Error occured while creating repository: ", e);
throw new RuntimeException("Error occurred while creating repository: ", e);
}
}

Expand Down Expand Up @@ -830,7 +831,7 @@ private static Map<String, Object> deleteRepo(Map<String, Object> in, String git

return Collections.emptyMap();
} catch (Exception e) {
throw new RuntimeException("Error occured while deleting repository: ", e);
throw new RuntimeException("Error occurred while deleting repository: ", e);
}
}

Expand Down Expand Up @@ -1023,18 +1024,25 @@ private static Map<String, Object> makeResult(Object data) {
return m;
}

private static GitHubClient createClient(String url) {
static GitHubClient createClient(String rawUrl) {
String host;
int port;
String scheme;

try {
host = (new URL(url)).getHost();
URI uri = new URI(rawUrl);
host = uri.getHost();
if ("github.com".equals(host) || "gist.github.com".equals(host)) {
host = "api.github.com";
}
} catch (IOException e) {

scheme = uri.getScheme();
port = uri.getPort();
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}

return new GitHubClient(host) {
return new GitHubClient(host, port, scheme) {
@Override
protected IOException createException(InputStream response, int code, String status) {
String responseBody = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ class GitHubCommonTest {

@Test
void testCreateClient() {
GitHubClient client = GitHubClient.createClient("https://mock.github.local");
GitHubClient client = GitHubTask.createClient("https://mock.github.local");

assertNotNull(client);
}

@Test
void testCreateClientWithPort() {
GitHubClient client = GitHubTask.createClient("https://mock.github.local:8080");

assertNotNull(client);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.walmartlabs.concord.plugins.git.v2;

import com.github.tomakehurst.wiremock.common.ConsoleNotifier;
import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
import com.walmartlabs.concord.plugins.git.GitHubTask;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.util.List;
import java.util.Map;

import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertTrue;

class CommitTest {

@RegisterExtension
protected static WireMockExtension httpRule = WireMockExtension.newInstance()
.options(wireMockConfig()
.dynamicPort()
.usingFilesUnderClasspath("wiremock/commit")
.notifier(new ConsoleNotifier(false))) // set to true for verbose logging
.build();

@Test
void testGet() {
Map<String, Object> input = Map.of(
"action", "getCommit",
"accessToken", "mockToken",
"org", "octocat",
"repo", "mock-repo",
"commitSHA", "6dcb09b5b57875f334f61aebed695e2e4193db5e",
"apiUrl", httpRule.baseUrl()
);

var result = new GitHubTask().execute(input, Map.of());

httpRule.verify(1, getRequestedFor(urlEqualTo("/api/v3/repos/octocat/mock-repo/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e")));
httpRule.verify(1, getRequestedFor(urlEqualTo("/api/v3/repos/octocat/mock-repo")));

var r = assertInstanceOf(Map.class, result.get("result"));
var data = assertInstanceOf(Map.class, r.get("data"));
var defaultBranch = assertInstanceOf(String.class, data.get("defaultBranch"));

assertEquals(true, r.get("ok"));
assertEquals("master", defaultBranch);
}

@Test
void testAddStatus() {
Map<String, Object> input = Map.of(
"action", "addStatus",
"accessToken", "mockToken",
"org", "octocat",
"repo", "mock-repo",
"commitSHA", "6dcb09b5b57875f334f61aebed695e2e4193db5e",
"context", "myContext",
"state", "pending",
"targetUrl", "https://concord.example.com/#/process/${txId}",
"apiUrl", httpRule.baseUrl()
);

var result = new GitHubTask().execute(input, Map.of());

httpRule.verify(1, postRequestedFor(urlEqualTo("/api/v3/repos/octocat/mock-repo/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e")));

assertTrue(result.isEmpty());
}

@Test
void testGetStatuses() {
Map<String, Object> input = Map.of(
"action", "getStatuses",
"accessToken", "mockToken",
"org", "octocat",
"repo", "mock-repo",
"commitSHA", "6dcb09b5b57875f334f61aebed695e2e4193db5e",
"apiUrl", httpRule.baseUrl()
);

var result = new GitHubTask().execute(input, Map.of());

httpRule.verify(1, getRequestedFor(urlEqualTo("/api/v3/repos/octocat/mock-repo/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e?per_page=100&page=1")));

var commitStatuses = assertInstanceOf(List.class, result.get("commitStatuses"));

assertFalse(commitStatuses.isEmpty());
var status = assertInstanceOf(Map.class, commitStatuses.get(0));
assertEquals("success", status.get("state"));
}

}
Loading

0 comments on commit bd3ec77

Please sign in to comment.