Light, fluffy, and always free - The AWS Local Emulator alternative
fix(codebuild): resolve project ARNs in batch lookup (#2999)
Aniket Shuklade92212b1b4f
diff --git a/src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildJsonHandler.javaindex 465930e9ae..f92b7ef806 100644--- a/src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildJsonHandler.java+++ b/src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildJsonHandler.java@@ -18,6 +18,7 @@ import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;+import java.util.stream.Stream;@ApplicationScopedpublic class CodeBuildJsonHandler {@@ -121,8 +122,10 @@ public class CodeBuildJsonHandler {List<String> names = new ArrayList<>();req.path("names").forEach(n -> names.add(n.asText()));List<Project> found = service.batchGetProjects(region, names);- List<String> foundNames = found.stream().map(Project::getName).toList();- List<String> notFound = names.stream().filter(n -> !foundNames.contains(n)).toList();+ List<String> foundIdentifiers = found.stream()+ .flatMap(project -> Stream.of(project.getName(), project.getArn()))+ .toList();+ List<String> notFound = names.stream().filter(n -> !foundIdentifiers.contains(n)).toList();return Response.ok(Map.of("projects", found, "projectsNotFound", notFound)).build();}diff --git a/src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildService.java b/src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildService.javaindex 01d7ad4d09..84bbcd518e 100644--- a/src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildService.java+++ b/src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildService.java@@ -227,7 +227,16 @@ public class CodeBuildService {public List<Project> batchGetProjects(String region, List<String> names) {Map<String, Project> store = projectsFor(region);return names.stream()- .map(store::get)+ .map(identifier -> {+ Project project = store.get(identifier);+ if (project != null) {+ return project;+ }+ return store.values().stream()+ .filter(candidate -> identifier.equals(candidate.getArn()))+ .findFirst()+ .orElse(null);+ }).filter(p -> p != null).collect(Collectors.toList());}diff --git a/src/test/java/io/github/hectorvent/floci/services/codebuild/CodeBuildIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/codebuild/CodeBuildIntegrationTest.javaindex d762d03fad..ad181bb636 100644--- a/src/test/java/io/github/hectorvent/floci/services/codebuild/CodeBuildIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/codebuild/CodeBuildIntegrationTest.java@@ -94,7 +94,10 @@ class CodeBuildIntegrationTest {.contentType(CONTENT_TYPE).body("""{- "names": ["my-build-project", "nonexistent-project"]+ "names": [+ "arn:aws:codebuild:us-east-1:000000000000:project/my-build-project",+ "nonexistent-project"+ ]}""").when()