mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(cloudformation): map FIFO and redrive attributes for AWS::SQS::Queue (#1939)
* test(cloudformation): reproduce dropped DeduplicationScope and FifoThroughputLimit in SqsCfnProvisioner * test(cloudformation): reproduce dropped RedrivePolicy in SqsCfnProvisioner * fix(cloudformation): pass DeduplicationScope and FifoThroughputLimit to CreateQueue * fix(cloudformation): serialize RedrivePolicy with resolved DLQ ARN for CreateQueue * test(cloudformation): cover FifoQueue mapping for queues without an explicit QueueName * fix(cloudformation): map FifoQueue and suffix generated FIFO queue names with .fifo * test(cloudformation): verify CFN FIFO queue attributes end-to-end via CreateStack * refactor(cloudformation): resolve FifoQueue once in SqsCfnProvisioner * fix(cloudformation): unwrap already-serialized RedrivePolicy strings RedrivePolicy in a template is usually a JSON object, but CDK commonly emits it as an already-serialized JSON string via Fn::Join. resolveNode collapses that to a TextNode, and calling toString() on it re-encodes (quotes/escapes) the string a second time, so SqsService.createQueue receives an unparseable value and the redrive silently doesn't work. Reported on #1939. * test(cloudformation): add regression test for string-form RedrivePolicy Reproduces the double-encoding bug reported on #1939: when RedrivePolicy is supplied as an already-serialized JSON string (CDK's common Fn::Join form), resolveNode collapses it to a TextNode and TextNode#toString() re-quotes/escapes it, so SqsService receives an unparseable value. * chore: retrigger CI (transient base-image layer pull failure) --------- Co-authored-by: Priamo Germosen <6233424+pgermosen@users.noreply.github.com>
This commit is contained in:
1 parent
0971cf6f64
commit
58112b1f3b
3 files changed
+243
-1
No files matched your search
+27
-1
@@ -50,18 +50,44 @@ public class SqsCfnProvisioner implements CfnResourceProvisioner {
|
||||
}
|
||||
|
||||
private void provisionQueue(StackResource r, JsonNode props, ProvisionContext ctx) {
|
||||
String fifoFlag = props != null && props.has("FifoQueue")
|
||||
? ctx.engine().resolve(props.get("FifoQueue"))
|
||||
: null;
|
||||
boolean fifo = "true".equalsIgnoreCase(fifoFlag);
|
||||
String queueName = ctx.resolveOptional(props, "QueueName");
|
||||
if (queueName == null || queueName.isBlank()) {
|
||||
queueName = ctx.generatePhysicalName(r.getLogicalId(), 80, false);
|
||||
// Like real CloudFormation, generated names of FIFO queues must end in .fifo
|
||||
// (SqsService rejects FifoQueue=true otherwise). Keep within the 80-char limit.
|
||||
queueName = fifo
|
||||
? ctx.generatePhysicalName(r.getLogicalId(), 75, false) + ".fifo"
|
||||
: ctx.generatePhysicalName(r.getLogicalId(), 80, false);
|
||||
}
|
||||
Map<String, String> attrs = new HashMap<>();
|
||||
if (props != null) {
|
||||
if (fifoFlag != null) {
|
||||
attrs.put("FifoQueue", fifoFlag);
|
||||
}
|
||||
if (props.has("VisibilityTimeout")) {
|
||||
attrs.put("VisibilityTimeout", ctx.engine().resolve(props.get("VisibilityTimeout")));
|
||||
}
|
||||
if (props.has("ContentBasedDeduplication")) {
|
||||
attrs.put("ContentBasedDeduplication", ctx.engine().resolve(props.get("ContentBasedDeduplication")));
|
||||
}
|
||||
if (props.has("DeduplicationScope")) {
|
||||
attrs.put("DeduplicationScope", ctx.engine().resolve(props.get("DeduplicationScope")));
|
||||
}
|
||||
if (props.has("FifoThroughputLimit")) {
|
||||
attrs.put("FifoThroughputLimit", ctx.engine().resolve(props.get("FifoThroughputLimit")));
|
||||
}
|
||||
if (props.has("RedrivePolicy") && !props.path("RedrivePolicy").isNull()) {
|
||||
// Usually a JSON object in the template (deadLetterTargetArn is an Fn::GetAtt);
|
||||
// resolveNode resolves intrinsics in place and SqsService expects the JSON string.
|
||||
// CDK commonly emits RedrivePolicy as an already-serialized string via Fn::Join,
|
||||
// which resolveNode collapses to a TextNode — unwrap it instead of calling
|
||||
// toString(), which would JSON-re-encode (quote/escape) the string a second time.
|
||||
JsonNode redrivePolicy = ctx.engine().resolveNode(props.path("RedrivePolicy"));
|
||||
attrs.put("RedrivePolicy", redrivePolicy.isTextual() ? redrivePolicy.asText() : redrivePolicy.toString());
|
||||
}
|
||||
}
|
||||
Queue queue = sqsService.createQueue(queueName, attrs, ctx.region());
|
||||
// QueueArn is computed on demand in SqsService#getQueueAttributes and is not stored on the
|
||||
|
||||
Reference in new issue
Block a user