mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(codebuild): resolve project ARNs in batch lookup (#2999)
This commit is contained in:
1 parent
06349c8d88
commit
de92212b1b
3 files changed
+19
-4
No files matched your search
+5
-2
@@ -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<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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
+4
-1
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user