Skip to content

Commit

Permalink
aws: use paginator API, fix timestamp serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
ibodrov committed Jun 20, 2024
1 parent 5d5f902 commit e929f75
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change log

## [2.3.1] - Unreleased

### Changed

- aws: use paginator API, fix timestamp serialization
([#155](https://github.com/walmartlabs/concord-plugins/pull/155)).



## [2.3.0] - 2024-06-20

- aws: add a basic ecr describe-images wrapper
Expand Down
3 changes: 2 additions & 1 deletion tasks/aws/examples/ecr/concord.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
configuration:
runtime: concord-v2
dependencies:
- mvn://com.walmartlabs.concord.plugins:aws-tasks:2.3.0
- mvn://com.walmartlabs.concord.plugins:aws-tasks:2.3.1

flows:
default:
Expand All @@ -10,5 +10,6 @@ flows:
action: describe-images
region: us-east-1
repositoryName: foo
maxResults: 1
out: result
- log: "Image Details: ${resource.prettyPrintJson(result.imageDetails)}"
4 changes: 4 additions & 0 deletions tasks/aws/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<groupId>software.amazon.awssdk</groupId>
<artifactId>ecr</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sdk-core</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
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 javax.inject.Inject;
import javax.inject.Named;
Expand All @@ -48,7 +50,8 @@ public class EcrTask implements Task {
public EcrTask(ObjectMapper objectMapper) {
this.objectMapper = requireNonNull(objectMapper).copy()
.registerModule(new JavaTimeModule())
.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}

@Override
Expand All @@ -63,29 +66,38 @@ public TaskResult execute(Variables input) {
private TaskResult describeImages(Variables input) {
var region = assertRegion(input, "region");
var repositoryName = input.assertString("repositoryName");
var maxResults = input.getInt("maxResults", 100);
var verbose = input.getBoolean("verbose", false);

// create the client
if (verbose) {
log.info("Using region: {}", region);
log.info("Using region={}, maxResults={}", region, maxResults);
}
var client = EcrClient.builder()

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

// describe-images
if (verbose) {
log.info("Describing images in repository '{}'", repositoryName);
}
var result = client.describeImages(r -> r.repositoryName(repositoryName));
if (verbose) {
log.info("Done: {}", result.imageDetails().size());
}
if (verbose) {
log.info("Describing images in repository '{}'", repositoryName);
}

// serialize result into POJOs
var data = objectMapper.convertValue(result.toBuilder(), Map.class);
//noinspection unchecked
return TaskResult.success().values(data);
var request = DescribeImagesRequest.builder()
.repositoryName(repositoryName)
.maxResults(maxResults)
.build();

var data = client.describeImagesPaginator(request).stream()
.flatMap(response -> response.imageDetails().stream())
.map(ImageDetail::toBuilder)
.map(b -> (Map<?, ?>) objectMapper.convertValue(b, Map.class))
.toList();

if (verbose) {
log.info("Done: {}", data.size());
}

return TaskResult.success().values(Map.of("imageDetails", data));
}
}

private static Region assertRegion(Variables input, String key) {
Expand Down

0 comments on commit e929f75

Please sign in to comment.