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.java index 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; @ApplicationScoped public class CodeBuildJsonHandler { @@ -121,8 +122,10 @@ public class CodeBuildJsonHandler { List names = new ArrayList<>(); req.path("names").forEach(n -> names.add(n.asText())); List found = service.batchGetProjects(region, names); - List foundNames = found.stream().map(Project::getName).toList(); - List notFound = names.stream().filter(n -> !foundNames.contains(n)).toList(); + List foundIdentifiers = found.stream() + .flatMap(project -> Stream.of(project.getName(), project.getArn())) + .toList(); + List 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.java index 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 batchGetProjects(String region, List names) { Map 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.java index 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()