feat(scheduler): support TagResource, UntagResource, ListTagsForResource (#700)

* feat(scheduler): support TagResource, UntagResource, ListTagsForResource

Implements the three remaining EventBridge Scheduler tag APIs by
extending the shared /tags/{arn} dispatcher. Tags apply to schedule
groups only, matching AWS behavior; ARNs pointing at individual
schedules return ValidationException.

A survey of all ~75 AWS services that share the /tags/{arn} path
shows three independent shape axes — body key (`tags` lower vs
`Tags` capital), body structure (map vs list of {Key, Value}), and
untag query parameter name (`tagKeys` vs `TagKeys`) — and most
"capital Tags" services still use lowercase tagKeys query, so these
axes vary independently. TagHandler exposes them as five orthogonal
default methods rather than a coarse-grained enum:

- tagsBodyKey()           defaults to "tags"
- tagsBodyIsList()        defaults to false (map)
- tagKeysQueryName()      defaults to "tagKeys"
- tagResourceUsesPut()    defaults to false (POST)
- strictTagValidation()   defaults to false (lenient parsing)

The defaults match the most common AWS shape (~73 services use
lowercase tags map + POST + lowercase tagKeys) so handlers like
EKS, Pipes, and AppConfig need no overrides. The dispatcher
returns 405 MethodNotAllowedException for the unused HTTP method
per handler. Strict input validation (missing Tags, wrong-shaped
Tags, missing TagKeys, entries missing Key or Value) is enforced
when strictTagValidation() is true, mirroring the AWS Scheduler
error shape; lenient handlers retain the looser parsing they had
before.

SchedulerTagHandler overrides tagsBodyKey, tagsBodyIsList,
tagKeysQueryName, and strictTagValidation. ApiGatewayTagHandler
overrides tagResourceUsesPut to true. AppConfigIntegrationTest
switches its tagApplication call from PUT to POST to match the
AWS spec for AppConfig (was relying on the dispatcher's prior
leniency on HTTP method).

* fix(tags): normalize empty body and reject non-object payloads

Address Copilot review on floci-io/floci#700.

- doTagResource normalizes null/blank request bodies to "{}" before
  passing to ObjectMapper.readTree, mirroring SchedulerController's
  parseTags. Previously an empty body raised a Jackson parse error
  that strict handlers surfaced as a ValidationException with a raw
  Java/Jackson message instead of the structured AWS error shape.
- parseTags adds a strict-only check that the JSON root is an
  object. A request body like a JSON array or string used to fall
  through to "Value null at 'Tags' ..." which misleads about the
  actual problem; it now reports that the payload itself must be a
  JSON object.

SchedulerIntegrationTest covers both paths with a 400 assertion.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-05-04 17:22:12 -05:00
1 parent 99204e2caf
commit 8e30c09d0a
11 files changed
+615 -23

No files matched your search

@@ -3,6 +3,7 @@ package com.floci.test;
import org.junit.jupiter.api.*;
import software.amazon.awssdk.services.scheduler.SchedulerClient;
import software.amazon.awssdk.services.scheduler.model.*;
import software.amazon.awssdk.services.scheduler.model.Tag;
import java.time.Instant;
@@ -454,4 +455,56 @@ class SchedulerTest {
.build()))
.isInstanceOf(ResourceNotFoundException.class);
}
// ──────────────────────────── Tagging ────────────────────────────
@Test
@Order(30)
@DisplayName("TagResource / ListTagsForResource / UntagResource - schedule group")
void tagAndUntagScheduleGroup() {
String tagGroup = "tag-test-group";
try {
scheduler.createScheduleGroup(CreateScheduleGroupRequest.builder()
.name(tagGroup)
.tags(Tag.builder().key("env").value("dev").build())
.build());
String arn = scheduler.getScheduleGroup(GetScheduleGroupRequest.builder()
.name(tagGroup).build()).arn();
ListTagsForResourceResponse listed = scheduler.listTagsForResource(
ListTagsForResourceRequest.builder().resourceArn(arn).build());
assertThat(listed.tags())
.extracting(Tag::key, Tag::value)
.containsExactlyInAnyOrder(tuple("env", "dev"));
scheduler.tagResource(TagResourceRequest.builder()
.resourceArn(arn)
.tags(
Tag.builder().key("owner").value("Alice").build(),
Tag.builder().key("env").value("staging").build())
.build());
assertThat(scheduler.listTagsForResource(
ListTagsForResourceRequest.builder().resourceArn(arn).build()).tags())
.extracting(Tag::key, Tag::value)
.containsExactlyInAnyOrder(
tuple("env", "staging"),
tuple("owner", "Alice"));
scheduler.untagResource(UntagResourceRequest.builder()
.resourceArn(arn)
.tagKeys("owner", "env")
.build());
assertThat(scheduler.listTagsForResource(
ListTagsForResourceRequest.builder().resourceArn(arn).build()).tags())
.isEmpty();
} finally {
try {
scheduler.deleteScheduleGroup(DeleteScheduleGroupRequest.builder()
.name(tagGroup).build());
} catch (Exception ignored) {}
}
}
}