mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(common): share remaining map key messages (#9256)
Builds the remaining hand-written map key constraint messages with Violations.mapKeys: Firehose mappings, SES v2 filters, both Lambda Web key checks, Lambda tags and IoT authorizer token signing keys. The messages are unchanged. Closes #9255
This commit is contained in:
1 parent
a4b2f01713
commit
711d9ea887
5 files changed
+17
-19
No files matched your search
@@ -228,8 +228,9 @@ public final class S3DestinationValidator {
|
||||
valueViolation |= !isMappingValueValid(mapping.getValue());
|
||||
}
|
||||
if (keyViolation) {
|
||||
violations.add(violation(shapeName, member,
|
||||
"Map keys must satisfy constraint: " + constraintSet(NO_WHITESPACE_PATTERN)));
|
||||
violations.add(SmithyValidationErrors.Violations.WITHOUT_VALUES.mapKeys(
|
||||
shapeName + "." + member, null,
|
||||
SmithyValidationErrors.constraintSet(1, MAPPING_MAX_LENGTH, NO_WHITESPACE_PATTERN, null)));
|
||||
}
|
||||
if (valueViolation) {
|
||||
violations.add(SmithyValidationErrors.Violations.WITHOUT_VALUES.mapValues(shapeName + "." + member,
|
||||
|
||||
@@ -295,9 +295,9 @@ public class IotAuthorizerService {
|
||||
Map<String, String> keys = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, JsonNode> entry : node.properties()) {
|
||||
if (!KEY_NAME_PATTERN.matcher(entry.getKey()).matches()) {
|
||||
throw constraint("tokenSigningPublicKeys", "Map keys must satisfy constraint: [Member must have length "
|
||||
+ "less than or equal to 128, Member must have length greater than or equal to 1, "
|
||||
+ "Member must satisfy regular expression pattern: [a-zA-Z0-9:_-]+]");
|
||||
throw invalid(SmithyValidationErrors.message(List.of(
|
||||
SmithyValidationErrors.Violations.WITHOUT_VALUES.mapKeys("tokenSigningPublicKeys", null,
|
||||
SmithyValidationErrors.constraintSet(1, 128, "[a-zA-Z0-9:_-]+", null)))));
|
||||
}
|
||||
keys.put(entry.getKey(), entry.getValue().asText(null));
|
||||
}
|
||||
|
||||
@@ -4458,11 +4458,9 @@ public class LambdaService implements ResourceProvider, VpcDependencyProvider {
|
||||
for (String key : tags.keySet()) {
|
||||
if (key.isEmpty() || key.codePointCount(0, key.length()) > MAX_TAG_KEY_LENGTH
|
||||
|| !TAG_KEY_PATTERN.matcher(key).matches()) {
|
||||
throw SmithyValidationErrors.validationException("Value '" + tags
|
||||
+ "' at 'tags' failed to satisfy constraint: Map keys must satisfy constraint: [Member"
|
||||
+ " must have length less than or equal to " + MAX_TAG_KEY_LENGTH + ", Member must have"
|
||||
+ " length greater than or equal to 1, Member must satisfy regular expression pattern: "
|
||||
+ TAG_KEY_PATTERN.pattern() + "]");
|
||||
throw SmithyValidationErrors.validationException(SmithyValidationErrors.Violations.QUOTED
|
||||
.mapKeys("tags", tags.toString(), SmithyValidationErrors.constraintSet(
|
||||
1, MAX_TAG_KEY_LENGTH, TAG_KEY_PATTERN.pattern(), null)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,9 +87,9 @@ final class LambdaWebValidation {
|
||||
boolean bad = map.keySet().stream()
|
||||
.anyMatch(k -> k.length() < min || k.length() > max || !pattern.matcher(k).matches());
|
||||
if (bad) {
|
||||
errors.add("Value at '" + path + "' failed to satisfy constraint: Map keys must satisfy constraint: ["
|
||||
+ lengthConstraints(min, max) + ", Member must satisfy regular expression pattern: "
|
||||
+ pattern.pattern() + "]");
|
||||
errors.add(SmithyValidationErrors.Violations.WITHOUT_VALUES.mapKeys(path, null, List.of(
|
||||
lengthConstraints(min, max),
|
||||
"Member must satisfy regular expression pattern: " + pattern.pattern())));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -110,9 +110,9 @@ final class LambdaWebValidation {
|
||||
LambdaWebValidation sensitiveMapKeys(String path, Map<String, ?> map, int min, Pattern pattern) {
|
||||
boolean bad = map.keySet().stream().anyMatch(k -> k.length() < min || !pattern.matcher(k).matches());
|
||||
if (bad) {
|
||||
errors.add("Value at '" + path + "' failed to satisfy constraint: Map keys must satisfy constraint: ["
|
||||
+ "Member must have length greater than or equal to " + min
|
||||
+ ", Member must satisfy regular expression pattern: " + pattern.pattern() + "]");
|
||||
errors.add(SmithyValidationErrors.Violations.WITHOUT_VALUES.mapKeys(path, null, List.of(
|
||||
"Member must have length greater than or equal to " + min,
|
||||
"Member must satisfy regular expression pattern: " + pattern.pattern())));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -235,9 +235,8 @@ final class SesV2Json {
|
||||
return Map.of();
|
||||
}
|
||||
if (!keys.containsAll(filter.keySet())) {
|
||||
throw SmithyValidationErrors.badRequest( "Value at 'filter' "
|
||||
+ "failed to satisfy constraint: Map keys must satisfy constraint: "
|
||||
+ "[Member must satisfy enum value set: [" + String.join(", ", keys) + "]]");
|
||||
throw SmithyValidationErrors.badRequest(SmithyValidationErrors.Violations.WITHOUT_VALUES
|
||||
.mapKeys("filter", null, List.of("Member must satisfy enum value set: " + keys)));
|
||||
}
|
||||
if (filter.values().stream().anyMatch(v -> v != null && invalidValue.test(v))) {
|
||||
throw SmithyValidationErrors.badRequest(SmithyValidationErrors.Violations.WITHOUT_VALUES
|
||||
|
||||
Reference in new issue
Block a user