mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
feat: add ListTagsForResource, TagResource, UntagResource for Step Functions (#767)
* feat: add ListTagsForResource, TagResource, UntagResource for Step Functions Implements the SharedTagsController TagHandler pattern for SFN state machines and activities. Adds tags field to StateMachine and Activity models, tag CRUD methods to StepFunctionsService, and a new StepFunctionsTagHandler that registers the 'states' service key. Closes #766 * feat: cover JSON 1.0 SDK wire path for SFN tag operations Add ListTagsForResource, TagResource, UntagResource cases to StepFunctionsJsonHandler for AWS SDK (awsJson1.0) compatibility. The REST /tags/{arn} path (SharedTagsController) already covers Terraform; this commit covers the SDK path. Expand integration test to verify both wire paths. Add SDK-based compatibility test using SfnClient. * chore: remove invented inline comment from tags integration test * refactor: remove dead REST TagHandler and clean up integration tests StepFunctionsTagHandler registered the 'states' service key with SharedTagsController (REST /tags/{arn}), but SFN uses JSON 1.0 exclusively. No real client calls GET/POST/DELETE /tags/arn:aws:states:... — the handler was unreachable dead code. Remove StepFunctionsTagHandler and strip the eight REST-path tests from StepFunctionsTagsIntegrationTest. The remaining JSON 1.0 tests are now self-contained (no longer depend on state set by the deleted REST tests). * fix: correct SDK API usage in tag tests and persist creation-time tags - Fix StepFunctionsTagsTest: tags() takes Tag... not Map, use tagsAsMap() helper to convert List<Tag> before asserting with MapAssert methods - Fix StepFunctionsService: pass tags through createStateMachine/createActivity so tags set at creation time are persisted immediately - Fix StepFunctionsJsonHandler: extract parseTagsArray() helper, add 400 validation when tags/tagKeys are not arrays, wire tags into create calls - Expand StepFunctionsTagsIntegrationTest: cover creation-time tag persistence for state machines and activities, and 400 on malformed tag input
This commit is contained in:
1 parent
39ef0694a4
commit
4d2a99506a
6 files changed
+614
-4
No files matched your search
+58
-2
@@ -14,7 +14,9 @@ import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ApplicationScoped
|
||||
public class StepFunctionsJsonHandler {
|
||||
@@ -48,6 +50,9 @@ public class StepFunctionsJsonHandler {
|
||||
case "DescribeActivity" -> handleDescribeActivity(request);
|
||||
case "ListActivities" -> handleListActivities(request, region);
|
||||
case "GetActivityTask" -> handleGetActivityTask(request);
|
||||
case "ListTagsForResource" -> handleListTagsForResource(request);
|
||||
case "TagResource" -> handleTagResource(request);
|
||||
case "UntagResource" -> handleUntagResource(request);
|
||||
default -> Response.status(400)
|
||||
.entity(new AwsErrorResponse("UnsupportedOperation", "Operation " + action + " is not supported."))
|
||||
.build();
|
||||
@@ -60,7 +65,8 @@ public class StepFunctionsJsonHandler {
|
||||
request.path("definition").asText(),
|
||||
request.path("roleArn").asText(),
|
||||
request.path("type").asText(null),
|
||||
region
|
||||
region,
|
||||
parseTagsArray(request.path("tags"))
|
||||
);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("stateMachineArn", sm.getStateMachineArn());
|
||||
@@ -214,7 +220,7 @@ public class StepFunctionsJsonHandler {
|
||||
}
|
||||
|
||||
private Response handleCreateActivity(JsonNode request, String region) {
|
||||
Activity activity = service.createActivity(request.path("name").asText(), region);
|
||||
Activity activity = service.createActivity(request.path("name").asText(), region, parseTagsArray(request.path("tags")));
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("activityArn", activity.getActivityArn());
|
||||
response.put("creationDate", activity.getCreationDate());
|
||||
@@ -260,4 +266,54 @@ public class StepFunctionsJsonHandler {
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleListTagsForResource(JsonNode request) {
|
||||
java.util.Map<String, String> tags = service.listTags(request.path("resourceArn").asText());
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode array = response.putArray("tags");
|
||||
tags.forEach((k, v) -> {
|
||||
ObjectNode entry = array.addObject();
|
||||
entry.put("key", k);
|
||||
entry.put("value", v);
|
||||
});
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleTagResource(JsonNode request) {
|
||||
String arn = request.path("resourceArn").asText();
|
||||
JsonNode tagsNode = request.path("tags");
|
||||
if (!tagsNode.isArray()) {
|
||||
return Response.status(400)
|
||||
.entity(new AwsErrorResponse("ValidationException", "Parameter 'tags' must be a list"))
|
||||
.build();
|
||||
}
|
||||
service.tagResource(arn, parseTagsArray(tagsNode));
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
private Response handleUntagResource(JsonNode request) {
|
||||
String arn = request.path("resourceArn").asText();
|
||||
JsonNode keysNode = request.path("tagKeys");
|
||||
if (!keysNode.isArray()) {
|
||||
return Response.status(400)
|
||||
.entity(new AwsErrorResponse("ValidationException", "Parameter 'tagKeys' must be a list"))
|
||||
.build();
|
||||
}
|
||||
java.util.List<String> tagKeys = new java.util.ArrayList<>();
|
||||
for (JsonNode key : keysNode) {
|
||||
tagKeys.add(key.asText());
|
||||
}
|
||||
service.untagResource(arn, tagKeys);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
private Map<String, String> parseTagsArray(JsonNode tagsNode) {
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
if (tagsNode != null && tagsNode.isArray()) {
|
||||
for (JsonNode entry : tagsNode) {
|
||||
tags.put(entry.path("key").asText(), entry.path("value").asText());
|
||||
}
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
}
|
||||
+58
-2
@@ -62,7 +62,7 @@ public class StepFunctionsService {
|
||||
|
||||
// ──────────────────────────── State Machines ────────────────────────────
|
||||
|
||||
public StateMachine createStateMachine(String name, String definition, String roleArn, String type, String region) {
|
||||
public StateMachine createStateMachine(String name, String definition, String roleArn, String type, String region, Map<String, String> tags) {
|
||||
String arn = regionResolver.buildArn("states", region, "stateMachine:" + name);
|
||||
if (stateMachineStore.get(arn).isPresent()) {
|
||||
throw new AwsException("StateMachineAlreadyExists", "State machine already exists: " + arn, 400);
|
||||
@@ -78,6 +78,9 @@ public class StepFunctionsService {
|
||||
if (type != null && !type.isEmpty()) {
|
||||
sm.setType(type);
|
||||
}
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
sm.getTags().putAll(tags);
|
||||
}
|
||||
|
||||
stateMachineStore.put(arn, sm);
|
||||
LOG.infov("Created State Machine: {0}", arn);
|
||||
@@ -213,7 +216,7 @@ public class StepFunctionsService {
|
||||
|
||||
// ──────────────────────────── Activities ────────────────────────────
|
||||
|
||||
public Activity createActivity(String name, String region) {
|
||||
public Activity createActivity(String name, String region, Map<String, String> tags) {
|
||||
String arn = regionResolver.buildArn("states", region, "activity:" + name);
|
||||
if (activityStore.get(arn).isPresent()) {
|
||||
throw new AwsException("ActivityAlreadyExists", "Activity already exists: " + arn, 400);
|
||||
@@ -221,6 +224,9 @@ public class StepFunctionsService {
|
||||
Activity activity = new Activity();
|
||||
activity.setActivityArn(arn);
|
||||
activity.setName(name);
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
activity.getTags().putAll(tags);
|
||||
}
|
||||
activityStore.put(arn, activity);
|
||||
LOG.infov("Created activity: {0}", arn);
|
||||
return activity;
|
||||
@@ -297,6 +303,56 @@ public class StepFunctionsService {
|
||||
LOG.debugv("Task heartbeat for token {0}", taskToken);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Tags ────────────────────────────
|
||||
|
||||
public Map<String, String> listTags(String arn) {
|
||||
Optional<StateMachine> sm = stateMachineStore.get(arn);
|
||||
if (sm.isPresent()) {
|
||||
return sm.get().getTags();
|
||||
}
|
||||
Optional<Activity> activity = activityStore.get(arn);
|
||||
if (activity.isPresent()) {
|
||||
return activity.get().getTags();
|
||||
}
|
||||
throw new AwsException("ResourceNotFound", "Resource not found: " + arn, 400);
|
||||
}
|
||||
|
||||
public void tagResource(String arn, Map<String, String> tags) {
|
||||
Optional<StateMachine> smOpt = stateMachineStore.get(arn);
|
||||
if (smOpt.isPresent()) {
|
||||
StateMachine sm = smOpt.get();
|
||||
sm.getTags().putAll(tags);
|
||||
stateMachineStore.put(arn, sm);
|
||||
return;
|
||||
}
|
||||
Optional<Activity> actOpt = activityStore.get(arn);
|
||||
if (actOpt.isPresent()) {
|
||||
Activity activity = actOpt.get();
|
||||
activity.getTags().putAll(tags);
|
||||
activityStore.put(arn, activity);
|
||||
return;
|
||||
}
|
||||
throw new AwsException("ResourceNotFound", "Resource not found: " + arn, 400);
|
||||
}
|
||||
|
||||
public void untagResource(String arn, List<String> tagKeys) {
|
||||
Optional<StateMachine> smOpt = stateMachineStore.get(arn);
|
||||
if (smOpt.isPresent()) {
|
||||
StateMachine sm = smOpt.get();
|
||||
tagKeys.forEach(sm.getTags()::remove);
|
||||
stateMachineStore.put(arn, sm);
|
||||
return;
|
||||
}
|
||||
Optional<Activity> actOpt = activityStore.get(arn);
|
||||
if (actOpt.isPresent()) {
|
||||
Activity activity = actOpt.get();
|
||||
tagKeys.forEach(activity.getTags()::remove);
|
||||
activityStore.put(arn, activity);
|
||||
return;
|
||||
}
|
||||
throw new AwsException("ResourceNotFound", "Resource not found: " + arn, 400);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Validation ────────────────────────────
|
||||
|
||||
private void validateDefinition(String definition) {
|
||||
|
||||
@@ -3,12 +3,16 @@ package io.github.hectorvent.floci.services.stepfunctions.model;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Activity {
|
||||
private String activityArn;
|
||||
private String name;
|
||||
private double creationDate;
|
||||
private Map<String, String> tags = new HashMap<>();
|
||||
|
||||
public Activity() {
|
||||
this.creationDate = System.currentTimeMillis() / 1000.0;
|
||||
@@ -22,4 +26,7 @@ public class Activity {
|
||||
|
||||
public double getCreationDate() { return creationDate; }
|
||||
public void setCreationDate(double creationDate) { this.creationDate = creationDate; }
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags; }
|
||||
}
|
||||
+7
@@ -3,6 +3,9 @@ package io.github.hectorvent.floci.services.stepfunctions.model;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class StateMachine {
|
||||
@@ -13,6 +16,7 @@ public class StateMachine {
|
||||
private String type = "STANDARD";
|
||||
private String status = "ACTIVE";
|
||||
private double creationDate;
|
||||
private Map<String, String> tags = new HashMap<>();
|
||||
|
||||
public StateMachine() {
|
||||
this.creationDate = System.currentTimeMillis() / 1000.0;
|
||||
@@ -38,4 +42,7 @@ public class StateMachine {
|
||||
|
||||
public double getCreationDate() { return creationDate; }
|
||||
public void setCreationDate(double creationDate) { this.creationDate = creationDate; }
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags; }
|
||||
}
|
||||
Reference in new issue
Block a user