fix(scheduler): honor target EventBridgeParameters DetailType/Source (#1489)

* fix(scheduler): honor target EventBridgeParameters DetailType/Source

* chore: update after review

* chore: update after greptile feedbacks

* chore(scheduler): add missing validation for eventbridge target

* chore: add missing test annotation

* chore: sync docs
This commit is contained in:
Saliou Gaye authored and GitHub committed 2026-07-10 20:52:40 -05:00
1 parent f915622e36
commit 8590ffec34
6 files changed
+277 -4

No files matched your search

@@ -9,6 +9,7 @@ import io.github.hectorvent.floci.services.ecs.model.LaunchType;
import io.github.hectorvent.floci.services.eventbridge.EventBridgeService;
import io.github.hectorvent.floci.services.lambda.LambdaService;
import io.github.hectorvent.floci.services.lambda.model.InvocationType;
import io.github.hectorvent.floci.services.scheduler.model.EventBridgeParameters;
import io.github.hectorvent.floci.services.scheduler.model.EcsParameters;
import io.github.hectorvent.floci.services.scheduler.model.Target;
import io.github.hectorvent.floci.services.sns.SnsService;
@@ -94,7 +95,7 @@ public class ScheduleInvoker {
deliverToEcsRunTask(target, targetRegion);
LOG.debugv("Scheduler delivered to ECS RunTask: {0}", arn);
} else if (isEventBridgePutEventsArn(arn)) {
deliverToEventBridge(arn, payload, targetRegion);
deliverToEventBridge(target, payload, targetRegion);
LOG.debugv("Scheduler delivered to EventBridge: {0}", arn);
} else {
LOG.warnv("Scheduler: unsupported target ARN type: {0}", arn);
@@ -193,12 +194,23 @@ public class ScheduleInvoker {
return arn.contains(":events:") && arn.contains(":event-bus/");
}
private void deliverToEventBridge(String busArn, String payload, String region) {
private void deliverToEventBridge(Target target, String payload, String region) {
String busArn = target.getArn();
String busName = busArn.substring(busArn.indexOf(":event-bus/") + ":event-bus/".length());
// AWS requires DetailType and Source on the target's EventBridgeParameters for
// event-bus targets; honor them. Keep the historical defaults as a fallback for
// schedules created without those parameters.
EventBridgeParameters ebp = target.getEventBridgeParameters();
String source = ebp != null && ebp.getSource() != null && !ebp.getSource().isBlank()
? ebp.getSource() : "aws.scheduler";
String detailType = ebp != null && ebp.getDetailType() != null && !ebp.getDetailType().isBlank()
? ebp.getDetailType() : "Scheduled Event";
Map<String, Object> entry = new HashMap<>();
entry.put("EventBusName", busName);
entry.put("Source", "aws.scheduler");
entry.put("DetailType", "Scheduled Event");
entry.put("Source", source);
entry.put("DetailType", detailType);
entry.put("Detail", asDetail(payload));
eventBridgeService.putEvents(List.of(entry), region);
}
@@ -5,6 +5,7 @@ import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.services.scheduler.model.AwsVpcConfiguration;
import io.github.hectorvent.floci.services.scheduler.model.DeadLetterConfig;
import io.github.hectorvent.floci.services.scheduler.model.EcsParameters;
import io.github.hectorvent.floci.services.scheduler.model.EventBridgeParameters;
import io.github.hectorvent.floci.services.scheduler.model.FlexibleTimeWindow;
import io.github.hectorvent.floci.services.scheduler.model.NetworkConfiguration;
import io.github.hectorvent.floci.services.scheduler.model.RetryPolicy;
@@ -276,6 +277,19 @@ public class SchedulerController {
t.put("EcsParameters", ep);
}
}
if (s.getTarget().getEventBridgeParameters() != null) {
EventBridgeParameters ebp = s.getTarget().getEventBridgeParameters();
Map<String, Object> eb = new HashMap<>();
if (ebp.getDetailType() != null) {
eb.put("DetailType", ebp.getDetailType());
}
if (ebp.getSource() != null) {
eb.put("Source", ebp.getSource());
}
if (!eb.isEmpty()) {
t.put("EventBridgeParameters", eb);
}
}
r.put("Target", t);
}
if (s.getDescription() != null) {
@@ -414,6 +428,44 @@ public class SchedulerController {
if (node.has("EcsParameters") && !node.get("EcsParameters").isNull()) {
target.setEcsParameters(parseEcsParameters(node.get("EcsParameters")));
}
if (node.has("EventBridgeParameters") && !node.get("EventBridgeParameters").isNull()) {
JsonNode ebNode = node.get("EventBridgeParameters");
EventBridgeParameters ebp = new EventBridgeParameters();
if (
ebNode.has("DetailType") &&
!ebNode.get("DetailType").isNull() &&
!ebNode.get("DetailType").asText().isBlank()
) {
ebp.setDetailType(ebNode.get("DetailType").asText());
}
if (
ebNode.has("Source") &&
!ebNode.get("Source").isNull() &&
!ebNode.get("Source").asText().isBlank()
) {
ebp.setSource(ebNode.get("Source").asText());
}
if (ebp.getDetailType() == null || ebp.getSource() == null) {
throw new AwsException("ValidationException",
"EventBridgeParameters requires both DetailType and Source.", 400);
}
if(ebp.getDetailType().length() > 128) {
throw new AwsException("ValidationException",
"EventBridgeParameters DetailType must be less than or equal to 128 characters.", 400);
}
if(ebp.getSource().length() > 256) {
throw new AwsException("ValidationException",
"EventBridgeParameters Source must be less than or equal to 256 characters.", 400);
}
if(ebp.getSource().startsWith("aws.") || ebp.getSource().startsWith("aws:")) {
throw new AwsException("ValidationException",
"EventBridgeParameters Source cannot start with 'aws.' or 'aws:'.", 400);
}
target.setEventBridgeParameters(ebp);
}
return target;
}
@@ -0,0 +1,28 @@
package io.github.hectorvent.floci.services.scheduler.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
/**
* EventBridge Scheduler {@code Target.EventBridgeParameters}. Carries the
* {@code DetailType} and {@code Source} used for the PutEvents entry when the
* target is an EventBridge event bus (both required by AWS in that case).
*/
@RegisterForReflection
public class EventBridgeParameters {
private String detailType;
private String source;
public EventBridgeParameters() {}
public EventBridgeParameters(String detailType, String source) {
this.detailType = detailType;
this.source = source;
}
public String getDetailType() { return detailType; }
public void setDetailType(String detailType) { this.detailType = detailType; }
public String getSource() { return source; }
public void setSource(String source) { this.source = source; }
}
@@ -12,6 +12,7 @@ public class Target {
private DeadLetterConfig deadLetterConfig;
private SqsParameters sqsParameters;
private EcsParameters ecsParameters;
private EventBridgeParameters eventBridgeParameters;
public Target() {}
@@ -42,4 +43,7 @@ public class Target {
public EcsParameters getEcsParameters() { return ecsParameters; }
public void setEcsParameters(EcsParameters ecsParameters) { this.ecsParameters = ecsParameters; }
public EventBridgeParameters getEventBridgeParameters() { return eventBridgeParameters; }
public void setEventBridgeParameters(EventBridgeParameters eventBridgeParameters) { this.eventBridgeParameters = eventBridgeParameters; }
}