mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudformation): apply SES string schema constraints (#8879)
The CloudFormation property types generator now keeps minLength, maxLength and pattern on every string the published schemas constrain, and HandlerReader checks them for AWS::SES::ConfigurationSetEventDestination with CloudFormation's wording: "expected minLength: 36, actual: 0", "expected maxLength: 1024, actual: 1100" and "failed validation constraint for keyword [pattern]". A blank required string counts as missing only where the schema sets no constraint. Follow-up to #8733.
This commit is contained in:
1 parent
c0325c5488
commit
8619ad65cc
6 files changed
+349
-62
No files matched your search
@@ -23,9 +23,14 @@ public record RequestShapeModel(Map<String, String> operations, Map<String, Shap
|
||||
|
||||
/**
|
||||
* One shape: its type, the shape of each structure member and the members it requires, or the
|
||||
* list element or map value shape.
|
||||
* list element or map value shape, and any string constraints the vendor retains.
|
||||
*/
|
||||
public record Shape(String type, Map<String, String> members, String element, List<String> required) {
|
||||
public record Shape(String type, Map<String, String> members, String element, List<String> required,
|
||||
Integer minLength, Integer maxLength, String pattern) {
|
||||
|
||||
public Shape(String type, Map<String, String> members, String element, List<String> required) {
|
||||
this(type, members, element, required, null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
/** The vendored resource {@code name}; {@code description} names it in a failure. */
|
||||
@@ -45,7 +50,10 @@ public record RequestShapeModel(Map<String, String> operations, Map<String, Shap
|
||||
List<String> required = new ArrayList<>();
|
||||
node.path("required").forEach(name -> required.add(name.asText()));
|
||||
shapes.put(entry.getKey(), new Shape(node.path("type").asText(), Collections.unmodifiableMap(members),
|
||||
element, List.copyOf(required)));
|
||||
element, List.copyOf(required),
|
||||
node.hasNonNull("minLength") ? node.get("minLength").asInt() : null,
|
||||
node.hasNonNull("maxLength") ? node.get("maxLength").asInt() : null,
|
||||
node.hasNonNull("pattern") ? node.get("pattern").asText() : null));
|
||||
}
|
||||
return new RequestShapeModel(Map.copyOf(operations), Map.copyOf(shapes));
|
||||
}
|
||||
|
||||
+33
-6
@@ -161,6 +161,9 @@ final class CfnPropertyTypes {
|
||||
|
||||
abstract JsonNode readBoolean(String path, String property, JsonNode value);
|
||||
|
||||
void checkString(String path, Shape shape, String value) {
|
||||
}
|
||||
|
||||
/** Checks the members {@code shape} requires of the object {@code value} at {@code path}; none by default. */
|
||||
void checkRequired(String path, JsonNode value, Shape shape) {
|
||||
}
|
||||
@@ -191,7 +194,7 @@ final class CfnPropertyTypes {
|
||||
case "structure" -> readObject(path, property, value, shape);
|
||||
case "map" -> readMap(path, property, value, shape.element());
|
||||
case "list" -> readList(path, property, value, shape.element());
|
||||
case "string" -> readString(path, property, value);
|
||||
case "string" -> readString(path, property, value, shape);
|
||||
case "integer" -> readInteger(path, property, value);
|
||||
case "boolean" -> readBoolean(path, property, value);
|
||||
default -> value == raw ? engine.resolveNode(raw) : value;
|
||||
@@ -283,12 +286,14 @@ final class CfnPropertyTypes {
|
||||
return out;
|
||||
}
|
||||
|
||||
private JsonNode readString(String path, String property, JsonNode value) {
|
||||
private JsonNode readString(String path, String property, JsonNode value, Shape shape) {
|
||||
if (value.isContainerNode()) {
|
||||
mismatch(path, property, "String", containerName(value));
|
||||
return null;
|
||||
}
|
||||
return value.isTextual() ? value : TextNode.valueOf(value.asText());
|
||||
JsonNode text = value.isTextual() ? value : TextNode.valueOf(value.asText());
|
||||
checkString(path, shape, text.textValue());
|
||||
return text;
|
||||
}
|
||||
|
||||
static String child(String path, String name) {
|
||||
@@ -471,6 +476,24 @@ final class CfnPropertyTypes {
|
||||
return flag == null ? value : BooleanNode.valueOf(flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
void checkString(String path, Shape shape, String value) {
|
||||
if (shape.minLength() == null && shape.maxLength() == null && shape.pattern() == null) {
|
||||
return;
|
||||
}
|
||||
int length = value.codePointCount(0, value.length());
|
||||
if (shape.minLength() != null && length < shape.minLength()) {
|
||||
record(new Violation(path, "expected minLength: " + shape.minLength() + ", actual: " + length,
|
||||
false), false);
|
||||
} else if (shape.maxLength() != null && length > shape.maxLength()) {
|
||||
record(new Violation(path, "expected maxLength: " + shape.maxLength() + ", actual: " + length,
|
||||
false), false);
|
||||
} else if (shape.pattern() != null && !Pattern.compile(shape.pattern()).matcher(value).matches()) {
|
||||
record(new Violation(path, "failed validation constraint for keyword [pattern]", false),
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void checkRequired(String path, JsonNode value, Shape shape) {
|
||||
for (String member : shape.required()) {
|
||||
@@ -478,10 +501,14 @@ final class CfnPropertyTypes {
|
||||
boolean absent = raw == null;
|
||||
if (!absent && !preserveEcsHandlerSemantics) {
|
||||
absent = raw.isNull() || raw.isMissingNode();
|
||||
if (!absent && "string".equals(model.shapes().get(shape.members().get(member)).type())) {
|
||||
Shape memberShape = model.shapes().get(shape.members().get(member));
|
||||
if (!absent && "string".equals(memberShape.type())) {
|
||||
JsonNode resolved = engine.resolveNode(raw);
|
||||
absent = resolved == null || resolved.isNull() || resolved.isMissingNode()
|
||||
|| resolved.isTextual() && resolved.textValue().isBlank();
|
||||
absent = resolved == null || resolved.isNull() || resolved.isMissingNode();
|
||||
if (!absent && memberShape.minLength() == null && memberShape.maxLength() == null
|
||||
&& memberShape.pattern() == null) {
|
||||
absent = resolved.isTextual() && resolved.textValue().isBlank();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (absent) {
|
||||
|
||||
Reference in new issue
Block a user