mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(codebuild,codedeploy): add management APIs (#622)
This commit is contained in:
1 parent
33ce936d44
commit
f5ec6fc887
30 files changed
+3059
-7
No files matched your search
@@ -270,6 +270,18 @@ public interface EmulatorConfig {
|
||||
EksServiceConfig eks();
|
||||
PipesServiceConfig pipes();
|
||||
ElbV2ServiceConfig elbv2();
|
||||
CodeBuildServiceConfig codebuild();
|
||||
CodeDeployServiceConfig codedeploy();
|
||||
}
|
||||
|
||||
interface CodeBuildServiceConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
}
|
||||
|
||||
interface CodeDeployServiceConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
}
|
||||
|
||||
interface SsmServiceConfig {
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.services.acm.AcmJsonHandler;
|
||||
import io.github.hectorvent.floci.services.athena.AthenaJsonHandler;
|
||||
import io.github.hectorvent.floci.services.codebuild.CodeBuildJsonHandler;
|
||||
import io.github.hectorvent.floci.services.codedeploy.CodeDeployJsonHandler;
|
||||
import io.github.hectorvent.floci.services.ecr.EcrJsonHandler;
|
||||
import io.github.hectorvent.floci.services.ecs.EcsJsonHandler;
|
||||
import io.github.hectorvent.floci.services.firehose.FirehoseJsonHandler;
|
||||
@@ -56,6 +58,8 @@ public class AwsJson11Controller {
|
||||
private final AthenaJsonHandler athenaJsonHandler;
|
||||
private final FirehoseJsonHandler firehoseJsonHandler;
|
||||
private final ResourceGroupsTaggingJsonHandler resourceGroupsTaggingJsonHandler;
|
||||
private final CodeBuildJsonHandler codeBuildJsonHandler;
|
||||
private final CodeDeployJsonHandler codeDeployJsonHandler;
|
||||
|
||||
@Inject
|
||||
public AwsJson11Controller(ObjectMapper objectMapper, ResolvedServiceCatalog catalog,
|
||||
@@ -70,7 +74,9 @@ public class AwsJson11Controller {
|
||||
EcrJsonHandler ecrJsonHandler, GlueJsonHandler glueJsonHandler,
|
||||
AthenaJsonHandler athenaJsonHandler,
|
||||
FirehoseJsonHandler firehoseJsonHandler,
|
||||
ResourceGroupsTaggingJsonHandler resourceGroupsTaggingJsonHandler) {
|
||||
ResourceGroupsTaggingJsonHandler resourceGroupsTaggingJsonHandler,
|
||||
CodeBuildJsonHandler codeBuildJsonHandler,
|
||||
CodeDeployJsonHandler codeDeployJsonHandler) {
|
||||
this.objectMapper = objectMapper;
|
||||
this.catalog = catalog;
|
||||
this.regionResolver = regionResolver;
|
||||
@@ -89,6 +95,8 @@ public class AwsJson11Controller {
|
||||
this.athenaJsonHandler = athenaJsonHandler;
|
||||
this.firehoseJsonHandler = firehoseJsonHandler;
|
||||
this.resourceGroupsTaggingJsonHandler = resourceGroupsTaggingJsonHandler;
|
||||
this.codeBuildJsonHandler = codeBuildJsonHandler;
|
||||
this.codeDeployJsonHandler = codeDeployJsonHandler;
|
||||
}
|
||||
|
||||
@POST
|
||||
@@ -132,6 +140,8 @@ public class AwsJson11Controller {
|
||||
case "athena" -> athenaJsonHandler.handle(action, request, region);
|
||||
case "firehose" -> firehoseJsonHandler.handle(action, request, region);
|
||||
case "tagging" -> resourceGroupsTaggingJsonHandler.handle(action, request, region);
|
||||
case "codebuild" -> codeBuildJsonHandler.handle(action, request, region, regionResolver.getAccountId());
|
||||
case "codedeploy" -> codeDeployJsonHandler.handle(action, request, region);
|
||||
default -> null;
|
||||
};
|
||||
// catalog.matchTarget is protocol-agnostic: a JSON 1.0 target
|
||||
|
||||
@@ -208,7 +208,15 @@ public class ResolvedServiceCatalog {
|
||||
descriptor("elasticloadbalancing", "elbv2", config.services().elbv2().enabled(), true,
|
||||
"elbv2", config.storage().mode(), 5000L, AwsNamespaces.ELB_V2, ServiceProtocol.QUERY,
|
||||
protocols(ServiceProtocol.QUERY),
|
||||
Set.of(), Set.of("elasticloadbalancing"), Set.of(), Set.of())
|
||||
Set.of(), Set.of("elasticloadbalancing"), Set.of(), Set.of()),
|
||||
descriptor("codebuild", "codebuild", config.services().codebuild().enabled(), true,
|
||||
null, null, 5000L, null, ServiceProtocol.JSON,
|
||||
protocols(ServiceProtocol.JSON),
|
||||
Set.of("CodeBuild_20161006."), Set.of("codebuild"), Set.of(), Set.of()),
|
||||
descriptor("codedeploy", "codedeploy", config.services().codedeploy().enabled(), true,
|
||||
null, null, 5000L, null, ServiceProtocol.JSON,
|
||||
protocols(ServiceProtocol.JSON),
|
||||
Set.of("CodeDeploy_20141006."), Set.of("codedeploy"), Set.of(), Set.of())
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
package io.github.hectorvent.floci.services.codebuild;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.codebuild.model.Project;
|
||||
import io.github.hectorvent.floci.services.codebuild.model.ProjectArtifacts;
|
||||
import io.github.hectorvent.floci.services.codebuild.model.ProjectEnvironment;
|
||||
import io.github.hectorvent.floci.services.codebuild.model.ProjectSource;
|
||||
import io.github.hectorvent.floci.services.codebuild.model.ReportGroup;
|
||||
import io.github.hectorvent.floci.services.codebuild.model.SourceCredential;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ApplicationScoped
|
||||
public class CodeBuildJsonHandler {
|
||||
|
||||
private final CodeBuildService service;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
@Inject
|
||||
public CodeBuildJsonHandler(CodeBuildService service, ObjectMapper mapper) {
|
||||
this.service = service;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public Response handle(String action, JsonNode request, String region, String account) throws Exception {
|
||||
return switch (action) {
|
||||
case "CreateProject" -> createProject(request, region, account);
|
||||
case "UpdateProject" -> updateProject(request, region);
|
||||
case "DeleteProject" -> deleteProject(request, region);
|
||||
case "BatchGetProjects" -> batchGetProjects(request, region);
|
||||
case "ListProjects" -> listProjects(region);
|
||||
case "CreateReportGroup" -> createReportGroup(request, region, account);
|
||||
case "UpdateReportGroup" -> updateReportGroup(request, region);
|
||||
case "DeleteReportGroup" -> deleteReportGroup(request, region);
|
||||
case "BatchGetReportGroups" -> batchGetReportGroups(request, region);
|
||||
case "ListReportGroups" -> listReportGroups(region);
|
||||
case "ImportSourceCredentials" -> importSourceCredentials(request, region, account);
|
||||
case "ListSourceCredentials" -> listSourceCredentials(region);
|
||||
case "DeleteSourceCredentials" -> deleteSourceCredentials(request, region);
|
||||
case "ListCuratedEnvironmentImages" -> listCuratedEnvironmentImages();
|
||||
default -> throw new AwsException("InvalidAction", "Action " + action + " is not supported", 400);
|
||||
};
|
||||
}
|
||||
|
||||
private Response createProject(JsonNode req, String region, String account) throws Exception {
|
||||
String name = req.path("name").asText(null);
|
||||
String description = req.has("description") ? req.path("description").asText() : null;
|
||||
ProjectSource source = req.has("source") ? mapper.treeToValue(req.get("source"), ProjectSource.class) : null;
|
||||
List<ProjectSource> secondarySources = parseList(req, "secondarySources", ProjectSource.class);
|
||||
String sourceVersion = req.has("sourceVersion") ? req.path("sourceVersion").asText() : null;
|
||||
ProjectArtifacts artifacts = req.has("artifacts") ? mapper.treeToValue(req.get("artifacts"), ProjectArtifacts.class) : null;
|
||||
List<ProjectArtifacts> secondaryArtifacts = parseList(req, "secondaryArtifacts", ProjectArtifacts.class);
|
||||
ProjectEnvironment environment = req.has("environment") ? mapper.treeToValue(req.get("environment"), ProjectEnvironment.class) : null;
|
||||
String serviceRole = req.has("serviceRole") ? req.path("serviceRole").asText() : null;
|
||||
Integer timeout = req.has("timeoutInMinutes") ? req.path("timeoutInMinutes").asInt() : null;
|
||||
Integer queuedTimeout = req.has("queuedTimeoutInMinutes") ? req.path("queuedTimeoutInMinutes").asInt() : null;
|
||||
String encryptionKey = req.has("encryptionKey") ? req.path("encryptionKey").asText() : null;
|
||||
List<Map<String, String>> tags = parseTags(req);
|
||||
Map<String, Object> logsConfig = req.has("logsConfig") ? mapper.treeToValue(req.get("logsConfig"), Map.class) : null;
|
||||
Map<String, Object> vpcConfig = req.has("vpcConfig") ? mapper.treeToValue(req.get("vpcConfig"), Map.class) : null;
|
||||
Integer concurrentBuildLimit = req.has("concurrentBuildLimit") ? req.path("concurrentBuildLimit").asInt() : null;
|
||||
|
||||
Project project = service.createProject(region, account, name, description,
|
||||
source, secondarySources, sourceVersion,
|
||||
artifacts, secondaryArtifacts, environment,
|
||||
serviceRole, timeout, queuedTimeout, encryptionKey,
|
||||
tags, logsConfig, vpcConfig, concurrentBuildLimit);
|
||||
|
||||
return Response.ok(Map.of("project", project)).build();
|
||||
}
|
||||
|
||||
private Response updateProject(JsonNode req, String region) throws Exception {
|
||||
String name = req.path("name").asText(null);
|
||||
String description = req.has("description") ? req.path("description").asText() : null;
|
||||
ProjectSource source = req.has("source") ? mapper.treeToValue(req.get("source"), ProjectSource.class) : null;
|
||||
List<ProjectSource> secondarySources = parseList(req, "secondarySources", ProjectSource.class);
|
||||
String sourceVersion = req.has("sourceVersion") ? req.path("sourceVersion").asText() : null;
|
||||
ProjectArtifacts artifacts = req.has("artifacts") ? mapper.treeToValue(req.get("artifacts"), ProjectArtifacts.class) : null;
|
||||
List<ProjectArtifacts> secondaryArtifacts = parseList(req, "secondaryArtifacts", ProjectArtifacts.class);
|
||||
ProjectEnvironment environment = req.has("environment") ? mapper.treeToValue(req.get("environment"), ProjectEnvironment.class) : null;
|
||||
String serviceRole = req.has("serviceRole") ? req.path("serviceRole").asText() : null;
|
||||
Integer timeout = req.has("timeoutInMinutes") ? req.path("timeoutInMinutes").asInt() : null;
|
||||
Integer queuedTimeout = req.has("queuedTimeoutInMinutes") ? req.path("queuedTimeoutInMinutes").asInt() : null;
|
||||
String encryptionKey = req.has("encryptionKey") ? req.path("encryptionKey").asText() : null;
|
||||
List<Map<String, String>> tags = parseTags(req);
|
||||
Map<String, Object> logsConfig = req.has("logsConfig") ? mapper.treeToValue(req.get("logsConfig"), Map.class) : null;
|
||||
Map<String, Object> vpcConfig = req.has("vpcConfig") ? mapper.treeToValue(req.get("vpcConfig"), Map.class) : null;
|
||||
Integer concurrentBuildLimit = req.has("concurrentBuildLimit") ? req.path("concurrentBuildLimit").asInt() : null;
|
||||
|
||||
Project project = service.updateProject(region, name, description,
|
||||
source, secondarySources, sourceVersion,
|
||||
artifacts, secondaryArtifacts, environment,
|
||||
serviceRole, timeout, queuedTimeout, encryptionKey,
|
||||
tags, logsConfig, vpcConfig, concurrentBuildLimit);
|
||||
|
||||
return Response.ok(Map.of("project", project)).build();
|
||||
}
|
||||
|
||||
private Response deleteProject(JsonNode req, String region) {
|
||||
String name = req.path("name").asText(null);
|
||||
service.deleteProject(region, name);
|
||||
return Response.ok(Map.of()).build();
|
||||
}
|
||||
|
||||
private Response batchGetProjects(JsonNode req, String region) {
|
||||
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();
|
||||
return Response.ok(Map.of("projects", found, "projectsNotFound", notFound)).build();
|
||||
}
|
||||
|
||||
private Response listProjects(String region) {
|
||||
List<String> names = service.listProjects(region);
|
||||
return Response.ok(Map.of("projects", names)).build();
|
||||
}
|
||||
|
||||
private Response createReportGroup(JsonNode req, String region, String account) throws Exception {
|
||||
String name = req.path("name").asText(null);
|
||||
String type = req.path("type").asText(null);
|
||||
Map<String, Object> exportConfig = req.has("exportConfig") ? mapper.treeToValue(req.get("exportConfig"), Map.class) : null;
|
||||
List<Map<String, String>> tags = parseTags(req);
|
||||
ReportGroup rg = service.createReportGroup(region, account, name, type, exportConfig, tags);
|
||||
return Response.ok(Map.of("reportGroup", rg)).build();
|
||||
}
|
||||
|
||||
private Response updateReportGroup(JsonNode req, String region) throws Exception {
|
||||
String arn = req.path("arn").asText(null);
|
||||
Map<String, Object> exportConfig = req.has("exportConfig") ? mapper.treeToValue(req.get("exportConfig"), Map.class) : null;
|
||||
List<Map<String, String>> tags = parseTags(req);
|
||||
ReportGroup rg = service.updateReportGroup(region, arn, exportConfig, tags);
|
||||
return Response.ok(Map.of("reportGroup", rg)).build();
|
||||
}
|
||||
|
||||
private Response deleteReportGroup(JsonNode req, String region) {
|
||||
String arn = req.path("arn").asText(null);
|
||||
service.deleteReportGroup(region, arn);
|
||||
return Response.ok(Map.of()).build();
|
||||
}
|
||||
|
||||
private Response batchGetReportGroups(JsonNode req, String region) {
|
||||
List<String> arns = new ArrayList<>();
|
||||
req.path("reportGroupArns").forEach(a -> arns.add(a.asText()));
|
||||
List<ReportGroup> found = service.batchGetReportGroups(region, arns);
|
||||
List<String> foundArns = found.stream().map(ReportGroup::getArn).toList();
|
||||
List<String> notFound = arns.stream().filter(a -> !foundArns.contains(a)).toList();
|
||||
return Response.ok(Map.of("reportGroups", found, "reportGroupsNotFound", notFound)).build();
|
||||
}
|
||||
|
||||
private Response listReportGroups(String region) {
|
||||
return Response.ok(Map.of("reportGroups", service.listReportGroups(region))).build();
|
||||
}
|
||||
|
||||
private Response importSourceCredentials(JsonNode req, String region, String account) {
|
||||
String token = req.path("token").asText(null);
|
||||
String serverType = req.path("serverType").asText(null);
|
||||
String authType = req.path("authType").asText(null);
|
||||
Boolean shouldOverwrite = req.has("shouldOverwrite") ? req.path("shouldOverwrite").asBoolean() : null;
|
||||
SourceCredential cred = service.importSourceCredentials(region, account, token, serverType, authType, shouldOverwrite);
|
||||
return Response.ok(Map.of("arn", cred.getArn())).build();
|
||||
}
|
||||
|
||||
private Response listSourceCredentials(String region) {
|
||||
List<SourceCredential> creds = service.listSourceCredentials(region);
|
||||
return Response.ok(Map.of("sourceCredentialsInfos", creds)).build();
|
||||
}
|
||||
|
||||
private Response deleteSourceCredentials(JsonNode req, String region) {
|
||||
String arn = req.path("arn").asText(null);
|
||||
service.deleteSourceCredentials(region, arn);
|
||||
return Response.ok(Map.of("arn", arn)).build();
|
||||
}
|
||||
|
||||
private Response listCuratedEnvironmentImages() {
|
||||
return Response.ok(Map.of("platforms", service.listCuratedEnvironmentImages())).build();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> List<T> parseList(JsonNode req, String field, Class<T> type) throws Exception {
|
||||
if (!req.has(field) || req.get(field).isNull()) {
|
||||
return null;
|
||||
}
|
||||
List<T> result = new ArrayList<>();
|
||||
for (JsonNode node : req.get(field)) {
|
||||
result.add(mapper.treeToValue(node, type));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Map<String, String>> parseTags(JsonNode req) {
|
||||
if (!req.has("tags") || req.get("tags").isNull()) {
|
||||
return null;
|
||||
}
|
||||
List<Map<String, String>> tags = new ArrayList<>();
|
||||
for (JsonNode tag : req.get("tags")) {
|
||||
Map<String, String> t = new HashMap<>();
|
||||
t.put("key", tag.path("key").asText());
|
||||
t.put("value", tag.path("value").asText());
|
||||
tags.add(t);
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,318 @@
|
||||
package io.github.hectorvent.floci.services.codebuild;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.codebuild.model.Project;
|
||||
import io.github.hectorvent.floci.services.codebuild.model.ProjectArtifacts;
|
||||
import io.github.hectorvent.floci.services.codebuild.model.ProjectEnvironment;
|
||||
import io.github.hectorvent.floci.services.codebuild.model.ProjectSource;
|
||||
import io.github.hectorvent.floci.services.codebuild.model.ReportGroup;
|
||||
import io.github.hectorvent.floci.services.codebuild.model.SourceCredential;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ApplicationScoped
|
||||
public class CodeBuildService {
|
||||
|
||||
// key: region -> name -> project
|
||||
private final ConcurrentHashMap<String, ConcurrentHashMap<String, Project>> projects = new ConcurrentHashMap<>();
|
||||
// key: region -> arn -> report group
|
||||
private final ConcurrentHashMap<String, ConcurrentHashMap<String, ReportGroup>> reportGroups = new ConcurrentHashMap<>();
|
||||
// key: region -> arn -> source credential (token is stored but never returned)
|
||||
private final ConcurrentHashMap<String, ConcurrentHashMap<String, SourceCredential>> sourceCredentials = new ConcurrentHashMap<>();
|
||||
|
||||
private Map<String, Project> projectsFor(String region) {
|
||||
return projects.computeIfAbsent(region, r -> new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
private Map<String, ReportGroup> reportGroupsFor(String region) {
|
||||
return reportGroups.computeIfAbsent(region, r -> new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
private Map<String, SourceCredential> sourceCredentialsFor(String region) {
|
||||
return sourceCredentials.computeIfAbsent(region, r -> new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
// ---- Projects ----
|
||||
|
||||
public Project createProject(String region, String account,
|
||||
String name, String description,
|
||||
ProjectSource source, List<ProjectSource> secondarySources,
|
||||
String sourceVersion,
|
||||
ProjectArtifacts artifacts, List<ProjectArtifacts> secondaryArtifacts,
|
||||
ProjectEnvironment environment,
|
||||
String serviceRole,
|
||||
Integer timeoutInMinutes, Integer queuedTimeoutInMinutes,
|
||||
String encryptionKey,
|
||||
List<Map<String, String>> tags,
|
||||
Map<String, Object> logsConfig,
|
||||
Map<String, Object> vpcConfig,
|
||||
Integer concurrentBuildLimit) {
|
||||
Map<String, Project> store = projectsFor(region);
|
||||
if (store.containsKey(name)) {
|
||||
throw new AwsException("ResourceAlreadyExistsException",
|
||||
"Project already exists: " + name, 400);
|
||||
}
|
||||
validateProjectName(name);
|
||||
if (source == null || source.getType() == null) {
|
||||
throw new AwsException("InvalidInputException", "source.type is required", 400);
|
||||
}
|
||||
if (environment == null) {
|
||||
throw new AwsException("InvalidInputException", "environment is required", 400);
|
||||
}
|
||||
if (serviceRole == null || serviceRole.isBlank()) {
|
||||
throw new AwsException("InvalidInputException", "serviceRole is required", 400);
|
||||
}
|
||||
if (artifacts == null || artifacts.getType() == null) {
|
||||
throw new AwsException("InvalidInputException", "artifacts.type is required", 400);
|
||||
}
|
||||
|
||||
double now = Instant.now().toEpochMilli() / 1000.0;
|
||||
Project project = new Project();
|
||||
project.setName(name);
|
||||
project.setArn("arn:aws:codebuild:" + region + ":" + account + ":project/" + name);
|
||||
project.setDescription(description);
|
||||
project.setSource(source);
|
||||
project.setSecondarySources(secondarySources);
|
||||
project.setSourceVersion(sourceVersion);
|
||||
project.setArtifacts(artifacts);
|
||||
project.setSecondaryArtifacts(secondaryArtifacts);
|
||||
project.setEnvironment(environment);
|
||||
project.setServiceRole(serviceRole);
|
||||
project.setTimeoutInMinutes(timeoutInMinutes != null ? timeoutInMinutes : 60);
|
||||
project.setQueuedTimeoutInMinutes(queuedTimeoutInMinutes != null ? queuedTimeoutInMinutes : 480);
|
||||
project.setEncryptionKey(encryptionKey);
|
||||
project.setTags(tags);
|
||||
project.setCreated(now);
|
||||
project.setLastModified(now);
|
||||
project.setLogsConfig(logsConfig);
|
||||
project.setVpcConfig(vpcConfig);
|
||||
project.setConcurrentBuildLimit(concurrentBuildLimit);
|
||||
project.setProjectVisibility("PRIVATE");
|
||||
|
||||
store.put(name, project);
|
||||
return project;
|
||||
}
|
||||
|
||||
public Project updateProject(String region, String name,
|
||||
String description,
|
||||
ProjectSource source, List<ProjectSource> secondarySources,
|
||||
String sourceVersion,
|
||||
ProjectArtifacts artifacts, List<ProjectArtifacts> secondaryArtifacts,
|
||||
ProjectEnvironment environment,
|
||||
String serviceRole,
|
||||
Integer timeoutInMinutes, Integer queuedTimeoutInMinutes,
|
||||
String encryptionKey,
|
||||
List<Map<String, String>> tags,
|
||||
Map<String, Object> logsConfig,
|
||||
Map<String, Object> vpcConfig,
|
||||
Integer concurrentBuildLimit) {
|
||||
Map<String, Project> store = projectsFor(region);
|
||||
Project project = store.get(name);
|
||||
if (project == null) {
|
||||
throw new AwsException("ResourceNotFoundException", "Project not found: " + name, 400);
|
||||
}
|
||||
|
||||
if (description != null) { project.setDescription(description); }
|
||||
if (source != null) { project.setSource(source); }
|
||||
if (secondarySources != null) { project.setSecondarySources(secondarySources); }
|
||||
if (sourceVersion != null) { project.setSourceVersion(sourceVersion); }
|
||||
if (artifacts != null) { project.setArtifacts(artifacts); }
|
||||
if (secondaryArtifacts != null) { project.setSecondaryArtifacts(secondaryArtifacts); }
|
||||
if (environment != null) { project.setEnvironment(environment); }
|
||||
if (serviceRole != null) { project.setServiceRole(serviceRole); }
|
||||
if (timeoutInMinutes != null) { project.setTimeoutInMinutes(timeoutInMinutes); }
|
||||
if (queuedTimeoutInMinutes != null) { project.setQueuedTimeoutInMinutes(queuedTimeoutInMinutes); }
|
||||
if (encryptionKey != null) { project.setEncryptionKey(encryptionKey); }
|
||||
if (tags != null) { project.setTags(tags); }
|
||||
if (logsConfig != null) { project.setLogsConfig(logsConfig); }
|
||||
if (vpcConfig != null) { project.setVpcConfig(vpcConfig); }
|
||||
if (concurrentBuildLimit != null) { project.setConcurrentBuildLimit(concurrentBuildLimit); }
|
||||
project.setLastModified(Instant.now().toEpochMilli() / 1000.0);
|
||||
|
||||
return project;
|
||||
}
|
||||
|
||||
public void deleteProject(String region, String name) {
|
||||
Map<String, Project> store = projectsFor(region);
|
||||
if (store.remove(name) == null) {
|
||||
throw new AwsException("ResourceNotFoundException", "Project not found: " + name, 400);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Project> batchGetProjects(String region, List<String> names) {
|
||||
Map<String, Project> store = projectsFor(region);
|
||||
return names.stream()
|
||||
.map(store::get)
|
||||
.filter(p -> p != null)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<String> listProjects(String region) {
|
||||
return new ArrayList<>(projectsFor(region).keySet());
|
||||
}
|
||||
|
||||
// ---- Report Groups ----
|
||||
|
||||
public ReportGroup createReportGroup(String region, String account,
|
||||
String name, String type,
|
||||
Map<String, Object> exportConfig,
|
||||
List<Map<String, String>> tags) {
|
||||
Map<String, ReportGroup> store = reportGroupsFor(region);
|
||||
String arn = "arn:aws:codebuild:" + region + ":" + account + ":report-group/" + name;
|
||||
if (store.containsKey(arn)) {
|
||||
throw new AwsException("ResourceAlreadyExistsException",
|
||||
"Report group already exists: " + name, 400);
|
||||
}
|
||||
if (name == null || name.isBlank()) {
|
||||
throw new AwsException("InvalidInputException", "name is required", 400);
|
||||
}
|
||||
if (type == null) {
|
||||
throw new AwsException("InvalidInputException", "type is required", 400);
|
||||
}
|
||||
|
||||
double now = Instant.now().toEpochMilli() / 1000.0;
|
||||
ReportGroup rg = new ReportGroup();
|
||||
rg.setArn(arn);
|
||||
rg.setName(name);
|
||||
rg.setType(type);
|
||||
rg.setExportConfig(exportConfig);
|
||||
rg.setCreated(now);
|
||||
rg.setLastModified(now);
|
||||
rg.setTags(tags);
|
||||
rg.setStatus("ACTIVE");
|
||||
|
||||
store.put(arn, rg);
|
||||
return rg;
|
||||
}
|
||||
|
||||
public ReportGroup updateReportGroup(String region, String arn,
|
||||
Map<String, Object> exportConfig,
|
||||
List<Map<String, String>> tags) {
|
||||
Map<String, ReportGroup> store = reportGroupsFor(region);
|
||||
ReportGroup rg = store.get(arn);
|
||||
if (rg == null) {
|
||||
throw new AwsException("ResourceNotFoundException", "Report group not found: " + arn, 400);
|
||||
}
|
||||
if (exportConfig != null) { rg.setExportConfig(exportConfig); }
|
||||
if (tags != null) { rg.setTags(tags); }
|
||||
rg.setLastModified(Instant.now().toEpochMilli() / 1000.0);
|
||||
return rg;
|
||||
}
|
||||
|
||||
public void deleteReportGroup(String region, String arn) {
|
||||
Map<String, ReportGroup> store = reportGroupsFor(region);
|
||||
if (store.remove(arn) == null) {
|
||||
throw new AwsException("ResourceNotFoundException", "Report group not found: " + arn, 400);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ReportGroup> batchGetReportGroups(String region, List<String> arns) {
|
||||
Map<String, ReportGroup> store = reportGroupsFor(region);
|
||||
return arns.stream()
|
||||
.map(store::get)
|
||||
.filter(rg -> rg != null)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<String> listReportGroups(String region) {
|
||||
return new ArrayList<>(reportGroupsFor(region).keySet());
|
||||
}
|
||||
|
||||
// ---- Source Credentials ----
|
||||
|
||||
public SourceCredential importSourceCredentials(String region, String account,
|
||||
String token, String serverType, String authType,
|
||||
Boolean shouldOverwrite) {
|
||||
Map<String, SourceCredential> store = sourceCredentialsFor(region);
|
||||
// One credential per serverType+authType combo — overwrite existing by default
|
||||
String key = serverType + "/" + authType;
|
||||
SourceCredential existing = store.values().stream()
|
||||
.filter(c -> c.getServerType().equals(serverType) && c.getAuthType().equals(authType))
|
||||
.findFirst().orElse(null);
|
||||
if (existing != null && Boolean.FALSE.equals(shouldOverwrite)) {
|
||||
throw new AwsException("ResourceAlreadyExistsException",
|
||||
"Source credentials already exist for " + serverType + "/" + authType, 400);
|
||||
}
|
||||
|
||||
String arn = "arn:aws:codebuild:" + region + ":" + account + ":token/" + serverType.toLowerCase() + "-" + UUID.randomUUID();
|
||||
if (existing != null) {
|
||||
arn = existing.getArn();
|
||||
store.remove(existing.getArn());
|
||||
}
|
||||
|
||||
SourceCredential cred = new SourceCredential();
|
||||
cred.setArn(arn);
|
||||
cred.setServerType(serverType);
|
||||
cred.setAuthType(authType);
|
||||
// Token is accepted but not stored in plaintext in a returned field
|
||||
store.put(arn, cred);
|
||||
return cred;
|
||||
}
|
||||
|
||||
public List<SourceCredential> listSourceCredentials(String region) {
|
||||
return new ArrayList<>(sourceCredentialsFor(region).values());
|
||||
}
|
||||
|
||||
public void deleteSourceCredentials(String region, String arn) {
|
||||
Map<String, SourceCredential> store = sourceCredentialsFor(region);
|
||||
if (store.remove(arn) == null) {
|
||||
throw new AwsException("ResourceNotFoundException",
|
||||
"Source credentials not found: " + arn, 400);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Curated Environment Images ----
|
||||
|
||||
public List<Map<String, Object>> listCuratedEnvironmentImages() {
|
||||
// Return the standard CodeBuild curated platform/language/image list
|
||||
return List.of(
|
||||
Map.of("platform", "AMAZON_LINUX_2",
|
||||
"languages", List.of(
|
||||
Map.of("language", "JAVA",
|
||||
"images", List.of(
|
||||
Map.of("name", "aws/codebuild/amazonlinux2-x86_64-standard:5.0",
|
||||
"description", "AWS CodeBuild - amazonlinux2 - 5.0",
|
||||
"versions", List.of("aws/codebuild/amazonlinux2-x86_64-standard:5.0")))),
|
||||
Map.of("language", "PYTHON",
|
||||
"images", List.of(
|
||||
Map.of("name", "aws/codebuild/amazonlinux2-x86_64-standard:5.0",
|
||||
"description", "AWS CodeBuild - amazonlinux2 - 5.0",
|
||||
"versions", List.of("aws/codebuild/amazonlinux2-x86_64-standard:5.0")))),
|
||||
Map.of("language", "NODE_JS",
|
||||
"images", List.of(
|
||||
Map.of("name", "aws/codebuild/amazonlinux2-x86_64-standard:5.0",
|
||||
"description", "AWS CodeBuild - amazonlinux2 - 5.0",
|
||||
"versions", List.of("aws/codebuild/amazonlinux2-x86_64-standard:5.0")))))),
|
||||
Map.of("platform", "UBUNTU",
|
||||
"languages", List.of(
|
||||
Map.of("language", "JAVA",
|
||||
"images", List.of(
|
||||
Map.of("name", "aws/codebuild/standard:7.0",
|
||||
"description", "AWS CodeBuild - Ubuntu - 7.0",
|
||||
"versions", List.of("aws/codebuild/standard:7.0")))),
|
||||
Map.of("language", "PYTHON",
|
||||
"images", List.of(
|
||||
Map.of("name", "aws/codebuild/standard:7.0",
|
||||
"description", "AWS CodeBuild - Ubuntu - 7.0",
|
||||
"versions", List.of("aws/codebuild/standard:7.0")))),
|
||||
Map.of("language", "NODE_JS",
|
||||
"images", List.of(
|
||||
Map.of("name", "aws/codebuild/standard:7.0",
|
||||
"description", "AWS CodeBuild - Ubuntu - 7.0",
|
||||
"versions", List.of("aws/codebuild/standard:7.0")))))));
|
||||
}
|
||||
|
||||
private void validateProjectName(String name) {
|
||||
if (name == null || name.length() < 2 || name.length() > 150) {
|
||||
throw new AwsException("InvalidInputException",
|
||||
"Project name must be between 2 and 150 characters", 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package io.github.hectorvent.floci.services.codebuild.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class Project {
|
||||
public Project() {}
|
||||
|
||||
private String name;
|
||||
private String arn;
|
||||
private String description;
|
||||
private ProjectSource source;
|
||||
private List<ProjectSource> secondarySources;
|
||||
private String sourceVersion;
|
||||
private ProjectArtifacts artifacts;
|
||||
private List<ProjectArtifacts> secondaryArtifacts;
|
||||
private ProjectEnvironment environment;
|
||||
private String serviceRole;
|
||||
private Integer timeoutInMinutes;
|
||||
private Integer queuedTimeoutInMinutes;
|
||||
private String encryptionKey;
|
||||
private List<Map<String, String>> tags;
|
||||
private Double created;
|
||||
private Double lastModified;
|
||||
private Map<String, Object> logsConfig;
|
||||
private Map<String, Object> vpcConfig;
|
||||
private Integer concurrentBuildLimit;
|
||||
private String projectVisibility;
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public String getArn() { return arn; }
|
||||
public void setArn(String arn) { this.arn = arn; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public ProjectSource getSource() { return source; }
|
||||
public void setSource(ProjectSource source) { this.source = source; }
|
||||
|
||||
public List<ProjectSource> getSecondarySources() { return secondarySources; }
|
||||
public void setSecondarySources(List<ProjectSource> secondarySources) { this.secondarySources = secondarySources; }
|
||||
|
||||
public String getSourceVersion() { return sourceVersion; }
|
||||
public void setSourceVersion(String sourceVersion) { this.sourceVersion = sourceVersion; }
|
||||
|
||||
public ProjectArtifacts getArtifacts() { return artifacts; }
|
||||
public void setArtifacts(ProjectArtifacts artifacts) { this.artifacts = artifacts; }
|
||||
|
||||
public List<ProjectArtifacts> getSecondaryArtifacts() { return secondaryArtifacts; }
|
||||
public void setSecondaryArtifacts(List<ProjectArtifacts> secondaryArtifacts) { this.secondaryArtifacts = secondaryArtifacts; }
|
||||
|
||||
public ProjectEnvironment getEnvironment() { return environment; }
|
||||
public void setEnvironment(ProjectEnvironment environment) { this.environment = environment; }
|
||||
|
||||
public String getServiceRole() { return serviceRole; }
|
||||
public void setServiceRole(String serviceRole) { this.serviceRole = serviceRole; }
|
||||
|
||||
public Integer getTimeoutInMinutes() { return timeoutInMinutes; }
|
||||
public void setTimeoutInMinutes(Integer timeoutInMinutes) { this.timeoutInMinutes = timeoutInMinutes; }
|
||||
|
||||
public Integer getQueuedTimeoutInMinutes() { return queuedTimeoutInMinutes; }
|
||||
public void setQueuedTimeoutInMinutes(Integer queuedTimeoutInMinutes) { this.queuedTimeoutInMinutes = queuedTimeoutInMinutes; }
|
||||
|
||||
public String getEncryptionKey() { return encryptionKey; }
|
||||
public void setEncryptionKey(String encryptionKey) { this.encryptionKey = encryptionKey; }
|
||||
|
||||
public List<Map<String, String>> getTags() { return tags; }
|
||||
public void setTags(List<Map<String, String>> tags) { this.tags = tags; }
|
||||
|
||||
public Double getCreated() { return created; }
|
||||
public void setCreated(Double created) { this.created = created; }
|
||||
|
||||
public Double getLastModified() { return lastModified; }
|
||||
public void setLastModified(Double lastModified) { this.lastModified = lastModified; }
|
||||
|
||||
public Map<String, Object> getLogsConfig() { return logsConfig; }
|
||||
public void setLogsConfig(Map<String, Object> logsConfig) { this.logsConfig = logsConfig; }
|
||||
|
||||
public Map<String, Object> getVpcConfig() { return vpcConfig; }
|
||||
public void setVpcConfig(Map<String, Object> vpcConfig) { this.vpcConfig = vpcConfig; }
|
||||
|
||||
public Integer getConcurrentBuildLimit() { return concurrentBuildLimit; }
|
||||
public void setConcurrentBuildLimit(Integer concurrentBuildLimit) { this.concurrentBuildLimit = concurrentBuildLimit; }
|
||||
|
||||
public String getProjectVisibility() { return projectVisibility; }
|
||||
public void setProjectVisibility(String projectVisibility) { this.projectVisibility = projectVisibility; }
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package io.github.hectorvent.floci.services.codebuild.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class ProjectArtifacts {
|
||||
public ProjectArtifacts() {}
|
||||
|
||||
private String type;
|
||||
private String location;
|
||||
private String path;
|
||||
private String namespaceType;
|
||||
private String name;
|
||||
private String packaging;
|
||||
private Boolean overrideArtifactName;
|
||||
private Boolean encryptionDisabled;
|
||||
private String artifactIdentifier;
|
||||
|
||||
public String getType() { return type; }
|
||||
public void setType(String type) { this.type = type; }
|
||||
|
||||
public String getLocation() { return location; }
|
||||
public void setLocation(String location) { this.location = location; }
|
||||
|
||||
public String getPath() { return path; }
|
||||
public void setPath(String path) { this.path = path; }
|
||||
|
||||
public String getNamespaceType() { return namespaceType; }
|
||||
public void setNamespaceType(String namespaceType) { this.namespaceType = namespaceType; }
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public String getPackaging() { return packaging; }
|
||||
public void setPackaging(String packaging) { this.packaging = packaging; }
|
||||
|
||||
public Boolean getOverrideArtifactName() { return overrideArtifactName; }
|
||||
public void setOverrideArtifactName(Boolean overrideArtifactName) { this.overrideArtifactName = overrideArtifactName; }
|
||||
|
||||
public Boolean getEncryptionDisabled() { return encryptionDisabled; }
|
||||
public void setEncryptionDisabled(Boolean encryptionDisabled) { this.encryptionDisabled = encryptionDisabled; }
|
||||
|
||||
public String getArtifactIdentifier() { return artifactIdentifier; }
|
||||
public void setArtifactIdentifier(String artifactIdentifier) { this.artifactIdentifier = artifactIdentifier; }
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package io.github.hectorvent.floci.services.codebuild.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class ProjectEnvironment {
|
||||
public ProjectEnvironment() {}
|
||||
|
||||
private String type;
|
||||
private String image;
|
||||
private String computeType;
|
||||
private List<Map<String, String>> environmentVariables;
|
||||
private Boolean privilegedMode;
|
||||
private String certificate;
|
||||
private String imagePullCredentialsType;
|
||||
|
||||
public String getType() { return type; }
|
||||
public void setType(String type) { this.type = type; }
|
||||
|
||||
public String getImage() { return image; }
|
||||
public void setImage(String image) { this.image = image; }
|
||||
|
||||
public String getComputeType() { return computeType; }
|
||||
public void setComputeType(String computeType) { this.computeType = computeType; }
|
||||
|
||||
public List<Map<String, String>> getEnvironmentVariables() { return environmentVariables; }
|
||||
public void setEnvironmentVariables(List<Map<String, String>> environmentVariables) { this.environmentVariables = environmentVariables; }
|
||||
|
||||
public Boolean getPrivilegedMode() { return privilegedMode; }
|
||||
public void setPrivilegedMode(Boolean privilegedMode) { this.privilegedMode = privilegedMode; }
|
||||
|
||||
public String getCertificate() { return certificate; }
|
||||
public void setCertificate(String certificate) { this.certificate = certificate; }
|
||||
|
||||
public String getImagePullCredentialsType() { return imagePullCredentialsType; }
|
||||
public void setImagePullCredentialsType(String imagePullCredentialsType) { this.imagePullCredentialsType = imagePullCredentialsType; }
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package io.github.hectorvent.floci.services.codebuild.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class ProjectSource {
|
||||
public ProjectSource() {}
|
||||
|
||||
private String type;
|
||||
private String location;
|
||||
private Integer gitCloneDepth;
|
||||
private String buildspec;
|
||||
private Boolean reportBuildStatus;
|
||||
private Boolean insecureSsl;
|
||||
private String sourceIdentifier;
|
||||
|
||||
public String getType() { return type; }
|
||||
public void setType(String type) { this.type = type; }
|
||||
|
||||
public String getLocation() { return location; }
|
||||
public void setLocation(String location) { this.location = location; }
|
||||
|
||||
public Integer getGitCloneDepth() { return gitCloneDepth; }
|
||||
public void setGitCloneDepth(Integer gitCloneDepth) { this.gitCloneDepth = gitCloneDepth; }
|
||||
|
||||
public String getBuildspec() { return buildspec; }
|
||||
public void setBuildspec(String buildspec) { this.buildspec = buildspec; }
|
||||
|
||||
public Boolean getReportBuildStatus() { return reportBuildStatus; }
|
||||
public void setReportBuildStatus(Boolean reportBuildStatus) { this.reportBuildStatus = reportBuildStatus; }
|
||||
|
||||
public Boolean getInsecureSsl() { return insecureSsl; }
|
||||
public void setInsecureSsl(Boolean insecureSsl) { this.insecureSsl = insecureSsl; }
|
||||
|
||||
public String getSourceIdentifier() { return sourceIdentifier; }
|
||||
public void setSourceIdentifier(String sourceIdentifier) { this.sourceIdentifier = sourceIdentifier; }
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package io.github.hectorvent.floci.services.codebuild.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class ReportGroup {
|
||||
public ReportGroup() {}
|
||||
|
||||
private String arn;
|
||||
private String name;
|
||||
private String type;
|
||||
private Map<String, Object> exportConfig;
|
||||
private Double created;
|
||||
private Double lastModified;
|
||||
private List<Map<String, String>> tags;
|
||||
private String status;
|
||||
|
||||
public String getArn() { return arn; }
|
||||
public void setArn(String arn) { this.arn = arn; }
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public String getType() { return type; }
|
||||
public void setType(String type) { this.type = type; }
|
||||
|
||||
public Map<String, Object> getExportConfig() { return exportConfig; }
|
||||
public void setExportConfig(Map<String, Object> exportConfig) { this.exportConfig = exportConfig; }
|
||||
|
||||
public Double getCreated() { return created; }
|
||||
public void setCreated(Double created) { this.created = created; }
|
||||
|
||||
public Double getLastModified() { return lastModified; }
|
||||
public void setLastModified(Double lastModified) { this.lastModified = lastModified; }
|
||||
|
||||
public List<Map<String, String>> getTags() { return tags; }
|
||||
public void setTags(List<Map<String, String>> tags) { this.tags = tags; }
|
||||
|
||||
public String getStatus() { return status; }
|
||||
public void setStatus(String status) { this.status = status; }
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package io.github.hectorvent.floci.services.codebuild.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class SourceCredential {
|
||||
public SourceCredential() {}
|
||||
|
||||
private String arn;
|
||||
private String serverType;
|
||||
private String authType;
|
||||
private String token;
|
||||
|
||||
public String getArn() { return arn; }
|
||||
public void setArn(String arn) { this.arn = arn; }
|
||||
|
||||
public String getServerType() { return serverType; }
|
||||
public void setServerType(String serverType) { this.serverType = serverType; }
|
||||
|
||||
public String getAuthType() { return authType; }
|
||||
public void setAuthType(String authType) { this.authType = authType; }
|
||||
|
||||
public String getToken() { return token; }
|
||||
public void setToken(String token) { this.token = token; }
|
||||
}
|
||||
+233
@@ -0,0 +1,233 @@
|
||||
package io.github.hectorvent.floci.services.codedeploy;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.codedeploy.model.Application;
|
||||
import io.github.hectorvent.floci.services.codedeploy.model.DeploymentConfig;
|
||||
import io.github.hectorvent.floci.services.codedeploy.model.DeploymentGroup;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ApplicationScoped
|
||||
public class CodeDeployJsonHandler {
|
||||
|
||||
private final CodeDeployService service;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
@Inject
|
||||
public CodeDeployJsonHandler(CodeDeployService service, ObjectMapper mapper) {
|
||||
this.service = service;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public Response handle(String action, JsonNode request, String region) throws Exception {
|
||||
return switch (action) {
|
||||
case "CreateApplication" -> createApplication(request, region);
|
||||
case "GetApplication" -> getApplication(request, region);
|
||||
case "UpdateApplication" -> updateApplication(request, region);
|
||||
case "DeleteApplication" -> deleteApplication(request, region);
|
||||
case "ListApplications" -> listApplications(region);
|
||||
case "BatchGetApplications" -> batchGetApplications(request, region);
|
||||
case "CreateDeploymentGroup" -> createDeploymentGroup(request, region);
|
||||
case "GetDeploymentGroup" -> getDeploymentGroup(request, region);
|
||||
case "UpdateDeploymentGroup" -> updateDeploymentGroup(request, region);
|
||||
case "DeleteDeploymentGroup" -> deleteDeploymentGroup(request, region);
|
||||
case "ListDeploymentGroups" -> listDeploymentGroups(request, region);
|
||||
case "BatchGetDeploymentGroups" -> batchGetDeploymentGroups(request, region);
|
||||
case "CreateDeploymentConfig" -> createDeploymentConfig(request, region);
|
||||
case "GetDeploymentConfig" -> getDeploymentConfig(request, region);
|
||||
case "DeleteDeploymentConfig" -> deleteDeploymentConfig(request, region);
|
||||
case "ListDeploymentConfigs" -> listDeploymentConfigs(region);
|
||||
case "TagResource" -> tagResource(request);
|
||||
case "UntagResource" -> untagResource(request);
|
||||
case "ListTagsForResource" -> listTagsForResource(request);
|
||||
case "AddTagsToOnPremisesInstances", "RemoveTagsFromOnPremisesInstances" ->
|
||||
Response.ok(Map.of()).build();
|
||||
default -> throw new AwsException("InvalidAction", "Action " + action + " is not supported", 400);
|
||||
};
|
||||
}
|
||||
|
||||
private Response createApplication(JsonNode req, String region) {
|
||||
String name = req.path("applicationName").asText(null);
|
||||
String computePlatform = req.has("computePlatform") ? req.path("computePlatform").asText() : null;
|
||||
List<Map<String, String>> tags = parseTags(req, "tags");
|
||||
Application app = service.createApplication(region, name, computePlatform, tags);
|
||||
return Response.ok(Map.of("applicationId", app.getApplicationId())).build();
|
||||
}
|
||||
|
||||
private Response getApplication(JsonNode req, String region) {
|
||||
String name = req.path("applicationName").asText(null);
|
||||
Application app = service.getApplication(region, name);
|
||||
return Response.ok(Map.of("application", app)).build();
|
||||
}
|
||||
|
||||
private Response updateApplication(JsonNode req, String region) {
|
||||
String currentName = req.path("applicationName").asText(null);
|
||||
String newName = req.has("newApplicationName") ? req.path("newApplicationName").asText() : null;
|
||||
service.updateApplication(region, currentName, newName);
|
||||
return Response.ok(Map.of()).build();
|
||||
}
|
||||
|
||||
private Response deleteApplication(JsonNode req, String region) {
|
||||
String name = req.path("applicationName").asText(null);
|
||||
service.deleteApplication(region, name);
|
||||
return Response.ok(Map.of()).build();
|
||||
}
|
||||
|
||||
private Response listApplications(String region) {
|
||||
return Response.ok(Map.of("applications", service.listApplications(region))).build();
|
||||
}
|
||||
|
||||
private Response batchGetApplications(JsonNode req, String region) {
|
||||
List<String> names = new ArrayList<>();
|
||||
req.path("applicationNames").forEach(n -> names.add(n.asText()));
|
||||
List<Application> apps = service.batchGetApplications(region, names);
|
||||
return Response.ok(Map.of("applicationsInfo", apps)).build();
|
||||
}
|
||||
|
||||
private Response createDeploymentGroup(JsonNode req, String region) throws Exception {
|
||||
String appName = req.path("applicationName").asText(null);
|
||||
String groupName = req.path("deploymentGroupName").asText(null);
|
||||
String deploymentConfigName = req.has("deploymentConfigName") ? req.path("deploymentConfigName").asText() : null;
|
||||
String serviceRoleArn = req.has("serviceRoleArn") ? req.path("serviceRoleArn").asText() : null;
|
||||
Map<String, Object> fields = extractGroupFields(req);
|
||||
DeploymentGroup group = service.createDeploymentGroup(region, appName, groupName,
|
||||
deploymentConfigName, serviceRoleArn, fields);
|
||||
return Response.ok(Map.of("deploymentGroupId", group.getDeploymentGroupId())).build();
|
||||
}
|
||||
|
||||
private Response getDeploymentGroup(JsonNode req, String region) {
|
||||
String appName = req.path("applicationName").asText(null);
|
||||
String groupName = req.path("deploymentGroupName").asText(null);
|
||||
DeploymentGroup group = service.getDeploymentGroup(region, appName, groupName);
|
||||
return Response.ok(Map.of("deploymentGroupInfo", group)).build();
|
||||
}
|
||||
|
||||
private Response updateDeploymentGroup(JsonNode req, String region) throws Exception {
|
||||
String appName = req.path("applicationName").asText(null);
|
||||
String currentGroupName = req.path("currentDeploymentGroupName").asText(null);
|
||||
String newGroupName = req.has("newDeploymentGroupName") ? req.path("newDeploymentGroupName").asText() : null;
|
||||
String deploymentConfigName = req.has("deploymentConfigName") ? req.path("deploymentConfigName").asText() : null;
|
||||
String serviceRoleArn = req.has("serviceRoleArn") ? req.path("serviceRoleArn").asText() : null;
|
||||
Map<String, Object> fields = extractGroupFields(req);
|
||||
DeploymentGroup group = service.updateDeploymentGroup(region, appName, currentGroupName, newGroupName,
|
||||
deploymentConfigName, serviceRoleArn, fields);
|
||||
return Response.ok(Map.of()).build();
|
||||
}
|
||||
|
||||
private Response deleteDeploymentGroup(JsonNode req, String region) {
|
||||
String appName = req.path("applicationName").asText(null);
|
||||
String groupName = req.path("deploymentGroupName").asText(null);
|
||||
service.deleteDeploymentGroup(region, appName, groupName);
|
||||
return Response.ok(Map.of("hooksNotCleanedUp", List.of())).build();
|
||||
}
|
||||
|
||||
private Response listDeploymentGroups(JsonNode req, String region) {
|
||||
String appName = req.path("applicationName").asText(null);
|
||||
List<String> groups = service.listDeploymentGroups(region, appName);
|
||||
return Response.ok(Map.of("applicationName", appName, "deploymentGroups", groups)).build();
|
||||
}
|
||||
|
||||
private Response batchGetDeploymentGroups(JsonNode req, String region) {
|
||||
String appName = req.path("applicationName").asText(null);
|
||||
List<String> names = new ArrayList<>();
|
||||
req.path("deploymentGroupNames").forEach(n -> names.add(n.asText()));
|
||||
List<DeploymentGroup> found = service.batchGetDeploymentGroups(region, appName, names);
|
||||
List<String> foundNames = found.stream().map(DeploymentGroup::getDeploymentGroupName).toList();
|
||||
List<String> notFound = names.stream().filter(n -> !foundNames.contains(n)).toList();
|
||||
return Response.ok(Map.of("deploymentGroupsInfo", found, "errorMessage", "")).build();
|
||||
}
|
||||
|
||||
private Response createDeploymentConfig(JsonNode req, String region) throws Exception {
|
||||
String name = req.path("deploymentConfigName").asText(null);
|
||||
Map<String, Object> minimumHealthyHosts = req.has("minimumHealthyHosts")
|
||||
? mapper.treeToValue(req.get("minimumHealthyHosts"), Map.class) : null;
|
||||
String computePlatform = req.has("computePlatform") ? req.path("computePlatform").asText() : null;
|
||||
Map<String, Object> trafficRoutingConfig = req.has("trafficRoutingConfig")
|
||||
? mapper.treeToValue(req.get("trafficRoutingConfig"), Map.class) : null;
|
||||
Map<String, Object> zonalConfig = req.has("zonalConfig")
|
||||
? mapper.treeToValue(req.get("zonalConfig"), Map.class) : null;
|
||||
DeploymentConfig cfg = service.createDeploymentConfig(region, name, minimumHealthyHosts,
|
||||
computePlatform, trafficRoutingConfig, zonalConfig);
|
||||
return Response.ok(Map.of("deploymentConfigId", cfg.getDeploymentConfigId())).build();
|
||||
}
|
||||
|
||||
private Response getDeploymentConfig(JsonNode req, String region) {
|
||||
String name = req.path("deploymentConfigName").asText(null);
|
||||
DeploymentConfig cfg = service.getDeploymentConfig(region, name);
|
||||
return Response.ok(Map.of("deploymentConfigInfo", cfg)).build();
|
||||
}
|
||||
|
||||
private Response deleteDeploymentConfig(JsonNode req, String region) {
|
||||
String name = req.path("deploymentConfigName").asText(null);
|
||||
service.deleteDeploymentConfig(region, name);
|
||||
return Response.ok(Map.of()).build();
|
||||
}
|
||||
|
||||
private Response listDeploymentConfigs(String region) {
|
||||
return Response.ok(Map.of("deploymentConfigsList", service.listDeploymentConfigs(region))).build();
|
||||
}
|
||||
|
||||
private Response tagResource(JsonNode req) {
|
||||
String arn = req.path("ResourceArn").asText(null);
|
||||
List<Map<String, String>> tags = parseTags(req, "Tags");
|
||||
service.tagResource(arn, tags);
|
||||
return Response.ok(Map.of()).build();
|
||||
}
|
||||
|
||||
private Response untagResource(JsonNode req) {
|
||||
String arn = req.path("ResourceArn").asText(null);
|
||||
List<String> keys = new ArrayList<>();
|
||||
req.path("TagKeys").forEach(k -> keys.add(k.asText()));
|
||||
service.untagResource(arn, keys);
|
||||
return Response.ok(Map.of()).build();
|
||||
}
|
||||
|
||||
private Response listTagsForResource(JsonNode req) {
|
||||
String arn = req.path("ResourceArn").asText(null);
|
||||
List<Map<String, String>> tags = service.listTagsForResource(arn);
|
||||
return Response.ok(Map.of("Tags", tags)).build();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> extractGroupFields(JsonNode req) throws Exception {
|
||||
Map<String, Object> fields = new HashMap<>();
|
||||
for (String field : new String[]{"ec2TagFilters", "onPremisesInstanceTagFilters", "autoScalingGroups",
|
||||
"deploymentStyle", "blueGreenDeploymentConfiguration", "loadBalancerInfo",
|
||||
"ec2TagSet", "onPremisesTagSet", "alarmConfiguration", "autoRollbackConfiguration",
|
||||
"triggerConfigurations", "ecsServices", "computePlatform",
|
||||
"outdatedInstancesStrategy", "terminationHookEnabled"}) {
|
||||
if (req.has(field)) {
|
||||
fields.put(field, mapper.treeToValue(req.get(field), Object.class));
|
||||
}
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
private List<Map<String, String>> parseTags(JsonNode req, String fieldName) {
|
||||
if (!req.has(fieldName) || req.get(fieldName).isNull()) {
|
||||
return List.of();
|
||||
}
|
||||
List<Map<String, String>> result = new ArrayList<>();
|
||||
for (JsonNode tag : req.get(fieldName)) {
|
||||
Map<String, String> t = new HashMap<>();
|
||||
// Support both capitalizations (Tags uses Key/Value, tags uses key/value)
|
||||
if (tag.has("Key")) {
|
||||
t.put("Key", tag.path("Key").asText());
|
||||
t.put("Value", tag.path("Value").asText());
|
||||
} else {
|
||||
t.put("Key", tag.path("key").asText());
|
||||
t.put("Value", tag.path("value").asText());
|
||||
}
|
||||
result.add(t);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,427 @@
|
||||
package io.github.hectorvent.floci.services.codedeploy;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.codedeploy.model.Application;
|
||||
import io.github.hectorvent.floci.services.codedeploy.model.DeploymentConfig;
|
||||
import io.github.hectorvent.floci.services.codedeploy.model.DeploymentGroup;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ApplicationScoped
|
||||
public class CodeDeployService {
|
||||
|
||||
// key: region -> name -> application
|
||||
private final ConcurrentHashMap<String, ConcurrentHashMap<String, Application>> applications = new ConcurrentHashMap<>();
|
||||
// key: region -> appName -> groupName -> group
|
||||
private final ConcurrentHashMap<String, ConcurrentHashMap<String, ConcurrentHashMap<String, DeploymentGroup>>> deploymentGroups = new ConcurrentHashMap<>();
|
||||
// key: region -> configName -> config (pre-seeded with built-ins)
|
||||
private final ConcurrentHashMap<String, ConcurrentHashMap<String, DeploymentConfig>> deploymentConfigs = new ConcurrentHashMap<>();
|
||||
// key: resourceArn -> tags
|
||||
private final ConcurrentHashMap<String, Map<String, String>> tags = new ConcurrentHashMap<>();
|
||||
|
||||
private static final List<String> BUILT_IN_CONFIG_NAMES = List.of(
|
||||
"CodeDeployDefault.OneAtATime",
|
||||
"CodeDeployDefault.HalfAtATime",
|
||||
"CodeDeployDefault.AllAtOnce",
|
||||
"CodeDeployDefault.LambdaAllAtOnce",
|
||||
"CodeDeployDefault.LambdaCanary10Percent5Minutes",
|
||||
"CodeDeployDefault.LambdaCanary10Percent10Minutes",
|
||||
"CodeDeployDefault.LambdaCanary10Percent15Minutes",
|
||||
"CodeDeployDefault.LambdaCanary10Percent30Minutes",
|
||||
"CodeDeployDefault.LambdaLinear10PercentEvery1Minute",
|
||||
"CodeDeployDefault.LambdaLinear10PercentEvery2Minutes",
|
||||
"CodeDeployDefault.LambdaLinear10PercentEvery3Minutes",
|
||||
"CodeDeployDefault.LambdaLinear10PercentEvery10Minutes",
|
||||
"CodeDeployDefault.ECSAllAtOnce",
|
||||
"CodeDeployDefault.ECSCanary10Percent5Minutes",
|
||||
"CodeDeployDefault.ECSCanary10Percent15Minutes",
|
||||
"CodeDeployDefault.ECSLinear10PercentEvery1Minutes",
|
||||
"CodeDeployDefault.ECSLinear10PercentEvery3Minutes"
|
||||
);
|
||||
|
||||
private Map<String, Application> applicationsFor(String region) {
|
||||
return applications.computeIfAbsent(region, r -> new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
private Map<String, ConcurrentHashMap<String, DeploymentGroup>> deploymentGroupsFor(String region) {
|
||||
return deploymentGroups.computeIfAbsent(region, r -> new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
private Map<String, DeploymentConfig> deploymentConfigsFor(String region) {
|
||||
return deploymentConfigs.computeIfAbsent(region, r -> {
|
||||
ConcurrentHashMap<String, DeploymentConfig> store = new ConcurrentHashMap<>();
|
||||
double now = Instant.now().toEpochMilli() / 1000.0;
|
||||
for (String name : BUILT_IN_CONFIG_NAMES) {
|
||||
store.put(name, buildBuiltInConfig(name, now));
|
||||
}
|
||||
return store;
|
||||
});
|
||||
}
|
||||
|
||||
private DeploymentConfig buildBuiltInConfig(String name, double now) {
|
||||
DeploymentConfig cfg = new DeploymentConfig();
|
||||
cfg.setDeploymentConfigId("d-" + UUID.randomUUID().toString().replace("-", "").substring(0, 10).toUpperCase());
|
||||
cfg.setDeploymentConfigName(name);
|
||||
cfg.setCreateTime(now);
|
||||
|
||||
if (name.startsWith("CodeDeployDefault.Lambda")) {
|
||||
cfg.setComputePlatform("Lambda");
|
||||
if (name.equals("CodeDeployDefault.LambdaAllAtOnce")) {
|
||||
cfg.setTrafficRoutingConfig(Map.of("type", "AllAtOnce"));
|
||||
} else if (name.contains("Canary")) {
|
||||
int pct = 10;
|
||||
int minutes = extractMinutes(name);
|
||||
cfg.setTrafficRoutingConfig(Map.of("type", "TimeBasedCanary",
|
||||
"timeBasedCanary", Map.of("canaryPercentage", pct, "canaryInterval", minutes)));
|
||||
} else if (name.contains("Linear")) {
|
||||
int pct = 10;
|
||||
int minutes = extractMinutes(name);
|
||||
cfg.setTrafficRoutingConfig(Map.of("type", "TimeBasedLinear",
|
||||
"timeBasedLinear", Map.of("linearPercentage", pct, "linearInterval", minutes)));
|
||||
}
|
||||
} else if (name.startsWith("CodeDeployDefault.ECS")) {
|
||||
cfg.setComputePlatform("ECS");
|
||||
if (name.equals("CodeDeployDefault.ECSAllAtOnce")) {
|
||||
cfg.setTrafficRoutingConfig(Map.of("type", "AllAtOnce"));
|
||||
} else if (name.contains("Canary")) {
|
||||
int pct = 10;
|
||||
int minutes = extractMinutes(name);
|
||||
cfg.setTrafficRoutingConfig(Map.of("type", "TimeBasedCanary",
|
||||
"timeBasedCanary", Map.of("canaryPercentage", pct, "canaryInterval", minutes)));
|
||||
} else if (name.contains("Linear")) {
|
||||
int pct = 10;
|
||||
int minutes = extractMinutes(name);
|
||||
cfg.setTrafficRoutingConfig(Map.of("type", "TimeBasedLinear",
|
||||
"timeBasedLinear", Map.of("linearPercentage", pct, "linearInterval", minutes)));
|
||||
}
|
||||
} else {
|
||||
cfg.setComputePlatform("Server");
|
||||
if (name.equals("CodeDeployDefault.AllAtOnce")) {
|
||||
cfg.setMinimumHealthyHosts(Map.of("type", "FLEET_PERCENT", "value", 0));
|
||||
} else if (name.equals("CodeDeployDefault.HalfAtATime")) {
|
||||
cfg.setMinimumHealthyHosts(Map.of("type", "FLEET_PERCENT", "value", 50));
|
||||
} else {
|
||||
cfg.setMinimumHealthyHosts(Map.of("type", "HOST_COUNT", "value", 1));
|
||||
}
|
||||
}
|
||||
return cfg;
|
||||
}
|
||||
|
||||
private int extractMinutes(String name) {
|
||||
// e.g. "…Every1Minute" -> 1, "…5Minutes" -> 5
|
||||
java.util.regex.Matcher m = java.util.regex.Pattern.compile("(\\d+)Minute").matcher(name);
|
||||
return m.find() ? Integer.parseInt(m.group(1)) : 1;
|
||||
}
|
||||
|
||||
// ---- Applications ----
|
||||
|
||||
public Application createApplication(String region, String name, String computePlatform,
|
||||
List<Map<String, String>> tags) {
|
||||
Map<String, Application> store = applicationsFor(region);
|
||||
if (store.containsKey(name)) {
|
||||
throw new AwsException("ApplicationAlreadyExistsException",
|
||||
"Application already exists: " + name, 400);
|
||||
}
|
||||
Application app = new Application();
|
||||
app.setApplicationId(UUID.randomUUID().toString());
|
||||
app.setApplicationName(name);
|
||||
app.setCreateTime(Instant.now().toEpochMilli() / 1000.0);
|
||||
app.setLinkedToGitHub(false);
|
||||
app.setComputePlatform(computePlatform != null ? computePlatform : "Server");
|
||||
store.put(name, app);
|
||||
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
String arn = applicationArn(region, name);
|
||||
applyTags(arn, tags);
|
||||
}
|
||||
return app;
|
||||
}
|
||||
|
||||
public Application getApplication(String region, String name) {
|
||||
Application app = applicationsFor(region).get(name);
|
||||
if (app == null) {
|
||||
throw new AwsException("ApplicationDoesNotExistException",
|
||||
"Application does not exist: " + name, 400);
|
||||
}
|
||||
return app;
|
||||
}
|
||||
|
||||
public void updateApplication(String region, String currentName, String newName) {
|
||||
Map<String, Application> store = applicationsFor(region);
|
||||
Application app = store.get(currentName);
|
||||
if (app == null) {
|
||||
throw new AwsException("ApplicationDoesNotExistException",
|
||||
"Application does not exist: " + currentName, 400);
|
||||
}
|
||||
if (newName != null && !newName.equals(currentName)) {
|
||||
if (store.containsKey(newName)) {
|
||||
throw new AwsException("ApplicationAlreadyExistsException",
|
||||
"Application already exists: " + newName, 400);
|
||||
}
|
||||
store.remove(currentName);
|
||||
app.setApplicationName(newName);
|
||||
store.put(newName, app);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteApplication(String region, String name) {
|
||||
if (applicationsFor(region).remove(name) == null) {
|
||||
throw new AwsException("ApplicationDoesNotExistException",
|
||||
"Application does not exist: " + name, 400);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> listApplications(String region) {
|
||||
return new ArrayList<>(applicationsFor(region).keySet());
|
||||
}
|
||||
|
||||
public List<Application> batchGetApplications(String region, List<String> names) {
|
||||
Map<String, Application> store = applicationsFor(region);
|
||||
return names.stream()
|
||||
.map(n -> {
|
||||
Application a = store.get(n);
|
||||
if (a == null) {
|
||||
throw new AwsException("ApplicationDoesNotExistException",
|
||||
"Application does not exist: " + n, 400);
|
||||
}
|
||||
return a;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// ---- Deployment Groups ----
|
||||
|
||||
public DeploymentGroup createDeploymentGroup(String region, String appName, String groupName,
|
||||
String deploymentConfigName, String serviceRoleArn,
|
||||
Map<String, Object> fields) {
|
||||
getApplication(region, appName);
|
||||
Map<String, ConcurrentHashMap<String, DeploymentGroup>> appGroups = deploymentGroupsFor(region);
|
||||
ConcurrentHashMap<String, DeploymentGroup> groupStore = appGroups.computeIfAbsent(appName, a -> new ConcurrentHashMap<>());
|
||||
if (groupStore.containsKey(groupName)) {
|
||||
throw new AwsException("DeploymentGroupAlreadyExistsException",
|
||||
"Deployment group already exists: " + groupName, 400);
|
||||
}
|
||||
|
||||
DeploymentGroup group = new DeploymentGroup();
|
||||
group.setApplicationName(appName);
|
||||
group.setDeploymentGroupId(UUID.randomUUID().toString());
|
||||
group.setDeploymentGroupName(groupName);
|
||||
group.setDeploymentConfigName(deploymentConfigName != null ? deploymentConfigName : "CodeDeployDefault.OneAtATime");
|
||||
group.setServiceRoleArn(serviceRoleArn);
|
||||
applyGroupFields(group, fields);
|
||||
groupStore.put(groupName, group);
|
||||
return group;
|
||||
}
|
||||
|
||||
public DeploymentGroup getDeploymentGroup(String region, String appName, String groupName) {
|
||||
getApplication(region, appName);
|
||||
Map<String, ConcurrentHashMap<String, DeploymentGroup>> appGroups = deploymentGroupsFor(region);
|
||||
ConcurrentHashMap<String, DeploymentGroup> groupStore = appGroups.get(appName);
|
||||
DeploymentGroup group = groupStore != null ? groupStore.get(groupName) : null;
|
||||
if (group == null) {
|
||||
throw new AwsException("DeploymentGroupDoesNotExistException",
|
||||
"Deployment group does not exist: " + groupName, 400);
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
public DeploymentGroup updateDeploymentGroup(String region, String appName,
|
||||
String currentGroupName, String newGroupName,
|
||||
String deploymentConfigName, String serviceRoleArn,
|
||||
Map<String, Object> fields) {
|
||||
DeploymentGroup group = getDeploymentGroup(region, appName, currentGroupName);
|
||||
ConcurrentHashMap<String, DeploymentGroup> groupStore = deploymentGroupsFor(region)
|
||||
.computeIfAbsent(appName, a -> new ConcurrentHashMap<>());
|
||||
|
||||
if (deploymentConfigName != null) { group.setDeploymentConfigName(deploymentConfigName); }
|
||||
if (serviceRoleArn != null) { group.setServiceRoleArn(serviceRoleArn); }
|
||||
applyGroupFields(group, fields);
|
||||
|
||||
if (newGroupName != null && !newGroupName.equals(currentGroupName)) {
|
||||
groupStore.remove(currentGroupName);
|
||||
group.setDeploymentGroupName(newGroupName);
|
||||
groupStore.put(newGroupName, group);
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
public void deleteDeploymentGroup(String region, String appName, String groupName) {
|
||||
getApplication(region, appName);
|
||||
Map<String, ConcurrentHashMap<String, DeploymentGroup>> appGroups = deploymentGroupsFor(region);
|
||||
ConcurrentHashMap<String, DeploymentGroup> groupStore = appGroups.get(appName);
|
||||
if (groupStore == null || groupStore.remove(groupName) == null) {
|
||||
throw new AwsException("DeploymentGroupDoesNotExistException",
|
||||
"Deployment group does not exist: " + groupName, 400);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> listDeploymentGroups(String region, String appName) {
|
||||
getApplication(region, appName);
|
||||
Map<String, ConcurrentHashMap<String, DeploymentGroup>> appGroups = deploymentGroupsFor(region);
|
||||
ConcurrentHashMap<String, DeploymentGroup> groupStore = appGroups.get(appName);
|
||||
return groupStore != null ? new ArrayList<>(groupStore.keySet()) : List.of();
|
||||
}
|
||||
|
||||
public List<DeploymentGroup> batchGetDeploymentGroups(String region, String appName, List<String> names) {
|
||||
getApplication(region, appName);
|
||||
Map<String, ConcurrentHashMap<String, DeploymentGroup>> appGroups = deploymentGroupsFor(region);
|
||||
ConcurrentHashMap<String, DeploymentGroup> groupStore = appGroups.get(appName);
|
||||
if (groupStore == null) {
|
||||
return List.of();
|
||||
}
|
||||
return names.stream()
|
||||
.map(groupStore::get)
|
||||
.filter(g -> g != null)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// ---- Deployment Configs ----
|
||||
|
||||
public DeploymentConfig createDeploymentConfig(String region, String name,
|
||||
Map<String, Object> minimumHealthyHosts,
|
||||
String computePlatform,
|
||||
Map<String, Object> trafficRoutingConfig,
|
||||
Map<String, Object> zonalConfig) {
|
||||
Map<String, DeploymentConfig> store = deploymentConfigsFor(region);
|
||||
if (store.containsKey(name)) {
|
||||
throw new AwsException("DeploymentConfigAlreadyExistsException",
|
||||
"Deployment configuration already exists: " + name, 400);
|
||||
}
|
||||
if (name.startsWith("CodeDeployDefault.")) {
|
||||
throw new AwsException("InvalidDeploymentConfigNameException",
|
||||
"Cannot create a deployment configuration starting with 'CodeDeployDefault.'", 400);
|
||||
}
|
||||
DeploymentConfig cfg = new DeploymentConfig();
|
||||
cfg.setDeploymentConfigId(UUID.randomUUID().toString());
|
||||
cfg.setDeploymentConfigName(name);
|
||||
cfg.setMinimumHealthyHosts(minimumHealthyHosts);
|
||||
cfg.setCreateTime(Instant.now().toEpochMilli() / 1000.0);
|
||||
cfg.setComputePlatform(computePlatform != null ? computePlatform : "Server");
|
||||
cfg.setTrafficRoutingConfig(trafficRoutingConfig);
|
||||
cfg.setZonalConfig(zonalConfig);
|
||||
store.put(name, cfg);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public DeploymentConfig getDeploymentConfig(String region, String name) {
|
||||
DeploymentConfig cfg = deploymentConfigsFor(region).get(name);
|
||||
if (cfg == null) {
|
||||
throw new AwsException("DeploymentConfigDoesNotExistException",
|
||||
"Deployment configuration does not exist: " + name, 400);
|
||||
}
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public void deleteDeploymentConfig(String region, String name) {
|
||||
if (name.startsWith("CodeDeployDefault.")) {
|
||||
throw new AwsException("InvalidDeploymentConfigNameException",
|
||||
"Cannot delete a built-in deployment configuration.", 400);
|
||||
}
|
||||
if (deploymentConfigsFor(region).remove(name) == null) {
|
||||
throw new AwsException("DeploymentConfigDoesNotExistException",
|
||||
"Deployment configuration does not exist: " + name, 400);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> listDeploymentConfigs(String region) {
|
||||
return new ArrayList<>(deploymentConfigsFor(region).keySet());
|
||||
}
|
||||
|
||||
// ---- Tags ----
|
||||
|
||||
public void tagResource(String arn, List<Map<String, String>> tagList) {
|
||||
Map<String, String> tagMap = tags.computeIfAbsent(arn, k -> new ConcurrentHashMap<>());
|
||||
for (Map<String, String> t : tagList) {
|
||||
tagMap.put(t.get("Key"), t.get("Value"));
|
||||
}
|
||||
}
|
||||
|
||||
public void untagResource(String arn, List<String> tagKeys) {
|
||||
Map<String, String> tagMap = tags.get(arn);
|
||||
if (tagMap != null) {
|
||||
tagKeys.forEach(tagMap::remove);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Map<String, String>> listTagsForResource(String arn) {
|
||||
Map<String, String> tagMap = tags.getOrDefault(arn, Map.of());
|
||||
return tagMap.entrySet().stream()
|
||||
.map(e -> Map.of("Key", e.getKey(), "Value", e.getValue()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public String applicationArn(String region, String name) {
|
||||
return "arn:aws:codedeploy:" + region + ":000000000000:application:" + name;
|
||||
}
|
||||
|
||||
public String deploymentGroupArn(String region, String appName, String groupName) {
|
||||
return "arn:aws:codedeploy:" + region + ":000000000000:deploymentgroup:" + appName + "/" + groupName;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void applyGroupFields(DeploymentGroup group, Map<String, Object> fields) {
|
||||
if (fields == null) { return; }
|
||||
Object ec2TagFilters = fields.get("ec2TagFilters");
|
||||
if (ec2TagFilters instanceof List<?> list) {
|
||||
group.setEc2TagFilters((List<Map<String, String>>) list);
|
||||
}
|
||||
Object onPremTagFilters = fields.get("onPremisesInstanceTagFilters");
|
||||
if (onPremTagFilters instanceof List<?> list) {
|
||||
group.setOnPremisesInstanceTagFilters((List<Map<String, String>>) list);
|
||||
}
|
||||
Object asg = fields.get("autoScalingGroups");
|
||||
if (asg instanceof List<?> list) {
|
||||
group.setAutoScalingGroups((List<Map<String, Object>>) list);
|
||||
}
|
||||
setMapField(group, fields, "deploymentStyle", DeploymentGroup::setDeploymentStyle);
|
||||
setMapField(group, fields, "blueGreenDeploymentConfiguration", DeploymentGroup::setBlueGreenDeploymentConfiguration);
|
||||
setMapField(group, fields, "loadBalancerInfo", DeploymentGroup::setLoadBalancerInfo);
|
||||
setMapField(group, fields, "ec2TagSet", DeploymentGroup::setEc2TagSet);
|
||||
setMapField(group, fields, "onPremisesTagSet", DeploymentGroup::setOnPremisesTagSet);
|
||||
setMapField(group, fields, "alarmConfiguration", DeploymentGroup::setAlarmConfiguration);
|
||||
setMapField(group, fields, "autoRollbackConfiguration", DeploymentGroup::setAutoRollbackConfiguration);
|
||||
Object triggerConfigs = fields.get("triggerConfigurations");
|
||||
if (triggerConfigs instanceof List<?> list) {
|
||||
group.setTriggerConfigurations((List<Map<String, Object>>) list);
|
||||
}
|
||||
Object ecsServices = fields.get("ecsServices");
|
||||
if (ecsServices instanceof List<?> list) {
|
||||
group.setEcsServices((List<Map<String, Object>>) list);
|
||||
}
|
||||
if (fields.containsKey("computePlatform")) {
|
||||
group.setComputePlatform((String) fields.get("computePlatform"));
|
||||
}
|
||||
if (fields.containsKey("outdatedInstancesStrategy")) {
|
||||
group.setOutdatedInstancesStrategy((String) fields.get("outdatedInstancesStrategy"));
|
||||
}
|
||||
if (fields.containsKey("terminationHookEnabled")) {
|
||||
group.setTerminationHookEnabled((Boolean) fields.get("terminationHookEnabled"));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void setMapField(DeploymentGroup group, Map<String, Object> fields, String key,
|
||||
java.util.function.BiConsumer<DeploymentGroup, Map<String, Object>> setter) {
|
||||
Object val = fields.get(key);
|
||||
if (val instanceof Map<?, ?> m) {
|
||||
setter.accept(group, (Map<String, Object>) m);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyTags(String arn, List<Map<String, String>> tagList) {
|
||||
Map<String, String> tagMap = tags.computeIfAbsent(arn, k -> new ConcurrentHashMap<>());
|
||||
for (Map<String, String> t : tagList) {
|
||||
String key = t.containsKey("Key") ? t.get("Key") : t.get("key");
|
||||
String value = t.containsKey("Value") ? t.get("Value") : t.get("value");
|
||||
if (key != null) { tagMap.put(key, value != null ? value : ""); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package io.github.hectorvent.floci.services.codedeploy.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class Application {
|
||||
public Application() {}
|
||||
|
||||
private String applicationId;
|
||||
private String applicationName;
|
||||
private Double createTime;
|
||||
private Boolean linkedToGitHub;
|
||||
private String gitHubAccountName;
|
||||
private String computePlatform;
|
||||
|
||||
public String getApplicationId() { return applicationId; }
|
||||
public void setApplicationId(String applicationId) { this.applicationId = applicationId; }
|
||||
|
||||
public String getApplicationName() { return applicationName; }
|
||||
public void setApplicationName(String applicationName) { this.applicationName = applicationName; }
|
||||
|
||||
public Double getCreateTime() { return createTime; }
|
||||
public void setCreateTime(Double createTime) { this.createTime = createTime; }
|
||||
|
||||
public Boolean getLinkedToGitHub() { return linkedToGitHub; }
|
||||
public void setLinkedToGitHub(Boolean linkedToGitHub) { this.linkedToGitHub = linkedToGitHub; }
|
||||
|
||||
public String getGitHubAccountName() { return gitHubAccountName; }
|
||||
public void setGitHubAccountName(String gitHubAccountName) { this.gitHubAccountName = gitHubAccountName; }
|
||||
|
||||
public String getComputePlatform() { return computePlatform; }
|
||||
public void setComputePlatform(String computePlatform) { this.computePlatform = computePlatform; }
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package io.github.hectorvent.floci.services.codedeploy.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class DeploymentConfig {
|
||||
public DeploymentConfig() {}
|
||||
|
||||
private String deploymentConfigId;
|
||||
private String deploymentConfigName;
|
||||
private Map<String, Object> minimumHealthyHosts;
|
||||
private Double createTime;
|
||||
private String computePlatform;
|
||||
private Map<String, Object> trafficRoutingConfig;
|
||||
private Map<String, Object> zonalConfig;
|
||||
|
||||
public String getDeploymentConfigId() { return deploymentConfigId; }
|
||||
public void setDeploymentConfigId(String deploymentConfigId) { this.deploymentConfigId = deploymentConfigId; }
|
||||
|
||||
public String getDeploymentConfigName() { return deploymentConfigName; }
|
||||
public void setDeploymentConfigName(String deploymentConfigName) { this.deploymentConfigName = deploymentConfigName; }
|
||||
|
||||
public Map<String, Object> getMinimumHealthyHosts() { return minimumHealthyHosts; }
|
||||
public void setMinimumHealthyHosts(Map<String, Object> minimumHealthyHosts) { this.minimumHealthyHosts = minimumHealthyHosts; }
|
||||
|
||||
public Double getCreateTime() { return createTime; }
|
||||
public void setCreateTime(Double createTime) { this.createTime = createTime; }
|
||||
|
||||
public String getComputePlatform() { return computePlatform; }
|
||||
public void setComputePlatform(String computePlatform) { this.computePlatform = computePlatform; }
|
||||
|
||||
public Map<String, Object> getTrafficRoutingConfig() { return trafficRoutingConfig; }
|
||||
public void setTrafficRoutingConfig(Map<String, Object> trafficRoutingConfig) { this.trafficRoutingConfig = trafficRoutingConfig; }
|
||||
|
||||
public Map<String, Object> getZonalConfig() { return zonalConfig; }
|
||||
public void setZonalConfig(Map<String, Object> zonalConfig) { this.zonalConfig = zonalConfig; }
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
package io.github.hectorvent.floci.services.codedeploy.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class DeploymentGroup {
|
||||
public DeploymentGroup() {}
|
||||
|
||||
private String applicationName;
|
||||
private String deploymentGroupId;
|
||||
private String deploymentGroupName;
|
||||
private String deploymentConfigName;
|
||||
private String serviceRoleArn;
|
||||
private List<Map<String, String>> ec2TagFilters;
|
||||
private List<Map<String, String>> onPremisesInstanceTagFilters;
|
||||
private List<Map<String, Object>> autoScalingGroups;
|
||||
private Map<String, Object> deploymentStyle;
|
||||
private Map<String, Object> blueGreenDeploymentConfiguration;
|
||||
private Map<String, Object> loadBalancerInfo;
|
||||
private Map<String, Object> ec2TagSet;
|
||||
private Map<String, Object> onPremisesTagSet;
|
||||
private Map<String, Object> alarmConfiguration;
|
||||
private Map<String, Object> autoRollbackConfiguration;
|
||||
private List<Map<String, Object>> triggerConfigurations;
|
||||
private List<Map<String, Object>> ecsServices;
|
||||
private String computePlatform;
|
||||
private String outdatedInstancesStrategy;
|
||||
private Boolean terminationHookEnabled;
|
||||
|
||||
public String getApplicationName() { return applicationName; }
|
||||
public void setApplicationName(String applicationName) { this.applicationName = applicationName; }
|
||||
|
||||
public String getDeploymentGroupId() { return deploymentGroupId; }
|
||||
public void setDeploymentGroupId(String deploymentGroupId) { this.deploymentGroupId = deploymentGroupId; }
|
||||
|
||||
public String getDeploymentGroupName() { return deploymentGroupName; }
|
||||
public void setDeploymentGroupName(String deploymentGroupName) { this.deploymentGroupName = deploymentGroupName; }
|
||||
|
||||
public String getDeploymentConfigName() { return deploymentConfigName; }
|
||||
public void setDeploymentConfigName(String deploymentConfigName) { this.deploymentConfigName = deploymentConfigName; }
|
||||
|
||||
public String getServiceRoleArn() { return serviceRoleArn; }
|
||||
public void setServiceRoleArn(String serviceRoleArn) { this.serviceRoleArn = serviceRoleArn; }
|
||||
|
||||
public List<Map<String, String>> getEc2TagFilters() { return ec2TagFilters; }
|
||||
public void setEc2TagFilters(List<Map<String, String>> ec2TagFilters) { this.ec2TagFilters = ec2TagFilters; }
|
||||
|
||||
public List<Map<String, String>> getOnPremisesInstanceTagFilters() { return onPremisesInstanceTagFilters; }
|
||||
public void setOnPremisesInstanceTagFilters(List<Map<String, String>> onPremisesInstanceTagFilters) { this.onPremisesInstanceTagFilters = onPremisesInstanceTagFilters; }
|
||||
|
||||
public List<Map<String, Object>> getAutoScalingGroups() { return autoScalingGroups; }
|
||||
public void setAutoScalingGroups(List<Map<String, Object>> autoScalingGroups) { this.autoScalingGroups = autoScalingGroups; }
|
||||
|
||||
public Map<String, Object> getDeploymentStyle() { return deploymentStyle; }
|
||||
public void setDeploymentStyle(Map<String, Object> deploymentStyle) { this.deploymentStyle = deploymentStyle; }
|
||||
|
||||
public Map<String, Object> getBlueGreenDeploymentConfiguration() { return blueGreenDeploymentConfiguration; }
|
||||
public void setBlueGreenDeploymentConfiguration(Map<String, Object> blueGreenDeploymentConfiguration) { this.blueGreenDeploymentConfiguration = blueGreenDeploymentConfiguration; }
|
||||
|
||||
public Map<String, Object> getLoadBalancerInfo() { return loadBalancerInfo; }
|
||||
public void setLoadBalancerInfo(Map<String, Object> loadBalancerInfo) { this.loadBalancerInfo = loadBalancerInfo; }
|
||||
|
||||
public Map<String, Object> getEc2TagSet() { return ec2TagSet; }
|
||||
public void setEc2TagSet(Map<String, Object> ec2TagSet) { this.ec2TagSet = ec2TagSet; }
|
||||
|
||||
public Map<String, Object> getOnPremisesTagSet() { return onPremisesTagSet; }
|
||||
public void setOnPremisesTagSet(Map<String, Object> onPremisesTagSet) { this.onPremisesTagSet = onPremisesTagSet; }
|
||||
|
||||
public Map<String, Object> getAlarmConfiguration() { return alarmConfiguration; }
|
||||
public void setAlarmConfiguration(Map<String, Object> alarmConfiguration) { this.alarmConfiguration = alarmConfiguration; }
|
||||
|
||||
public Map<String, Object> getAutoRollbackConfiguration() { return autoRollbackConfiguration; }
|
||||
public void setAutoRollbackConfiguration(Map<String, Object> autoRollbackConfiguration) { this.autoRollbackConfiguration = autoRollbackConfiguration; }
|
||||
|
||||
public List<Map<String, Object>> getTriggerConfigurations() { return triggerConfigurations; }
|
||||
public void setTriggerConfigurations(List<Map<String, Object>> triggerConfigurations) { this.triggerConfigurations = triggerConfigurations; }
|
||||
|
||||
public List<Map<String, Object>> getEcsServices() { return ecsServices; }
|
||||
public void setEcsServices(List<Map<String, Object>> ecsServices) { this.ecsServices = ecsServices; }
|
||||
|
||||
public String getComputePlatform() { return computePlatform; }
|
||||
public void setComputePlatform(String computePlatform) { this.computePlatform = computePlatform; }
|
||||
|
||||
public String getOutdatedInstancesStrategy() { return outdatedInstancesStrategy; }
|
||||
public void setOutdatedInstancesStrategy(String outdatedInstancesStrategy) { this.outdatedInstancesStrategy = outdatedInstancesStrategy; }
|
||||
|
||||
public Boolean getTerminationHookEnabled() { return terminationHookEnabled; }
|
||||
public void setTerminationHookEnabled(Boolean terminationHookEnabled) { this.terminationHookEnabled = terminationHookEnabled; }
|
||||
}
|
||||
Reference in new issue
Block a user