fix: support SSM PutParameter tags and ECS container healthCheck (#2567) (#3550)

* fix(ssm): support Tags and preserve tags on Overwrite in PutParameter (#2567)

* fix(ecs): round-trip containerDefinition healthCheck (#2567)

* style(ecs): replace em-dash with comma in test doc per AGENTS.md

* fix(ssm,ecs): address review feedback on description, ARN parsing and ECS healthCheck command

* test(ecs): pass HostVolumePolicy to EcsJsonHandler in healthCheck tests
This commit is contained in:
Vũ Thế Huy authored and GitHub committed 2026-09-13 21:23:52 -04:00
1 parent 19917ed9ed
commit 7d6e9588cd
10 files changed
+518 -4

No files matched your search

@@ -11,6 +11,7 @@ import io.github.hectorvent.floci.services.ecs.model.ContainerDefinition;
import io.github.hectorvent.floci.services.ecs.model.ContainerInstance;
import io.github.hectorvent.floci.services.ecs.model.Deployment;
import io.github.hectorvent.floci.services.ecs.model.Failure;
import io.github.hectorvent.floci.services.ecs.model.HealthCheck;
import io.github.hectorvent.floci.services.ecs.model.ContainerOverride;
import io.github.hectorvent.floci.services.ecs.model.EcsCluster;
import io.github.hectorvent.floci.services.ecs.model.EcsLoadBalancer;
@@ -1117,6 +1118,29 @@ public class EcsJsonHandler {
n.set("logConfiguration", logNode);
}
if (def.getHealthCheck() != null) {
HealthCheck hc = def.getHealthCheck();
ObjectNode hcNode = objectMapper.createObjectNode();
if (hc.command() != null) {
ArrayNode cmd = objectMapper.createArrayNode();
hc.command().forEach(cmd::add);
hcNode.set("command", cmd);
}
if (hc.interval() != null) {
hcNode.put("interval", hc.interval());
}
if (hc.timeout() != null) {
hcNode.put("timeout", hc.timeout());
}
if (hc.retries() != null) {
hcNode.put("retries", hc.retries());
}
if (hc.startPeriod() != null) {
hcNode.put("startPeriod", hc.startPeriod());
}
n.set("healthCheck", hcNode);
}
return n;
}
@@ -1419,6 +1443,9 @@ public class EcsJsonHandler {
}
def.setMountPoints(parseMountPoints(item.path("mountPoints")));
def.setLogConfiguration(parseLogConfiguration(item.path("logConfiguration")));
if (item.has("healthCheck")) {
def.setHealthCheck(parseHealthCheck(item.path("healthCheck")));
}
if (item.has("command") && item.path("command").isArray()) {
List<String> cmd = new ArrayList<>();
@@ -1503,6 +1530,21 @@ public class EcsJsonHandler {
return new LogConfiguration(logDriver, options, secretOptions);
}
private HealthCheck parseHealthCheck(JsonNode node) {
if (node == null || !node.isObject()) {
return null;
}
if (!node.hasNonNull("command") || !node.path("command").isArray() || node.path("command").isEmpty()) {
throw new AwsException("ClientException", "HealthCheck command is required.", 400);
}
List<String> command = jsonArrayToList(node.path("command"));
Integer interval = node.has("interval") ? node.path("interval").asInt() : null;
Integer timeout = node.has("timeout") ? node.path("timeout").asInt() : null;
Integer retries = node.has("retries") ? node.path("retries").asInt() : null;
Integer startPeriod = node.has("startPeriod") ? node.path("startPeriod").asInt() : null;
return new HealthCheck(command, interval, timeout, retries, startPeriod);
}
private List<Volume> parseVolumes(JsonNode node) {
List<Volume> result = new ArrayList<>();
if (!node.isArray()) {
@@ -20,6 +20,7 @@ public class ContainerDefinition {
private List<String> entryPoint;
private List<MountPoint> mountPoints;
private LogConfiguration logConfiguration;
private HealthCheck healthCheck;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
@@ -59,4 +60,7 @@ public class ContainerDefinition {
public LogConfiguration getLogConfiguration() { return logConfiguration; }
public void setLogConfiguration(LogConfiguration logConfiguration) { this.logConfiguration = logConfiguration; }
public HealthCheck getHealthCheck() { return healthCheck; }
public void setHealthCheck(HealthCheck healthCheck) { this.healthCheck = healthCheck; }
}
@@ -0,0 +1,21 @@
package io.github.hectorvent.floci.services.ecs.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.List;
/**
* The {@code healthCheck} of an ECS container definition:
* {@code {"command": [...], "interval": ..., "timeout": ..., "retries": ..., "startPeriod": ...}}.
*
* <p>Modelled for RegisterTaskDefinition/DescribeTaskDefinition round-trip fidelity.
*/
@RegisterForReflection
public record HealthCheck(
List<String> command,
Integer interval,
Integer timeout,
Integer retries,
Integer startPeriod
) {
}
@@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -110,7 +111,15 @@ public class SsmJsonHandler {
String description = request.has("Description") ? request.path("Description").asText() : null;
boolean overwrite = request.path("Overwrite").asBoolean(false);
long version = ssmService.putParameter(name, value, type, description, overwrite, region);
Map<String, String> tags = null;
if (request.has("Tags") && request.path("Tags").isArray()) {
tags = new LinkedHashMap<>();
for (JsonNode t : request.path("Tags")) {
tags.put(t.path("Key").asText(), t.path("Value").asText());
}
}
long version = ssmService.putParameter(name, value, type, description, overwrite, tags, region);
return Response.ok(new PutParameterResponse(version)).build();
}
@@ -155,6 +155,11 @@ public class SsmService implements ResourceProvider {
* Returns the version number.
*/
public long putParameter(String name, String value, String type, String description, boolean overwrite, String region) {
return putParameter(name, value, type, description, overwrite, null, region);
}
public long putParameter(String name, String value, String type, String description, boolean overwrite,
Map<String, String> tags, String region) {
rejectReservedName(name);
String storageKey = regionKey(region, name);
Parameter existing = parameterStore.get(storageKey).orElse(null);
@@ -165,6 +170,14 @@ public class SsmService implements ResourceProvider {
400);
}
if (overwrite && tags != null && !tags.isEmpty()) {
throw new AwsException("ValidationException",
"Invalid request: tags and overwrite can't be used together. To create a "
+ "parameter with tags, please remove overwrite flag. To update tags for an "
+ "existing parameter, please use AddTagsToResource or RemoveTagsFromResource.",
400);
}
long version = (existing != null) ? existing.getVersion() + 1 : 1;
Parameter parameter = new Parameter(name, value, type != null ? type : "String");
@@ -173,6 +186,12 @@ public class SsmService implements ResourceProvider {
parameter.setArn(regionResolver.buildArn("ssm", region, "parameter" + name));
parameter.setLastModifiedDate(Instant.now());
if (existing != null && existing.getTags() != null) {
parameter.setTags(new HashMap<>(existing.getTags()));
} else if (tags != null && !tags.isEmpty()) {
parameter.setTags(new HashMap<>(tags));
}
parameterStore.put(storageKey, parameter);
addHistory(storageKey, parameter);
@@ -356,7 +375,8 @@ public class SsmService implements ResourceProvider {
}
public void addTagsToResource(String resourceId, Map<String, String> tags, String region) {
String storageKey = regionKey(region, resourceId);
String normalizedId = normalizeResourceId(resourceId);
String storageKey = regionKey(region, normalizedId);
Parameter param = parameterStore.get(storageKey)
.orElseThrow(() -> new AwsException("InvalidResourceId",
"Resource " + resourceId + " not found.", 400));
@@ -370,7 +390,8 @@ public class SsmService implements ResourceProvider {
}
public Map<String, String> listTagsForResource(String resourceId, String region) {
String storageKey = regionKey(region, resourceId);
String normalizedId = normalizeResourceId(resourceId);
String storageKey = regionKey(region, normalizedId);
Parameter param = parameterStore.get(storageKey)
.orElseThrow(() -> new AwsException("InvalidResourceId",
"Resource " + resourceId + " not found.", 400));
@@ -378,7 +399,8 @@ public class SsmService implements ResourceProvider {
}
public void removeTagsFromResource(String resourceId, List<String> tagKeys, String region) {
String storageKey = regionKey(region, resourceId);
String normalizedId = normalizeResourceId(resourceId);
String storageKey = regionKey(region, normalizedId);
Parameter param = parameterStore.get(storageKey)
.orElseThrow(() -> new AwsException("InvalidResourceId",
"Resource " + resourceId + " not found.", 400));
@@ -392,6 +414,28 @@ public class SsmService implements ResourceProvider {
LOG.debugv("Removed tags from parameter: {0}", resourceId);
}
private static String normalizeResourceId(String resourceId) {
if (resourceId != null && resourceId.startsWith("arn:")) {
try {
AwsArnUtils.Arn arn = AwsArnUtils.parse(resourceId);
if ("ssm".equals(arn.service())) {
String resource = arn.resource();
if (resource.startsWith("parameter/")) {
return resource.substring("parameter".length());
}
if (resource.startsWith("parameter")) {
return resource.substring("parameter".length());
}
}
} catch (IllegalArgumentException e) {
// Not a valid ARN; fall through and use resourceId directly so callers
// querying parameterStore produce the standard InvalidResourceId error.
LOG.debugv("Failed to parse resourceId as ARN: {0}", resourceId);
}
}
return resourceId;
}
// ──────────────────────── Documents and Share Permissions ────────────────
// Documents live in documentStore; share state is kept alongside it in
// documentPermissionStore so callers like LZA's Custom::SSMShareDocument handler
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.ssm.model;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.quarkus.runtime.annotations.RegisterForReflection;
@@ -36,6 +37,8 @@ public class Parameter {
@JsonProperty("DataType")
private String dataType = "text";
@JsonProperty("Tags")
@JsonAlias({"tags", "Tags"})
private Map<String, String> tags = new HashMap<>();
public Parameter() {}