mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(eventbridge): forward resources array and support resources pattern matching (#210)
* test: add tests before changing code * feat: Forward resources array * feat: Add support for 'resources' pattern matching
This commit is contained in:
1 parent
625474b001
commit
6d49f0983f
4 files changed
+235
-2
No files matched your search
@@ -246,6 +246,9 @@ public class EventBridgeHandler {
|
||||
if (!entryNode.path("Detail").isMissingNode()) {
|
||||
entry.put("Detail", entryNode.path("Detail").asText(null));
|
||||
}
|
||||
if (!entryNode.path("Resources").isMissingNode()) {
|
||||
entry.put("Resources", entryNode.path("Resources"));
|
||||
}
|
||||
entries.add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
+14
-1
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.eventbridge;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
@@ -389,6 +390,17 @@ public class EventBridgeService {
|
||||
}
|
||||
}
|
||||
}
|
||||
JsonNode resourcesPattern = pattern.get("resources");
|
||||
if (resourcesPattern != null && resourcesPattern.isArray()) {
|
||||
var resources = ((ArrayNode) event.get("Resources")).elements();
|
||||
while (resources.hasNext()) {
|
||||
var resource = resources.next().asText(null);
|
||||
if (matchesArrayField(resourcesPattern, resource)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LOG.warnv("Failed to parse event pattern: {0}", e.getMessage());
|
||||
@@ -438,6 +450,7 @@ public class EventBridgeService {
|
||||
String source = (String) entry.getOrDefault("Source", "");
|
||||
String detailType = (String) entry.getOrDefault("DetailType", "");
|
||||
String detail = (String) entry.getOrDefault("Detail", "{}");
|
||||
ArrayNode resources = (ArrayNode) entry.getOrDefault("Resources", objectMapper.createArrayNode());
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("version", "0");
|
||||
node.put("id", eventId);
|
||||
@@ -446,7 +459,7 @@ public class EventBridgeService {
|
||||
node.put("account", regionResolver.getAccountId());
|
||||
node.put("time", Instant.now().toString());
|
||||
node.put("region", regionResolver.getDefaultRegion());
|
||||
node.putArray("resources");
|
||||
node.putArray("resources").addAll(resources);
|
||||
node.set("detail", objectMapper.readTree(detail));
|
||||
node.put("event-bus-name", busName);
|
||||
return objectMapper.writeValueAsString(node);
|
||||
|
||||
Reference in new issue
Block a user