mirror of
https://github.com/floci-io/floci.git
synced 2026-11-30 00:45:17 -05:00
fix(scheduler): forward MessageAttributes in universal sns:publish target (#1706)
* fix(events): SNS universal target message attributes * fix(scheduler): handle Binary MessageAttributes in universal sns:publish target
This commit is contained in:
1 parent
05302bc63b
commit
e49bc432bd
4 files changed
+116
-30
No files matched your search
@@ -12,8 +12,10 @@ 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.SnsMessageAttributes;
|
||||
import io.github.hectorvent.floci.services.sns.SnsService;
|
||||
import io.github.hectorvent.floci.services.sqs.SqsService;
|
||||
import io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
@@ -168,8 +170,9 @@ public class ScheduleInvoker {
|
||||
String subject = text(params, "Subject");
|
||||
String messageGroupId = text(params, "MessageGroupId");
|
||||
String messageDeduplicationId = text(params, "MessageDeduplicationId");
|
||||
Map<String, MessageAttributeValue> messageAttributes = SnsMessageAttributes.parse(params.path("MessageAttributes"));
|
||||
String snsRegion = extractRegion(topicArn != null ? topicArn : targetArn, region);
|
||||
snsService.publish(topicArn, targetArn, null, message, subject, null,
|
||||
snsService.publish(topicArn, targetArn, null, message, subject, messageAttributes,
|
||||
messageGroupId, messageDeduplicationId, snsRegion);
|
||||
LOG.debugv("Scheduler delivered to SNS (universal target): {0}", topicArn);
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ public class SnsJsonHandler {
|
||||
String subject = request.path("Subject").asText(null);
|
||||
String messageStructure = request.path("MessageStructure").asText(null);
|
||||
|
||||
Map<String, MessageAttributeValue> attributes = parseMessageAttributes(request.path("MessageAttributes"));
|
||||
Map<String, MessageAttributeValue> attributes = SnsMessageAttributes.parse(request.path("MessageAttributes"));
|
||||
|
||||
String messageId = snsService.publish(topicArn, targetArn, phoneNumber, message, subject,
|
||||
messageStructure, attributes, null, null, region);
|
||||
@@ -239,7 +239,7 @@ public class SnsJsonHandler {
|
||||
JsonNode attrsNode = entryNode.path("MessageAttributes");
|
||||
if (attrsNode.isObject()) {
|
||||
try {
|
||||
entry.put("MessageAttributes", parseMessageAttributes(attrsNode));
|
||||
entry.put("MessageAttributes", SnsMessageAttributes.parse(attrsNode));
|
||||
} catch (AwsException e) {
|
||||
// Real AWS SNS surfaces per-entry attribute errors as Failed entries
|
||||
// and keeps processing the rest of the batch, instead of aborting.
|
||||
@@ -315,32 +315,6 @@ public class SnsJsonHandler {
|
||||
return node;
|
||||
}
|
||||
|
||||
private Map<String, MessageAttributeValue> parseMessageAttributes(JsonNode attrsNode) {
|
||||
Map<String, MessageAttributeValue> attributes = new HashMap<>();
|
||||
if (!attrsNode.isObject()) {
|
||||
return attributes;
|
||||
}
|
||||
attrsNode.fields().forEachRemaining(entry -> {
|
||||
JsonNode valueNode = entry.getValue();
|
||||
String binaryValueBase64 = valueNode.path("BinaryValue").asText(null);
|
||||
String defaultDataType = binaryValueBase64 != null ? "Binary" : "String";
|
||||
String dataType = valueNode.path("DataType").asText(defaultDataType);
|
||||
if (binaryValueBase64 != null) {
|
||||
byte[] binaryValue;
|
||||
try {
|
||||
binaryValue = Base64.getDecoder().decode(binaryValueBase64);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Invalid binary value for message attribute '" + entry.getKey() + "': not valid base64.", 400);
|
||||
}
|
||||
attributes.put(entry.getKey(), new MessageAttributeValue(binaryValue, dataType));
|
||||
} else {
|
||||
String stringValue = valueNode.path("StringValue").asText();
|
||||
attributes.put(entry.getKey(), new MessageAttributeValue(stringValue, dataType));
|
||||
}
|
||||
});
|
||||
return attributes;
|
||||
}
|
||||
|
||||
private Response handleCreatePlatformApplication(JsonNode request, String region) {
|
||||
String name = request.path("Name").asText(null);
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package io.github.hectorvent.floci.services.sns;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.sqs.model.MessageAttributeValue;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class SnsMessageAttributes {
|
||||
|
||||
private SnsMessageAttributes() {}
|
||||
|
||||
public static Map<String, MessageAttributeValue> parse(JsonNode attrsNode) {
|
||||
Map<String, MessageAttributeValue> attributes = new HashMap<>();
|
||||
if (!attrsNode.isObject()) {
|
||||
return attributes;
|
||||
}
|
||||
attrsNode.fields().forEachRemaining(entry -> {
|
||||
JsonNode valueNode = entry.getValue();
|
||||
String binaryValueBase64 = valueNode.path("BinaryValue").asText(null);
|
||||
String defaultDataType = binaryValueBase64 != null ? "Binary" : "String";
|
||||
String dataType = valueNode.path("DataType").asText(defaultDataType);
|
||||
if (binaryValueBase64 != null) {
|
||||
byte[] binaryValue;
|
||||
try {
|
||||
binaryValue = Base64.getDecoder().decode(binaryValueBase64);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Invalid binary value for message attribute '" + entry.getKey() + "': not valid base64.", 400);
|
||||
}
|
||||
attributes.put(entry.getKey(), new MessageAttributeValue(binaryValue, dataType));
|
||||
} else {
|
||||
String stringValue = valueNode.path("StringValue").asText();
|
||||
attributes.put(entry.getKey(), new MessageAttributeValue(stringValue, dataType));
|
||||
}
|
||||
});
|
||||
return attributes;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user