Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

refactor: build the remaining one-violation validation messages through SmithyValidationErrors (#5927)

Kenshin Okinaka0f5260417fd8
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/TagDispatcher.java b/src/main/java/io/github/hectorvent/floci/core/common/TagDispatcher.java
index 3e704dc0f0..53f52a5248 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/TagDispatcher.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/TagDispatcher.java
@@ -129,22 +129,22 @@ public class TagDispatcher {
Map<String, String> tags = new HashMap<>();
String key = handler.tagsBodyKey();
if (handler.strictTagValidation() && !node.isObject()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Request payload must be a JSON object", 400);
+ throw SmithyValidationErrors.validationException(
+ "Request payload must be a JSON object");
}
JsonNode tagNode = node.get(key);
if (tagNode == null || tagNode.isNull()) {
if (handler.strictTagValidation()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at '" + key + "' failed to satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at '" + key + "' failed to satisfy constraint: Member must not be null");
}
return tags;
}
if (handler.tagsBodyIsList()) {
if (!tagNode.isArray()) {
if (handler.strictTagValidation()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at '" + key + "' failed to satisfy constraint: Member must be a list", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at '" + key + "' failed to satisfy constraint: Member must be a list");
}
return tags;
}
@@ -153,30 +153,30 @@ public class TagDispatcher {
JsonNode v = entry.get(handler.tagEntryValueName());
if (k == null || k.isNull() || v == null || v.isNull()) {
if (handler.strictTagValidation()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Tag entries at '" + key + "' must have non-null Key and Value", 400);
+ throw SmithyValidationErrors.validationException(
+ "Tag entries at '" + key + "' must have non-null Key and Value");
}
continue;
}
if (handler.strictTagValidation() && (!k.isTextual() || !v.isTextual())) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Tag entries at '" + key
- + "' must contain string Key and Value members", 400);
+ throw SmithyValidationErrors.validationException(
+ "Tag entries at '" + key
+ + "' must contain string Key and Value members");
}
tags.put(k.asText(), v.asText());
}
} else {
if (!tagNode.isObject()) {
if (handler.strictTagValidation()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at '" + key + "' failed to satisfy constraint: Member must be a map", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at '" + key + "' failed to satisfy constraint: Member must be a map");
}
return tags;
}
tagNode.fields().forEachRemaining(e -> {
if (handler.strictTagValidation() && !e.getValue().isTextual()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Tag values at '" + key + "' must be strings", 400);
+ throw SmithyValidationErrors.validationException(
+ "Tag values at '" + key + "' must be strings");
}
tags.put(e.getKey(), e.getValue().asText());
});
@@ -189,8 +189,8 @@ public class TagDispatcher {
List<String> values = uriInfo.getQueryParameters().get(paramName);
if (handler.strictTagValidation() && !handler.allowEmptyTagKeys()
&& (values == null || values.isEmpty())) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at '" + paramName + "' failed to satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at '" + paramName + "' failed to satisfy constraint: Member must not be null");
}
return (values == null) ? List.of() : List.copyOf(values);
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/acm/AcmJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/acm/AcmJsonHandler.java
index 119a743752..60a9d27dd8 100644
--- a/src/main/java/io/github/hectorvent/floci/services/acm/AcmJsonHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/acm/AcmJsonHandler.java
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.acm.model.Certificate;
import io.github.hectorvent.floci.services.acm.model.CertificateOptions;
import io.github.hectorvent.floci.services.acm.model.CertificateStatus;
@@ -102,9 +103,9 @@ public class AcmJsonHandler {
}
JsonNode sanNode = request.path("SubjectAlternativeNames");
if (sanNode.isArray() && sanNode.isEmpty()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '[]' at 'subjectAlternativeNames' failed to satisfy "
- + "constraint: Member must have length greater than or equal to 1", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '[]' at 'subjectAlternativeNames' failed to satisfy "
+ + "constraint: Member must have length greater than or equal to 1");
}
List<String> sans = parseStringList(sanNode);
ValidationMethod validationMethod = parseValidationMethod(request.path("ValidationMethod").asText(null));
diff --git a/src/main/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingQueryHandler.java
index a0f0298383..4aea160cdb 100644
--- a/src/main/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingQueryHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingQueryHandler.java
@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsNamespaces;
import io.github.hectorvent.floci.core.common.AwsQueryResponse;
import io.github.hectorvent.floci.core.common.PaginatedResult;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.common.XmlBuilder;
import io.github.hectorvent.floci.services.autoscaling.model.*;
import jakarta.enterprise.context.ApplicationScoped;
@@ -1957,9 +1958,9 @@ public class AutoScalingQueryHandler {
break;
}
if (deviceName == null || deviceName.isBlank()) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value null at '" + prefix
- + ".DeviceName' failed to satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationError(
+ "Value null at '" + prefix
+ + ".DeviceName' failed to satisfy constraint: Member must not be null");
}
LaunchConfigurationBlockDeviceMapping mapping = new LaunchConfigurationBlockDeviceMapping();
mapping.setDeviceName(deviceName);
@@ -2035,14 +2036,14 @@ public class AutoScalingQueryHandler {
private boolean requiredBoolParam(MultivaluedMap<String, String> p, String key) {
String val = p.getFirst(key);
if (val == null || val.isBlank()) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value null at '" + key
- + "' failed to satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationError(
+ "Value null at '" + key
+ + "' failed to satisfy constraint: Member must not be null");
}
if (!"true".equalsIgnoreCase(val) && !"false".equalsIgnoreCase(val)) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value '" + val + "' at '" + key
- + "' failed to satisfy constraint: Member must be a valid boolean", 400);
+ throw SmithyValidationErrors.validationError(
+ "Value '" + val + "' at '" + key
+ + "' failed to satisfy constraint: Member must be a valid boolean");
}
return parseOptionalBoolean(val, key);
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingService.java b/src/main/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingService.java
index 48f72ec086..3154ab47e6 100644
--- a/src/main/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingService.java
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageBackedMap;
import io.github.hectorvent.floci.core.storage.StorageFactory;
@@ -1119,30 +1120,30 @@ public class AutoScalingService {
private static void validateLifecycleHookName(String hookName) {
if (hookName == null) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value null at 'lifecycleHookName' failed to satisfy constraint: "
- + "Member must not be null", 400);
+ throw SmithyValidationErrors.validationError(
+ "Value null at 'lifecycleHookName' failed to satisfy constraint: "
+ + "Member must not be null");
}
if (hookName.length() > 255) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value '" + hookName
+ throw SmithyValidationErrors.validationError(
+ "Value '" + hookName
+ "' at 'lifecycleHookName' failed to satisfy constraint: Member must have length "
- + "less than or equal to 255", 400);
+ + "less than or equal to 255");
}
if (!LIFECYCLE_HOOK_NAME_PATTERN.matcher(hookName).matches()) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value '" + hookName
+ throw SmithyValidationErrors.validationError(
+ "Value '" + hookName
+ "' at 'lifecycleHookName' failed to satisfy constraint: Member must satisfy "
- + "regular expression pattern: [A-Za-z0-9\\-_/]+", 400);
+ + "regular expression pattern: [A-Za-z0-9\\-_/]+");
}
}
/** LifecycleActionToken is modeled as a fixed 36-character token (autoscaling/2011-01-01/service-2.json). */
private static void validateLifecycleActionToken(String token) {
if (token == null || token.length() != 36) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value at 'lifecycleActionToken' failed to satisfy constraint: "
- + "Member must have length equal to 36", 400);
+ throw SmithyValidationErrors.validationError(
+ "Value at 'lifecycleActionToken' failed to satisfy constraint: "
+ + "Member must have length equal to 36");
}
}
@@ -1561,20 +1562,19 @@ public class AutoScalingService {
for (String id : specification.getCapacityReservationIds()) {
if (id == null || id.isEmpty() || id.length() > 255
|| !CAPACITY_RESERVATION_ID_PATTERN.matcher(id).matches()) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value '" + id
+ throw SmithyValidationErrors.validationError(
+ "Value '" + id
+ "' at 'capacityReservationSpecification.capacityReservationTarget"
+ ".capacityReservationIds' failed to satisfy constraint: Member must have length "
- + "between 1 and 255 and satisfy regular expression pattern: [A-Za-z0-9\\-_\\/]+",
- 400);
+ + "between 1 and 255 and satisfy regular expression pattern: [A-Za-z0-9\\-_\\/]+");
}
}
for (String arn : specification.getCapacityReservationResourceGroupArns()) {
if (arn == null || arn.isEmpty() || arn.length() > MAX_RESOURCE_NAME_LENGTH) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value at 'capacityReservationSpecification"
+ throw SmithyValidationErrors.validationError(
+ "Value at 'capacityReservationSpecification"
+ ".capacityReservationTarget.capacityReservationResourceGroupArns' failed to "
- + "satisfy constraint: Member must have length between 1 and 1600", 400);
+ + "satisfy constraint: Member must have length between 1 and 1600");
}
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/bcmdataexports/BcmDataExportsService.java b/src/main/java/io/github/hectorvent/floci/services/bcmdataexports/BcmDataExportsService.java
index d6dcdc3d31..6282c8800e 100644
--- a/src/main/java/io/github/hectorvent/floci/services/bcmdataexports/BcmDataExportsService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/bcmdataexports/BcmDataExportsService.java
@@ -5,6 +5,7 @@ import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.S3DestinationValidation;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.bcmdataexports.model.DataQuery;
@@ -349,8 +350,8 @@ public class BcmDataExportsService {
private static void requireNonEmpty(String value, String field) {
if (value == null || value.isEmpty()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at '" + field + "' failed to satisfy constraint: Member must not be null.", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at '" + field + "' failed to satisfy constraint: Member must not be null.");
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/bedrockagentcorecontrol/BedrockAgentCoreControlService.java b/src/main/java/io/github/hectorvent/floci/services/bedrockagentcorecontrol/BedrockAgentCoreControlService.java
index 36dc64d505..be28bf7723 100644
--- a/src/main/java/io/github/hectorvent/floci/services/bedrockagentcorecontrol/BedrockAgentCoreControlService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/bedrockagentcorecontrol/BedrockAgentCoreControlService.java
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.model.AgentRuntime;
@@ -216,10 +217,10 @@ public class BedrockAgentCoreControlService {
throw new AwsException("ValidationException", member + " is required", 400);
}
if (!value.isTextual() || !allowed.contains(value.asText())) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + value.asText() + "' at '" + member
+ throw SmithyValidationErrors.validationException(
+ "Value '" + value.asText() + "' at '" + member
+ "' failed to satisfy constraint: Member must satisfy enum value set: "
- + allowed, 400);
+ + allowed);
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ce/CostExplorerService.java b/src/main/java/io/github/hectorvent/floci/services/ce/CostExplorerService.java
index 9975e7030f..1be138dc95 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ce/CostExplorerService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ce/CostExplorerService.java
@@ -5,8 +5,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.config.EmulatorConfig;
-import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.ResourceUsageEnumerator;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.common.UsageLine;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Instance;
@@ -84,8 +84,8 @@ public class CostExplorerService {
request.path("Granularity").asText(null));
Set<String> metrics = GroupAggregator.parseMetrics(request.path("Metrics"));
if (metrics.isEmpty()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at 'Metrics' failed to satisfy constraint: Member must contain at least 1 element.", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at 'Metrics' failed to satisfy constraint: Member must contain at least 1 element.");
}
List<GroupAggregator.GroupBy> groupBys = GroupAggregator.parseGroupBy(request.path("GroupBy"));
JsonNode filter = request.has("Filter") ? request.get("Filter") : null;
@@ -137,8 +137,8 @@ public class CostExplorerService {
TimeWindow window = parseTimeWindow(request);
String dimension = request.path("Dimension").asText(null);
if (dimension == null || dimension.isEmpty()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at 'Dimension' failed to satisfy constraint: Member must not be null.", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at 'Dimension' failed to satisfy constraint: Member must not be null.");
}
String search = request.path("SearchString").asText(null);
JsonNode filter = request.has("Filter") ? request.get("Filter") : null;
@@ -280,8 +280,8 @@ public class CostExplorerService {
private TimeWindow parseTimeWindow(JsonNode request) {
JsonNode tp = request.path("TimePeriod");
if (!tp.isObject() || tp.isEmpty()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at 'TimePeriod' failed to satisfy constraint: Member must not be null.", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at 'TimePeriod' failed to satisfy constraint: Member must not be null.");
}
Instant start = TimeBucketing.parseDate(tp.path("Start").asText(null), "TimePeriod.Start");
Instant end = TimeBucketing.parseDate(tp.path("End").asText(null), "TimePeriod.End");
diff --git a/src/main/java/io/github/hectorvent/floci/services/ce/TimeBucketing.java b/src/main/java/io/github/hectorvent/floci/services/ce/TimeBucketing.java
index 47e838fa6f..eda1efc563 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ce/TimeBucketing.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ce/TimeBucketing.java
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.ce;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import java.time.Instant;
import java.time.LocalDate;
@@ -25,22 +26,22 @@ final class TimeBucketing {
static Granularity parseGranularity(String value) {
if (value == null || value.isEmpty()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at 'Granularity' failed to satisfy constraint: Member must not be null.", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at 'Granularity' failed to satisfy constraint: Member must not be null.");
}
return switch (value) {
case "HOURLY" -> Granularity.HOURLY;
case "DAILY" -> Granularity.DAILY;
case "MONTHLY" -> Granularity.MONTHLY;
- default -> throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + value + "' at 'Granularity' failed to satisfy constraint: Member must satisfy enum value set: [DAILY, MONTHLY, HOURLY]", 400);
+ default -> throw SmithyValidationErrors.validationException(
+ "Value '" + value + "' at 'Granularity' failed to satisfy constraint: Member must satisfy enum value set: [DAILY, MONTHLY, HOURLY]");
};
}
static Instant parseDate(String value, String field) {
if (value == null || value.isEmpty()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at '" + field + "' failed to satisfy constraint: Member must not be null.", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at '" + field + "' failed to satisfy constraint: Member must not be null.");
}
// AWS accepts "YYYY-MM-DD" (most common) and ISO-8601 timestamps.
try {
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java
index c1443ef223..d185e05306 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java
@@ -1513,10 +1513,10 @@ public class CloudFormationService implements ResourceProvider {
return STAGE_ORIGINAL;
}
if (!TEMPLATE_STAGE_ENUM.contains(templateStage)) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value '" + templateStage + "' at 'templateStage' failed to "
+ throw SmithyValidationErrors.validationError(
+ "Value '" + templateStage + "' at 'templateStage' failed to "
+ "satisfy constraint: Member must satisfy enum value set: ["
- + String.join(", ", TEMPLATE_STAGE_ENUM) + "]", 400);
+ + String.join(", ", TEMPLATE_STAGE_ENUM) + "]");
}
return templateStage;
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/StackSetService.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/StackSetService.java
index 5599a0c68f..4139c10a08 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/StackSetService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/StackSetService.java
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.RequestScopes;
import io.github.hectorvent.floci.core.common.ServicePrincipals;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.cloudformation.model.ChangeSet;
@@ -311,12 +312,12 @@ public class StackSetService {
"Accounts can be used only with SELF_MANAGED StackSets. Use DeploymentTargets for SERVICE_MANAGED StackSets.", 400);
}
if (directAccounts.stream().anyMatch(account -> account == null || !account.matches("[0-9]{12}"))) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value '" + directAccounts
+ throw SmithyValidationErrors.validationError(
+ "Value '" + directAccounts
+ "' at 'accounts' failed to satisfy constraint: Member must satisfy constraint: "
+ "[Member must have length less than or equal to 12, Member must have length "
+ "greater than or equal to 12, Member must satisfy regular expression pattern: "
- + "^[0-9]{12}$]", 400);
+ + "^[0-9]{12}$]");
}
for (String ou : targetOus) validateOuOrRoot(ou);
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsService.java b/src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsService.java
index 68b07e61d8..129dfb4d04 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsService.java
@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.Base64Url;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.Resettable;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.resource.ExplorerResource;
import io.github.hectorvent.floci.core.resource.ResourceProvider;
import io.github.hectorvent.floci.core.resource.SupportedResourceType;
@@ -526,9 +527,9 @@ public class CloudWatchLogsService implements ResourceProvider, Resettable {
String region) {
boolean byLastEventTime = "LastEventTime".equals(orderBy);
if (orderBy != null && !orderBy.isBlank() && !byLastEventTime && !"LogStreamName".equals(orderBy)) {
- throw new AwsException("InvalidParameterException",
- "1 validation error detected: Value '" + orderBy + "' at 'orderBy' failed to satisfy "
- + "constraint: Member must satisfy enum value set: [LogStreamName, LastEventTime]", 400);
+ throw SmithyValidationErrors.exception("InvalidParameterException",
+ "Value '" + orderBy + "' at 'orderBy' failed to satisfy "
+ + "constraint: Member must satisfy enum value set: [LogStreamName, LastEventTime]");
}
// Matches real AWS: LastEventTime ordering cannot be combined with a name prefix.
if (byLastEventTime && prefix != null && !prefix.isBlank()) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/codegurureviewer/CodeGuruReviewerController.java b/src/main/java/io/github/hectorvent/floci/services/codegurureviewer/CodeGuruReviewerController.java
index 6ab4c50d7c..5269801d54 100644
--- a/src/main/java/io/github/hectorvent/floci/services/codegurureviewer/CodeGuruReviewerController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/codegurureviewer/CodeGuruReviewerController.java
@@ -4,10 +4,10 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
-import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.JsonErrorResponseUtils;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.codegurureviewer.model.RepositoryAssociation;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
@@ -179,9 +179,9 @@ public class CodeGuruReviewerController {
try {
return Integer.valueOf(maxResults);
} catch (NumberFormatException e) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + maxResults
- + "' at 'maxResults' failed to satisfy constraint: Member must be an integer.", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + maxResults
+ + "' at 'maxResults' failed to satisfy constraint: Member must be an integer.");
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoJsonHandler.java
index 83a4a03166..5ffe96cddc 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoJsonHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoJsonHandler.java
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.cognito.CognitoService.UserPoolDomainNames;
import io.github.hectorvent.floci.services.cognito.model.CognitoGroup;
import io.github.hectorvent.floci.services.cognito.model.CognitoUser;
@@ -872,11 +873,11 @@ public class CognitoJsonHandler {
List<Map<String, Object>> values = new ArrayList<>();
for (JsonNode element : node) {
if (element.isNull()) {
- throw new AwsException("InvalidParameterException",
- "1 validation error detected: Value '" + node + "' at '"
+ throw SmithyValidationErrors.exception("InvalidParameterException",
+ "Value '" + node + "' at '"
+ Character.toLowerCase(member.charAt(0)) + member.substring(1)
+ "' failed to satisfy constraint: Member must satisfy constraint: "
- + "[Member must not be null]", 400);
+ + "[Member must not be null]");
}
if (!element.isObject()) {
throw new AwsException("SerializationException", "Unexpected value type in payload", 400);
diff --git a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java
index 842355ef51..96d8e3dcd8 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java
@@ -577,26 +577,17 @@ public class CognitoService implements ResourceProvider {
private void validatePasswordPolicy(Map<String, Object> passwordPolicy) {
Object minLengthVal = passwordPolicy.get("MinimumLength");
if (minLengthVal == null) {
- throw new AwsException(
- "InvalidParameterException",
- "1 validation error detected: Value '0' at 'policies.passwordPolicy.minimumLength' failed to satisfy constraint: Member must have value greater than or equal to 6",
- 400
- );
+ throw validationError(
+ "Value '0' at 'policies.passwordPolicy.minimumLength' failed to satisfy constraint: Member must have value greater than or equal to 6");
}
BigInteger minLength = policyInteger(passwordPolicy, "MinimumLength", "minimumLength");
if (minLength.compareTo(BigInteger.valueOf(6)) < 0) {
- throw new AwsException(
- "InvalidParameterException",
- "1 validation error detected: Value '" + minLengthVal + "' at 'policies.passwordPolicy.minimumLength' failed to satisfy constraint: Member must have value greater than or equal to 6",
- 400
- );
+ throw validationError(
+ "Value '" + minLengthVal + "' at 'policies.passwordPolicy.minimumLength' failed to satisfy constraint: Member must have value greater than or equal to 6");
}
if (minLength.compareTo(BigInteger.valueOf(99)) > 0) {
- throw new AwsException(
- "InvalidParameterException",
- "1 validation error detected: Value '" + minLengthVal + "' at 'policies.passwordPolicy.minimumLength' failed to satisfy constraint: Member must have value less than or equal to 99",
- 400
- );
+ throw validationError(
+ "Value '" + minLengthVal + "' at 'policies.passwordPolicy.minimumLength' failed to satisfy constraint: Member must have value less than or equal to 99");
}
if (passwordPolicy.containsKey("TemporaryPasswordValidityDays")) {
@@ -605,18 +596,12 @@ public class CognitoService implements ResourceProvider {
BigInteger tempDays = policyInteger(passwordPolicy, "TemporaryPasswordValidityDays",
"temporaryPasswordValidityDays");
if (tempDays.compareTo(BigInteger.ZERO) < 0) {
- throw new AwsException(
- "InvalidParameterException",
- "1 validation error detected: Value '" + tempDaysVal + "' at 'policies.passwordPolicy.temporaryPasswordValidityDays' failed to satisfy constraint: Member must have value greater than or equal to 0",
- 400
- );
+ throw validationError(
+ "Value '" + tempDaysVal + "' at 'policies.passwordPolicy.temporaryPasswordValidityDays' failed to satisfy constraint: Member must have value greater than or equal to 0");
}
if (tempDays.compareTo(BigInteger.valueOf(365)) > 0) {
- throw new AwsException(
- "InvalidParameterException",
- "1 validation error detected: Value '" + tempDaysVal + "' at 'policies.passwordPolicy.temporaryPasswordValidityDays' failed to satisfy constraint: Member must have value less than or equal to 365",
- 400
- );
+ throw validationError(
+ "Value '" + tempDaysVal + "' at 'policies.passwordPolicy.temporaryPasswordValidityDays' failed to satisfy constraint: Member must have value less than or equal to 365");
}
}
}
@@ -626,18 +611,12 @@ public class CognitoService implements ResourceProvider {
if (historySizeVal != null) {
BigInteger historySize = policyInteger(passwordPolicy, "PasswordHistorySize", "passwordHistorySize");
if (historySize.compareTo(BigInteger.ZERO) < 0) {
- throw new AwsException(
- "InvalidParameterException",
- "1 validation error detected: Value '" + historySizeVal + "' at 'policies.passwordPolicy.passwordHistorySize' failed to satisfy constraint: Member must have value greater than or equal to 0",
- 400
- );
+ throw validationError(
+ "Value '" + historySizeVal + "' at 'policies.passwordPolicy.passwordHistorySize' failed to satisfy constraint: Member must have value greater than or equal to 0");
}
if (historySize.compareTo(BigInteger.valueOf(24)) > 0) {
- throw new AwsException(
- "InvalidParameterException",
- "1 validation error detected: Value '" + historySizeVal + "' at 'policies.passwordPolicy.passwordHistorySize' failed to satisfy constraint: Member must have value less than or equal to 24",
- 400
- );
+ throw validationError(
+ "Value '" + historySizeVal + "' at 'policies.passwordPolicy.passwordHistorySize' failed to satisfy constraint: Member must have value less than or equal to 24");
}
}
}
@@ -802,10 +781,10 @@ public class CognitoService implements ResourceProvider {
// to OFF when the member is omitted.
String mode = mfaConfiguration != null ? mfaConfiguration : "OFF";
if (!List.of("OPTIONAL", "OFF", "ON").contains(mode)) {
- throw new AwsException("InvalidParameterException",
- "1 validation error detected: Value '" + mode
+ throw validationError(
+ "Value '" + mode
+ "' at 'mfaConfiguration' failed to satisfy constraint: "
- + "Member must satisfy enum value set: [OPTIONAL, OFF, ON]", 400);
+ + "Member must satisfy enum value set: [OPTIONAL, OFF, ON]");
}
// Presence, not value: the live service rejects OFF alongside
// SoftwareTokenMfaConfiguration{Enabled:false} just as it does Enabled:true, and
@@ -858,25 +837,24 @@ public class CognitoService implements ResourceProvider {
private static void validateWebAuthnConfiguration(WebAuthnConfiguration configuration) {
String relyingPartyId = configuration.getRelyingPartyId();
if (relyingPartyId != null && (relyingPartyId.isEmpty() || relyingPartyId.length() > 127)) {
- throw new AwsException("InvalidParameterException",
- "1 validation error detected: Value at 'webAuthnConfiguration.relyingPartyId' failed to "
- + "satisfy constraint: Member must have length between 1 and 127", 400);
+ throw validationError(
+ "Value at 'webAuthnConfiguration.relyingPartyId' failed to "
+ + "satisfy constraint: Member must have length between 1 and 127");
}
String userVerification = configuration.getUserVerification();
if (userVerification != null && !List.of("required", "preferred").contains(userVerification)) {
- throw new AwsException("InvalidParameterException",
- "1 validation error detected: Value '" + userVerification + "' at "
+ throw validationError(
+ "Value '" + userVerification + "' at "
+ "'webAuthnConfiguration.userVerification' failed to satisfy constraint: Member must "
- + "satisfy enum value set: [required, preferred]", 400);
+ + "satisfy enum value set: [required, preferred]");
}
String factorConfiguration = configuration.getFactorConfiguration();
if (factorConfiguration != null
&& !List.of("SINGLE_FACTOR", "MULTI_FACTOR_WITH_USER_VERIFICATION").contains(factorConfiguration)) {
- throw new AwsException("InvalidParameterException",
- "1 validation error detected: Value '" + factorConfiguration + "' at "
+ throw validationError(
+ "Value '" + factorConfiguration + "' at "
+ "'webAuthnConfiguration.factorConfiguration' failed to satisfy constraint: Member "
- + "must satisfy enum value set: [SINGLE_FACTOR, MULTI_FACTOR_WITH_USER_VERIFICATION]",
- 400);
+ + "must satisfy enum value set: [SINGLE_FACTOR, MULTI_FACTOR_WITH_USER_VERIFICATION]");
}
}
@@ -1432,9 +1410,9 @@ public class CognitoService implements ResourceProvider {
String constraint = authSessionValidity < 3
? "Member must have value greater than or equal to 3"
: "Member must have value less than or equal to 15";
- throw new AwsException("InvalidParameterException",
- "1 validation error detected: Value '" + authSessionValidity
- + "' at 'authSessionValidity' failed to satisfy constraint: " + constraint, 400);
+ throw validationError(
+ "Value '" + authSessionValidity
+ + "' at 'authSessionValidity' failed to satisfy constraint: " + constraint);
}
}
@@ -1667,10 +1645,10 @@ public class CognitoService implements ResourceProvider {
private void validateProviderType(String providerType) {
if (providerType == null || !PROVIDER_TYPES.contains(providerType)) {
- throw new AwsException("InvalidParameterException",
- "1 validation error detected: Value '" + providerType + "' at 'providerType' failed to "
+ throw validationError(
+ "Value '" + providerType + "' at 'providerType' failed to "
+ "satisfy constraint: Member must satisfy enum value set: "
- + "[Facebook, SAML, SignInWithApple, LoginWithAmazon, OIDC, Google]", 400);
+ + "[Facebook, SAML, SignInWithApple, LoginWithAmazon, OIDC, Google]");
}
}
@@ -2070,10 +2048,14 @@ public class CognitoService implements ResourceProvider {
}
}
- private AwsException validationErrors(List<String> errors) {
+ private static AwsException validationErrors(List<String> errors) {
return SmithyValidationErrors.exception("InvalidParameterException", errors);
}
+ private static AwsException validationError(String violation) {
+ return SmithyValidationErrors.exception("InvalidParameterException", violation);
+ }
+
/** Mirrors the request model's {@code toString}, which AWS embeds in the length-constraint message. */
private String renderLogConfigurations(List<Map<String, Object>> configs) {
List<String> rendered = new ArrayList<>();
@@ -2209,9 +2191,9 @@ public class CognitoService implements ResourceProvider {
private static void validateMessageAction(String messageAction) {
if (messageAction != null && !MESSAGE_ACTIONS.contains(messageAction)) {
- throw new AwsException("InvalidParameterException",
- "1 validation error detected: Value '" + messageAction + "' at 'messageAction' failed to "
- + "satisfy constraint: Member must satisfy enum value set: [RESEND, SUPPRESS]", 400);
+ throw validationError(
+ "Value '" + messageAction + "' at 'messageAction' failed to "
+ + "satisfy constraint: Member must satisfy enum value set: [RESEND, SUPPRESS]");
}
}
@@ -2221,10 +2203,10 @@ public class CognitoService implements ResourceProvider {
return List.of("SMS");
}
if (!DELIVERY_MEDIUMS.containsAll(requested)) {
- throw new AwsException("InvalidParameterException",
- "1 validation error detected: Value '" + requested + "' at 'desiredDeliveryMediums' failed to "
+ throw validationError(
+ "Value '" + requested + "' at 'desiredDeliveryMediums' failed to "
+ "satisfy constraint: Member must satisfy constraint: "
- + "[Member must satisfy enum value set: [SMS, EMAIL]]", 400);
+ + "[Member must satisfy enum value set: [SMS, EMAIL]]");
}
return requested;
}
@@ -2543,8 +2525,8 @@ public class CognitoService implements ResourceProvider {
*/
public void globalSignOut(String accessToken) {
if (accessToken == null || accessToken.isEmpty()) {
- throw new AwsException("InvalidParameterException",
- "1 validation error detected: Value at 'accessToken' failed to satisfy constraint: Member must not be null", 400);
+ throw validationError(
+ "Value at 'accessToken' failed to satisfy constraint: Member must not be null");
}
VerifiedAccessToken token = verifyAccessToken(accessToken);
@@ -2574,8 +2556,8 @@ public class CognitoService implements ResourceProvider {
*/
public void deleteUser(String accessToken) {
if (accessToken == null || accessToken.isEmpty()) {
- throw new AwsException("InvalidParameterException",
- "1 validation error detected: Value at 'accessToken' failed to satisfy constraint: Member must not be null", 400);
+ throw validationError(
+ "Value at 'accessToken' failed to satisfy constraint: Member must not be null");
}
VerifiedAccessToken token = verifyAccessToken(accessToken);
@@ -3719,9 +3701,9 @@ public class CognitoService implements ResourceProvider {
String constraint = maxResults < 0
? "greater than or equal to 0"
: "less than or equal to " + CognitoWebAuthn.MAX_CREDENTIALS_PER_USER;
- throw new AwsException("InvalidParameterException",
- "1 validation error detected: Value '" + maxResults + "' at 'maxResults' failed to satisfy "
- + "constraint: Member must have value " + constraint, 400);
+ throw validationError(
+ "Value '" + maxResults + "' at 'maxResults' failed to satisfy "
+ + "constraint: Member must have value " + constraint);
}
int pageSize = maxResults == null || maxResults == 0 ? CognitoWebAuthn.MAX_CREDENTIALS_PER_USER : maxResults;
List<WebAuthnCredential> credentials = adminGetUser(token.poolId(), token.username()).getWebAuthnCredentials();
@@ -5325,11 +5307,9 @@ public class CognitoService implements ResourceProvider {
}
private static AwsException notAnInteger(Object value, String member) {
- return new AwsException(
- "InvalidParameterException",
- "1 validation error detected: Value '" + value + "' at 'policies.passwordPolicy." + member
- + "' failed to satisfy constraint: Member must be an integer",
- 400);
+ return validationError(
+ "Value '" + value + "' at 'policies.passwordPolicy." + member
+ + "' failed to satisfy constraint: Member must be an integer");
}
private boolean policyBoolean(Map<String, Object> policy, String key) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/cognitoidentity/CognitoIdentityJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/cognitoidentity/CognitoIdentityJsonHandler.java
index ba3026332b..456750e0a0 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cognitoidentity/CognitoIdentityJsonHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cognitoidentity/CognitoIdentityJsonHandler.java
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.cognitoidentity.model.CognitoIdentityProvider;
import io.github.hectorvent.floci.services.cognitoidentity.model.IdentityPool;
import io.github.hectorvent.floci.services.cognitoidentity.model.PrincipalTagAttributeMap;
@@ -219,9 +220,9 @@ public class CognitoIdentityJsonHandler {
private boolean requiredBool(JsonNode node, String field) {
Boolean value = bool(node, field);
if (value == null) {
- throw new AwsException("ValidationException", "1 validation error detected: Value null at '"
+ throw SmithyValidationErrors.validationException("Value null at '"
+ Character.toLowerCase(field.charAt(0)) + field.substring(1)
- + "' failed to satisfy constraint: Member must not be null", 400);
+ + "' failed to satisfy constraint: Member must not be null");
}
return value;
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/cur/CurService.java b/src/main/java/io/github/hectorvent/floci/services/cur/CurService.java
index 4d2db578f7..7b60499560 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cur/CurService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cur/CurService.java
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.S3DestinationValidation;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.cur.model.ReportDefinition;
@@ -281,8 +282,8 @@ public class CurService {
private static void requireNonEmpty(String value, String field) {
if (value == null || value.isEmpty()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at '" + field + "' failed to satisfy constraint: Member must not be null.", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at '" + field + "' failed to satisfy constraint: Member must not be null.");
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbService.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbService.java
index cbfc6f799a..1c1249bbca 100644
--- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbService.java
@@ -13,6 +13,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.Digests;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.RequestScopes;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.resource.ExplorerResource;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageBackend;
@@ -358,10 +359,10 @@ public class DynamoDbService {
for (int i = 0; i < keySchema.size(); i++) {
String keyType = keySchema.get(i).getKeyType();
if (!"HASH".equals(keyType) && !"RANGE".equals(keyType)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + keyType
+ throw SmithyValidationErrors.validationException(
+ "Value '" + keyType
+ "' at 'keySchema." + (i + 1) + ".member.keyType' failed to satisfy constraint: "
- + "Member must satisfy enum value set: [HASH, RANGE]", 400);
+ + "Member must satisfy enum value set: [HASH, RANGE]");
}
}
@@ -370,9 +371,9 @@ public class DynamoDbService {
String repr = "[" + keySchema.stream()
.map(k -> "KeySchemaElement(attributeName=" + k.getAttributeName() + ", keyType=" + k.getKeyType() + ")")
.collect(Collectors.joining(", ")) + "]";
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + repr + "' at 'keySchema' failed to satisfy constraint: "
- + "Member must have length less than or equal to 2", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + repr + "' at 'keySchema' failed to satisfy constraint: "
+ + "Member must have length less than or equal to 2");
}
// Validate no duplicate attribute names in keySchema
@@ -389,10 +390,10 @@ public class DynamoDbService {
for (int i = 0; i < attributeDefinitions.size(); i++) {
String attrType = attributeDefinitions.get(i).getAttributeType();
if (!"B".equals(attrType) && !"N".equals(attrType) && !"S".equals(attrType)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + attrType
+ throw SmithyValidationErrors.validationException(
+ "Value '" + attrType
+ "' at 'attributeDefinitions." + (i + 1) + ".member.attributeType' failed to satisfy constraint: "
- + "Member must satisfy enum value set: [B, N, S]", 400);
+ + "Member must satisfy enum value set: [B, N, S]");
}
}
}
@@ -552,24 +553,24 @@ public class DynamoDbService {
requireVectorIndexMember(index.getDistanceFunction(), memberPath + ".distanceFunction");
String indexName = index.getIndexName();
if (indexName == null || indexName.length() < MIN_VECTOR_INDEX_NAME_LENGTH) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + indexName + "' at '"
+ throw SmithyValidationErrors.validationException(
+ "Value '" + indexName + "' at '"
+ memberPath + ".indexName' failed to satisfy constraint: "
- + "Member must have length greater than or equal to " + MIN_VECTOR_INDEX_NAME_LENGTH, 400);
+ + "Member must have length greater than or equal to " + MIN_VECTOR_INDEX_NAME_LENGTH);
}
String distanceFunction = index.getDistanceFunction();
if (!VECTOR_DISTANCE_FUNCTIONS.contains(distanceFunction)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + distanceFunction + "' at '"
+ throw SmithyValidationErrors.validationException(
+ "Value '" + distanceFunction + "' at '"
+ memberPath + ".distanceFunction' failed to satisfy constraint: "
- + "Member must satisfy enum value set: " + VECTOR_DISTANCE_FUNCTIONS, 400);
+ + "Member must satisfy enum value set: " + VECTOR_DISTANCE_FUNCTIONS);
}
Long dimensions = index.getDimensions();
if (dimensions < 1) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + dimensions + "' at '"
+ throw SmithyValidationErrors.validationException(
+ "Value '" + dimensions + "' at '"
+ memberPath + ".dimensions' failed to satisfy constraint: "
- + "Member must have value greater than or equal to 1", 400);
+ + "Member must have value greater than or equal to 1");
}
}
}
@@ -644,9 +645,9 @@ public class DynamoDbService {
private static void requireVectorIndexMember(Object value, String memberPath) {
if (value == null) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at '" + memberPath
- + "' failed to satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at '" + memberPath
+ + "' failed to satisfy constraint: Member must not be null");
}
}
@@ -3512,13 +3513,11 @@ public class DynamoDbService {
}
if (index < 0 || index > MAX_DYNAMODB_LIST_INDEX) {
- throw new AwsException(
- "ValidationException",
- "1 validation error detected: Invalid UpdateExpression: "
+ throw SmithyValidationErrors.validationException(
+ "Invalid UpdateExpression: "
+ "List index is not within the allowable range; index: ["
+ indexText
- + "]. The maximum allowed index is 4294967294",
- 400);
+ + "]. The maximum allowed index is 4294967294");
}
tokens.add(index);
@@ -4729,15 +4728,15 @@ public class DynamoDbService {
return;
}
if (pageSize < 1) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + pageSize + "' at '" + field
- + "' failed to satisfy constraint: Member must have value greater than or equal to 1", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + pageSize + "' at '" + field
+ + "' failed to satisfy constraint: Member must have value greater than or equal to 1");
}
if (MAX_JOB_PAGE_SIZE < pageSize) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + pageSize + "' at '" + field
+ throw SmithyValidationErrors.validationException(
+ "Value '" + pageSize + "' at '" + field
+ "' failed to satisfy constraint: Member must have value less than or equal to "
- + MAX_JOB_PAGE_SIZE, 400);
+ + MAX_JOB_PAGE_SIZE);
}
}
@@ -4772,10 +4771,10 @@ public class DynamoDbService {
static void validateBillingMode(JsonNode request, String memberPrefix) {
JsonNode billingMode = request.path("BillingMode");
if (billingMode.isTextual() && !VALID_BILLING_MODES.contains(billingMode.asText())) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + billingMode.asText() + "' at '" + memberPrefix
+ throw SmithyValidationErrors.validationException(
+ "Value '" + billingMode.asText() + "' at '" + memberPrefix
+ "billingMode' failed to satisfy constraint: "
- + "Member must satisfy enum value set: [PROVISIONED, PAY_PER_REQUEST]", 400);
+ + "Member must satisfy enum value set: [PROVISIONED, PAY_PER_REQUEST]");
}
}
@@ -4794,26 +4793,26 @@ public class DynamoDbService {
case "" -> throw new AwsException("ValidationException", "InputFormat is required", 400);
case "CSV", "ION" -> throw new AwsException("ValidationException",
"Unsupported InputFormat: " + inputFormat + ". Floci imports DYNAMODB_JSON only", 400);
- default -> throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + inputFormat
- + "' at 'inputFormat' failed to satisfy constraint: Member must satisfy enum value set: [ION, CSV, DYNAMODB_JSON]", 400);
+ default -> throw SmithyValidationErrors.validationException(
+ "Value '" + inputFormat
+ + "' at 'inputFormat' failed to satisfy constraint: Member must satisfy enum value set: [ION, CSV, DYNAMODB_JSON]");
}
var compression = request.path("InputCompressionType").asText("NONE");
switch (compression) {
case "NONE", "GZIP" -> { }
case "ZSTD" -> throw new AwsException("ValidationException",
"Unsupported InputCompressionType: ZSTD. Floci accepts NONE or GZIP", 400);
- default -> throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + compression
- + "' at 'inputCompressionType' failed to satisfy constraint: Member must satisfy enum value set: [GZIP, ZSTD, NONE]", 400);
+ default -> throw SmithyValidationErrors.validationException(
+ "Value '" + compression
+ + "' at 'inputCompressionType' failed to satisfy constraint: Member must satisfy enum value set: [GZIP, ZSTD, NONE]");
}
DynamoDbTableNames.requireShortName(request.path("TableCreationParameters").path("TableName").asText(null));
validateBillingMode(request.path("TableCreationParameters"), "tableCreationParameters.");
var clientToken = request.path("ClientToken").asText(null);
if (clientToken != null && clientToken.isBlank()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + clientToken
- + "' at 'clientToken' failed to satisfy constraint: Member must have length greater than or equal to 1", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + clientToken
+ + "' at 'clientToken' failed to satisfy constraint: Member must have length greater than or equal to 1");
}
if (clientToken == null || importStore == null) {
return null;
diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbTableNames.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbTableNames.java
index 1d0cb98270..d14f56176a 100644
--- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbTableNames.java
+++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbTableNames.java
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.dynamodb;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import java.util.regex.Pattern;
@@ -32,9 +33,9 @@ public final class DynamoDbTableNames {
"The parameter 'TableName' is required but was not present in the request", 400);
}
if (input.isEmpty()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + input
- + "' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 3", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + input
+ + "' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 3");
}
if (input.startsWith("arn:")) {
throw invalid("TableName must be a short name, not an ARN: " + input);
@@ -53,12 +54,12 @@ public final class DynamoDbTableNames {
private static ResolvedTableRef resolveInternal(String input) {
if (input == null) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'tableName' failed to satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'tableName' failed to satisfy constraint: Member must not be null");
}
if (input.isEmpty()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 1", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 1");
}
if (input.startsWith("arn:")) {
return parseArn(input);
@@ -111,38 +112,38 @@ public final class DynamoDbTableNames {
// Validation for CreateTable: min length 3, max 255, pattern
private static void validateTableNameForCreate(String tableName) {
if (tableName.length() < 3) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + tableName
- + "' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 3", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + tableName
+ + "' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 3");
}
if (tableName.length() > 255) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + tableName
- + "' at 'tableName' failed to satisfy constraint: Member must have length less than or equal to 255", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + tableName
+ + "' at 'tableName' failed to satisfy constraint: Member must have length less than or equal to 255");
}
if (!TABLE_NAME_CHARS.matcher(tableName).matches()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + tableName
- + "' at 'tableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + tableName
+ + "' at 'tableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+");
}
}
// Validation for other operations (PutItem, GetItem, etc.): min length 3, max 255, pattern
private static void validateTableNameForOps(String tableName) {
if (tableName.length() < 3) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + tableName
- + "' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 3", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + tableName
+ + "' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 3");
}
if (tableName.length() > 255) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + tableName
- + "' at 'tableName' failed to satisfy constraint: Member must have length less than or equal to 255", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + tableName
+ + "' at 'tableName' failed to satisfy constraint: Member must have length less than or equal to 255");
}
if (!TABLE_NAME_CHARS.matcher(tableName).matches()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + tableName
- + "' at 'tableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + tableName
+ + "' at 'tableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+");
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java
index f632f44f97..512c5b3133 100644
--- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java
@@ -319,10 +319,10 @@ public class NativeDynamoDbJsonHandler {
private static void rejectEmptyNonKeyAttributes(JsonNode nonKeyAttrArray, String memberPath) {
if (nonKeyAttrArray.isArray() && nonKeyAttrArray.isEmpty()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '[]' at '" + memberPath
+ throw SmithyValidationErrors.validationException(
+ "Value '[]' at '" + memberPath
+ ".projection.nonKeyAttributes' failed to satisfy constraint: "
- + "Member must have length greater than or equal to 1", 400);
+ + "Member must have length greater than or equal to 1");
}
}
@@ -332,10 +332,10 @@ public class NativeDynamoDbJsonHandler {
// carries no AttributeName as the nested member. Only the request shape tells them apart.
JsonNode vectorAttribute = node.path("VectorAttribute");
if (vectorAttribute.isObject() && !vectorAttribute.hasNonNull("AttributeName")) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at '" + memberPath
+ throw SmithyValidationErrors.validationException(
+ "Value null at '" + memberPath
+ ".vectorAttribute.attributeName' failed to satisfy constraint: "
- + "Member must not be null", 400);
+ + "Member must not be null");
}
List<SearchSchemaElement> searchSchema = new ArrayList<>();
JsonNode searchSchemaArray = node.path("SearchSchema");
@@ -510,16 +510,16 @@ public class NativeDynamoDbJsonHandler {
if (limit != null) {
if (limit < 1) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + limit
+ throw SmithyValidationErrors.validationException(
+ "Value '" + limit
+ "' at 'limit' failed to satisfy constraint: "
- + "Member must have value greater than or equal to 1", 400);
+ + "Member must have value greater than or equal to 1");
}
if (limit > 100) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + limit
+ throw SmithyValidationErrors.validationException(
+ "Value '" + limit
+ "' at 'limit' failed to satisfy constraint: "
- + "Member must have value less than or equal to 100", 400);
+ + "Member must have value less than or equal to 100");
}
}
@@ -762,10 +762,10 @@ public class NativeDynamoDbJsonHandler {
// UpdateItem stops at the first invalid enum and reports one error, unlike PutItem
// and DeleteItem which aggregate.
if (!VALID_RETURN_VALUES_UPDATE.contains(returnValues)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + returnValues + "' at 'returnValues' "
+ throw SmithyValidationErrors.validationException(
+ "Value '" + returnValues + "' at 'returnValues' "
+ "failed to satisfy constraint: "
- + "Member must satisfy enum value set: [NONE, ALL_OLD, ALL_NEW, UPDATED_OLD, UPDATED_NEW]", 400);
+ + "Member must satisfy enum value set: [NONE, ALL_OLD, ALL_NEW, UPDATED_OLD, UPDATED_NEW]");
}
requireValidReturnConsumedCapacity(request);
DynamoDbExpressionSize.checkWrite(updateExpression, "UpdateExpression");
@@ -971,8 +971,8 @@ public class NativeDynamoDbJsonHandler {
}
private AwsException legacyExpectedValidationError(String detail) {
- return new AwsException("ValidationException",
- "1 validation error detected: One or more parameter values were invalid: " + detail, 400);
+ return SmithyValidationErrors.validationException(
+ "One or more parameter values were invalid: " + detail);
}
/**
@@ -1071,15 +1071,15 @@ public class NativeDynamoDbJsonHandler {
// Validate Limit
if (limit != null && limit < 1) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at 'Limit' failed to satisfy constraint: "
- + "Member must have value greater than or equal to 1", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at 'Limit' failed to satisfy constraint: "
+ + "Member must have value greater than or equal to 1");
}
// Validate ReturnConsumedCapacity before Select
String rccQueryError = returnConsumedCapacityError(request);
if (rccQueryError != null) {
- throw new AwsException("ValidationException", "1 validation error detected: " + rccQueryError, 400);
+ throw SmithyValidationErrors.validationException(rccQueryError);
}
// DynamoDB counts KeyConditions as a non-expression parameter only next to a KeyConditionExpression.
@@ -1119,15 +1119,15 @@ public class NativeDynamoDbJsonHandler {
ExpressionEvaluator.validateSemantics(keyConditionExpr, "KeyConditionExpression", exprAttrNames, exprAttrValues);
if (select != null && !VALID_SELECT.contains(select)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + select + "' at 'select' failed to satisfy constraint: "
- + "Member must satisfy enum value set: [SPECIFIC_ATTRIBUTES, COUNT, ALL_ATTRIBUTES, ALL_PROJECTED_ATTRIBUTES]", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + select + "' at 'select' failed to satisfy constraint: "
+ + "Member must satisfy enum value set: [SPECIFIC_ATTRIBUTES, COUNT, ALL_ATTRIBUTES, ALL_PROJECTED_ATTRIBUTES]");
}
boolean hasAttributesToGet = attributesToGet != null && attributesToGet.size() > 0;
if ("SPECIFIC_ATTRIBUTES".equals(select) && projectionExpression == null && !hasAttributesToGet) {
- throw new AwsException("ValidationException",
- "1 validation error detected: " + SELECT_NEEDS_PROJECTION, 400);
+ throw SmithyValidationErrors.validationException(
+ SELECT_NEEDS_PROJECTION);
}
TableDefinition queryTable = dynamoDbService.requireTableForItemCall(tableName, region);
@@ -1246,7 +1246,7 @@ public class NativeDynamoDbJsonHandler {
String rccScanError = returnConsumedCapacityError(request);
if (rccScanError != null) {
- throw new AwsException("ValidationException", "1 validation error detected: " + rccScanError, 400);
+ throw SmithyValidationErrors.validationException(rccScanError);
}
rejectMixedParameters(request,
@@ -1268,15 +1268,15 @@ public class NativeDynamoDbJsonHandler {
checkUnusedEav(exprAttrValues, extractColonTokens(filterExpr));
if (select != null && !VALID_SELECT.contains(select)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + select + "' at 'select' failed to satisfy constraint: "
- + "Member must satisfy enum value set: [SPECIFIC_ATTRIBUTES, COUNT, ALL_ATTRIBUTES, ALL_PROJECTED_ATTRIBUTES]", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + select + "' at 'select' failed to satisfy constraint: "
+ + "Member must satisfy enum value set: [SPECIFIC_ATTRIBUTES, COUNT, ALL_ATTRIBUTES, ALL_PROJECTED_ATTRIBUTES]");
}
boolean hasAttributesToGetScan = attributesToGetScan != null && attributesToGetScan.size() > 0;
if ("SPECIFIC_ATTRIBUTES".equals(select)
&& projectionExpressionScan == null && !hasAttributesToGetScan) {
- throw new AwsException("ValidationException",
- "1 validation error detected: " + SELECT_NEEDS_PROJECTION, 400);
+ throw SmithyValidationErrors.validationException(
+ SELECT_NEEDS_PROJECTION);
}
DynamoDbAccessPathValidator.validateSelection(select, indexNameScan,
projectionExpressionScan, attributesToGetScan);
@@ -1365,9 +1365,9 @@ public class NativeDynamoDbJsonHandler {
if (topK < 1) {
// AWS names this member TopK and quotes no value, unlike every other member of this
// family. Measured on real DynamoDB, eu-west-2, 2026-09-23.
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at 'TopK' failed to satisfy "
- + "constraint: Member must have value greater than or equal to 1", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at 'TopK' failed to satisfy "
+ + "constraint: Member must have value greater than or equal to 1");
}
// Both bounds answer before the table and the index are resolved: AWS reports the range
// even for a table that does not exist.
@@ -1476,10 +1476,10 @@ public class NativeDynamoDbJsonHandler {
reprs.add(w.toString());
}
sb.append(String.join(", ", reprs)).append("]}");
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + sb + "' at 'requestItems' failed to satisfy constraint: "
+ throw SmithyValidationErrors.validationException(
+ "Value '" + sb + "' at 'requestItems' failed to satisfy constraint: "
+ "Map value must satisfy constraint: [Member must have length less than or equal to 25, "
- + "Member must have length greater than or equal to 1]", 400);
+ + "Member must have length greater than or equal to 1]");
}
}
@@ -1546,9 +1546,9 @@ public class NativeDynamoDbJsonHandler {
// BatchGetItem answers an empty map from the validation framework, BatchWriteItem
// still answers with its own sentence.
if (!requestItems.fields().hasNext()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at 'RequestItems' failed to satisfy constraint: "
- + "Member must have length greater than or equal to 1", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at 'RequestItems' failed to satisfy constraint: "
+ + "Member must have length greater than or equal to 1");
}
Map<String, JsonNode> items = new HashMap<>();
Iterator<Map.Entry<String, JsonNode>> tables = requestItems.fields();
@@ -1581,10 +1581,10 @@ public class NativeDynamoDbJsonHandler {
}
JsonNode keysNode = entry.getValue().has("Keys") ? entry.getValue().get("Keys") : null;
if (keysNode != null && keysNode.size() > 100) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at 'RequestItems." + entry.getKey()
+ throw SmithyValidationErrors.validationException(
+ "Value at 'RequestItems." + entry.getKey()
+ ".member.Keys' failed to satisfy constraint: "
- + "Member must have length less than or equal to 100", 400);
+ + "Member must have length less than or equal to 100");
}
}
@@ -2196,9 +2196,9 @@ public class NativeDynamoDbJsonHandler {
"Invalid ResourceArn: " + resourceArn, 400);
}
if (!request.hasNonNull("Policy")) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'policy' failed to satisfy constraint: "
- + "Member must not be null", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'policy' failed to satisfy constraint: "
+ + "Member must not be null");
}
String policy = request.path("Policy").asText();
String expectedRevisionId = request.has("ExpectedRevisionId")
@@ -2250,11 +2250,10 @@ public class NativeDynamoDbJsonHandler {
? KinesisStreamingDestination.PRECISION_MILLISECOND : precisionNode.asText();
if (!KinesisStreamingDestination.PRECISION_MILLISECOND.equals(precision)
&& !KinesisStreamingDestination.PRECISION_MICROSECOND.equals(precision)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + precision
+ throw SmithyValidationErrors.validationException(
+ "Value '" + precision
+ "' at 'enableKinesisStreamingConfiguration.approximateCreationDateTimePrecision' "
- + "failed to satisfy constraint: Member must satisfy enum value set: [MILLISECOND, MICROSECOND]",
- 400);
+ + "failed to satisfy constraint: Member must satisfy enum value set: [MILLISECOND, MICROSECOND]");
}
return Response.ok(kinesisDestinationResponse(
diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbTableService.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbTableService.java
index f743fe3541..fb287ece19 100644
--- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbTableService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbTableService.java
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.dynamodb;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.dynamodb.model.AttributeDefinition;
import io.github.hectorvent.floci.services.dynamodb.model.GlobalSecondaryIndex;
import io.github.hectorvent.floci.services.dynamodb.model.KeySchemaElement;
@@ -392,10 +393,10 @@ public class NativeDynamoDbTableService {
private static void validateSseType(String sseType) {
if (!VALID_SSE_TYPES.contains(sseType)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + sseType
+ throw SmithyValidationErrors.validationException(
+ "Value '" + sseType
+ "' at 'sSESpecification.sSEType' failed to satisfy constraint: "
- + "Member must satisfy enum value set: [AES256, KMS]", 400);
+ + "Member must satisfy enum value set: [AES256, KMS]");
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ecs/EcsJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/ecs/EcsJsonHandler.java
index 24d4d0615f..43290a28fd 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ecs/EcsJsonHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ecs/EcsJsonHandler.java
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.ecs.container.HostVolumePolicy;
import io.github.hectorvent.floci.services.ecs.model.Attribute;
import io.github.hectorvent.floci.services.ecs.model.AwsVpcConfiguration;
@@ -1460,18 +1461,16 @@ public class EcsJsonHandler {
return null;
}
if (!node.hasNonNull("type")) {
- throw new AwsException("ClientException",
- "1 validation error detected: Value null at 'containerDefinitions." + containerIndex
- + ".member.firelensConfiguration.type' failed to satisfy constraint: Member must not be null",
- 400);
+ throw SmithyValidationErrors.exception("ClientException",
+ "Value null at 'containerDefinitions." + containerIndex
+ + ".member.firelensConfiguration.type' failed to satisfy constraint: Member must not be null");
}
String type = node.path("type").asText();
if (!"fluentd".equals(type) && !"fluentbit".equals(type)) {
- throw new AwsException("ClientException",
- "1 validation error detected: Value '" + type + "' at 'containerDefinitions." + containerIndex
+ throw SmithyValidationErrors.exception("ClientException",
+ "Value '" + type + "' at 'containerDefinitions." + containerIndex
+ ".member.firelensConfiguration.type' failed to satisfy constraint: "
- + "Member must satisfy enum value set: [fluentd, fluentbit]",
- 400);
+ + "Member must satisfy enum value set: [fluentd, fluentbit]");
}
Map<String, String> options = null;
if (node.path("options").isObject()) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/emr/EmrService.java b/src/main/java/io/github/hectorvent/floci/services/emr/EmrService.java
index a678edf05e..3546596d79 100644
--- a/src/main/java/io/github/hectorvent/floci/services/emr/EmrService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/emr/EmrService.java
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.emr.model.EmrBlockPublicAccess;
@@ -73,9 +74,9 @@ public class EmrService {
// Only a missing Name fails AWS's framework validation: the member is REQUIRED but its
// constraint is len=[0..256], so an explicit empty string is accepted by real EMR.
if (cluster.getName() == null) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'name' failed to satisfy constraint: "
- + "Member must not be null", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'name' failed to satisfy constraint: "
+ + "Member must not be null");
}
String id = "j-" + randomId(13);
cluster.setId(id);
diff --git a/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java b/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java
index 2af732bee8..cf3c88bf6c 100644
--- a/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java
@@ -486,9 +486,9 @@ public class EventBridgeService implements ResourceProvider {
? "length greater than or equal to 1" : "length less than or equal to 1600";
}
if (field != null) {
- throw new AwsException("ValidationException", "1 validation error detected: Value '" + value
+ throw SmithyValidationErrors.validationException("Value '" + value
+ "' at 'targets." + (i + 1) + ".member." + field
- + "' failed to satisfy constraint: Member must have " + constraint, 400);
+ + "' failed to satisfy constraint: Member must have " + constraint);
}
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/DelegationRequestService.java b/src/main/java/io/github/hectorvent/floci/services/iam/DelegationRequestService.java
index e6f8ea3539..0bb26549b9 100644
--- a/src/main/java/io/github/hectorvent/floci/services/iam/DelegationRequestService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/iam/DelegationRequestService.java
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsRegionFacts;
import io.github.hectorvent.floci.core.common.AwsRegions;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.iam.model.DelegationPermission;
@@ -436,9 +437,9 @@ public class DelegationRequestService {
* them, which is why it appears in no operation's error table and in none of these.
*/
private static AwsException constraintViolation(String value, String member, String constraint) {
- return new AwsException("ValidationError", "1 validation error detected: Value "
+ return SmithyValidationErrors.validationError("Value "
+ (value == null ? "null" : "'" + value + "'") + " at '" + member
- + "' failed to satisfy constraint: " + constraint, 400);
+ + "' failed to satisfy constraint: " + constraint);
}
private static AwsException noSuchRequest(String id) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java
index 7d89f8cc9a..799a209a21 100644
--- a/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/iam/IamQueryHandler.java
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.iam;
import io.github.hectorvent.floci.core.common.*;
import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.iam.model.AccessKey;
import io.github.hectorvent.floci.services.iam.model.AccountPasswordPolicy;
import io.github.hectorvent.floci.services.iam.model.CallerContext;
@@ -967,10 +968,10 @@ public class IamQueryHandler {
try {
return Integer.valueOf(raw.trim());
} catch (NumberFormatException e) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value '" + raw + "' at '"
+ throw SmithyValidationErrors.validationError(
+ "Value '" + raw + "' at '"
+ Character.toLowerCase(name.charAt(0)) + name.substring(1)
- + "' failed to satisfy constraint: Member must be an integer", 400);
+ + "' failed to satisfy constraint: Member must be an integer");
}
}
@@ -3275,9 +3276,9 @@ public class IamQueryHandler {
*/
private static void checkListLength(int members, String param, int limit) {
if (members > limit) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value at '" + param + "' failed to satisfy constraint: "
- + "Member must have length less than or equal to " + limit, 400);
+ throw SmithyValidationErrors.validationError(
+ "Value at '" + param + "' failed to satisfy constraint: "
+ + "Member must have length less than or equal to " + limit);
}
}
@@ -3301,9 +3302,9 @@ public class IamQueryHandler {
* outside a range reports the side it fell outside, not the whole range.
*/
private static AwsException validationError(String value, String at, String constraint) {
- return new AwsException("ValidationError",
- "1 validation error detected: Value '" + value + "' at '" + at + "' failed to satisfy constraint: "
- + constraint, 400);
+ return SmithyValidationErrors.validationError(
+ "Value '" + value + "' at '" + at + "' failed to satisfy constraint: "
+ + constraint);
}
private List<String> getMemberList(MultivaluedMap<String, String> params, String name) {
@@ -3376,10 +3377,10 @@ public class IamQueryHandler {
private String requireParam(MultivaluedMap<String, String> params, String name) {
String value = params.getFirst(name);
if (value == null || value.isBlank()) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value null at '"
+ throw SmithyValidationErrors.validationError(
+ "Value null at '"
+ Character.toLowerCase(name.charAt(0)) + name.substring(1)
- + "' failed to satisfy constraint: Member must not be null", 400);
+ + "' failed to satisfy constraint: Member must not be null");
}
return value;
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/IamService.java b/src/main/java/io/github/hectorvent/floci/services/iam/IamService.java
index a8f31f906b..92c30a990f 100644
--- a/src/main/java/io/github/hectorvent/floci/services/iam/IamService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/iam/IamService.java
@@ -1205,8 +1205,8 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
return;
}
String value = roleName == null ? "null" : "'" + roleName + "'";
- throw new AwsException("ValidationError", "1 validation error detected: Value " + value
- + " at 'roleName' failed to satisfy constraint: " + constraint, 400);
+ throw SmithyValidationErrors.validationError("Value " + value
+ + " at 'roleName' failed to satisfy constraint: " + constraint);
}
/**
@@ -1609,10 +1609,10 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
&& !"All".equalsIgnoreCase(scope)
&& !"AWS".equalsIgnoreCase(scope)
&& !"Local".equalsIgnoreCase(scope)) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value '" + scope + "' at 'scope' failed to "
+ throw SmithyValidationErrors.validationError(
+ "Value '" + scope + "' at 'scope' failed to "
+ "satisfy constraint: Member must satisfy enum value set: "
- + "[All, AWS, Local]", 400);
+ + "[All, AWS, Local]");
}
String prefix = pathPrefix != null ? pathPrefix : "/";
boolean blankScope = scope == null || scope.isBlank();
@@ -2753,15 +2753,15 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
*/
private static void validatePassword(String password, String member) {
if (password == null) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value null at '" + member
- + "' failed to satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationError(
+ "Value null at '" + member
+ + "' failed to satisfy constraint: Member must not be null");
}
if (!LOGIN_PROFILE_PASSWORD_PATTERN.matcher(password).matches()) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value at '" + member
+ throw SmithyValidationErrors.validationError(
+ "Value at '" + member
+ "' failed to satisfy constraint: Member must have length less than "
- + "or equal to 128 and greater than or equal to 1", 400);
+ + "or equal to 128 and greater than or equal to 1");
}
}
@@ -2827,9 +2827,9 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
*/
public void putAccountProperties(Map<String, String> properties) {
if (properties == null || properties.isEmpty()) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value null at 'properties' failed to "
- + "satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationError(
+ "Value null at 'properties' failed to "
+ + "satisfy constraint: Member must not be null");
}
String namespace = null;
for (Map.Entry<String, String> entry : properties.entrySet()) {
@@ -2865,13 +2865,13 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
private String validateAccountPropertyKey(String key) {
if (key == null || key.isEmpty() || key.length() > MAX_ACCOUNT_PROPERTY_KEY_LENGTH
|| !ACCOUNT_PROPERTY_KEY_PATTERN.matcher(key).matches()) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value '" + key + "' at 'properties' failed "
+ throw SmithyValidationErrors.validationError(
+ "Value '" + key + "' at 'properties' failed "
+ "to satisfy constraint: Map keys "
+ "must satisfy constraint: [Member must have length less than or "
+ "equal to " + MAX_ACCOUNT_PROPERTY_KEY_LENGTH + ", Member must "
+ "satisfy regular expression pattern: "
- + ACCOUNT_PROPERTY_KEY_PATTERN.pattern() + "]", 400);
+ + ACCOUNT_PROPERTY_KEY_PATTERN.pattern() + "]");
}
int separator = key.indexOf('/');
if (separator <= 0 || separator != key.lastIndexOf('/') || separator == key.length() - 1) {
@@ -2886,10 +2886,10 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
private void validateAccountPropertyValue(String key, String value) {
if (value == null || value.isEmpty()
|| value.length() > MAX_ACCOUNT_PROPERTY_VALUE_LENGTH) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value at 'properties." + key + "' failed to "
+ throw SmithyValidationErrors.validationError(
+ "Value at 'properties." + key + "' failed to "
+ "satisfy constraint: Member must have length between 1 and "
- + MAX_ACCOUNT_PROPERTY_VALUE_LENGTH, 400);
+ + MAX_ACCOUNT_PROPERTY_VALUE_LENGTH);
}
}
@@ -2897,11 +2897,11 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
public void setSecurityTokenServicePreferences(String globalEndpointTokenVersion) {
if (globalEndpointTokenVersion == null
|| !GLOBAL_ENDPOINT_TOKEN_VERSIONS.contains(globalEndpointTokenVersion)) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value '" + globalEndpointTokenVersion
+ throw SmithyValidationErrors.validationError(
+ "Value '" + globalEndpointTokenVersion
+ "' at 'globalEndpointTokenVersion' failed to satisfy constraint: "
+ "Member must satisfy enum value set: ["
- + String.join(", ", GLOBAL_ENDPOINT_TOKEN_VERSIONS) + "]", 400);
+ + String.join(", ", GLOBAL_ENDPOINT_TOKEN_VERSIONS) + "]");
}
stsPreferences.put(STS_PREFERENCES_KEY, globalEndpointTokenVersion);
LOG.infov("Set the global endpoint token version to {0}", globalEndpointTokenVersion);
@@ -3026,9 +3026,9 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
// parsed, which is what makes a whitespace-only chain a malformed certificate rather
// than silently storing no chain at all.
if (certificateChain.isEmpty()) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value at 'CertificateChain' failed to satisfy "
- + "constraint: Member must have length greater than or equal to 1", 400);
+ throw SmithyValidationErrors.validationError(
+ "Value at 'CertificateChain' failed to satisfy "
+ + "constraint: Member must have length greater than or equal to 1");
}
parseUploadedChain(certificateChain);
}
@@ -3086,10 +3086,10 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
private void checkMaterialLength(String value, String paramName, int limit) {
if (value != null && value.length() > limit) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value at '" + paramName
+ throw SmithyValidationErrors.validationError(
+ "Value at '" + paramName
+ "' failed to satisfy constraint: Member must have length less than "
- + "or equal to " + limit, 400);
+ + "or equal to " + limit);
}
}
@@ -3295,9 +3295,9 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
*/
private void requireStatusFromEnum(String status) {
if (status == null || !CREDENTIAL_STATUSES.contains(status)) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value at 'status' failed to satisfy "
- + "constraint: Member must satisfy enum value set", 400);
+ throw SmithyValidationErrors.validationError(
+ "Value at 'status' failed to satisfy "
+ + "constraint: Member must satisfy enum value set");
}
}
@@ -3623,11 +3623,11 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
}
if (credentialAgeDays < MIN_CREDENTIAL_AGE_DAYS
|| credentialAgeDays > MAX_CREDENTIAL_AGE_DAYS) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value '" + credentialAgeDays
+ throw SmithyValidationErrors.validationError(
+ "Value '" + credentialAgeDays
+ "' at 'credentialAgeDays' failed to satisfy constraint: "
+ "Member must be between " + MIN_CREDENTIAL_AGE_DAYS + " and "
- + MAX_CREDENTIAL_AGE_DAYS, 400);
+ + MAX_CREDENTIAL_AGE_DAYS);
}
}
synchronized (serviceCredentialLock) {
@@ -3943,10 +3943,10 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
public List<VirtualMfaDevice> listVirtualMfaDevices(String assignmentStatus) {
String status = assignmentStatus == null || assignmentStatus.isBlank() ? "Any" : assignmentStatus;
if (!status.equals("Any") && !status.equals("Assigned") && !status.equals("Unassigned")) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value '" + assignmentStatus
+ throw SmithyValidationErrors.validationError(
+ "Value '" + assignmentStatus
+ "' at 'assignmentStatus' failed to satisfy constraint: "
- + "Member must satisfy enum value set: [Any, Unassigned, Assigned]", 400);
+ + "Member must satisfy enum value set: [Any, Unassigned, Assigned]");
}
return virtualMfaDevices.scan(k -> true).stream()
.filter(d -> switch (status) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/OrganizationsAccessReportService.java b/src/main/java/io/github/hectorvent/floci/services/iam/OrganizationsAccessReportService.java
index 52d34dbf24..72494e9dca 100644
--- a/src/main/java/io/github/hectorvent/floci/services/iam/OrganizationsAccessReportService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/iam/OrganizationsAccessReportService.java
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.iam;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.iam.model.OrganizationsAccessReportJob;
@@ -276,9 +277,9 @@ public class OrganizationsAccessReportService {
/** AWS's shape-violation message: an unquoted null, a quoted value, and what it failed. */
private static AwsException validationError(String value, String at, String constraint) {
- return new AwsException("ValidationError", "1 validation error detected: Value "
+ return SmithyValidationErrors.validationError("Value "
+ (value == null ? "null" : "'" + value + "'") + " at '" + at
- + "' failed to satisfy constraint: " + constraint, 400);
+ + "' failed to satisfy constraint: " + constraint);
}
private OrganizationsAccessReportJob completed(String callerAccountId, String entityPath,
diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/ServiceLastAccessedService.java b/src/main/java/io/github/hectorvent/floci/services/iam/ServiceLastAccessedService.java
index 35982118ad..a6f87f2704 100644
--- a/src/main/java/io/github/hectorvent/floci/services/iam/ServiceLastAccessedService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/iam/ServiceLastAccessedService.java
@@ -1,7 +1,7 @@
package io.github.hectorvent.floci.services.iam;
import com.fasterxml.jackson.core.type.TypeReference;
-import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.iam.model.ServiceLastAccessedEntity;
@@ -57,10 +57,10 @@ public class ServiceLastAccessedService {
List<String> serviceNamespaces,
List<ServiceLastAccessedEntity> entities) {
if (granularity != null && !GRANULARITIES.contains(granularity)) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value '" + granularity + "' at 'granularity' "
+ throw SmithyValidationErrors.validationError(
+ "Value '" + granularity + "' at 'granularity' "
+ "failed to satisfy constraint: Member must satisfy enum value set: "
- + "[SERVICE_LEVEL, ACTION_LEVEL]", 400);
+ + "[SERVICE_LEVEL, ACTION_LEVEL]");
}
Instant now = Instant.now();
// jobIDType is min 36 / max 36, which is exactly a UUID string.
diff --git a/src/main/java/io/github/hectorvent/floci/services/kms/KmsJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/kms/KmsJsonHandler.java
index 0249d0b46e..dec10a13da 100644
--- a/src/main/java/io/github/hectorvent/floci/services/kms/KmsJsonHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/kms/KmsJsonHandler.java
@@ -249,9 +249,9 @@ public class KmsJsonHandler {
String name = request.path("Name").isMissingNode() ? null : request.path("Name").asText(null);
JsonNode constraintsNode = request.path("Constraints");
if (!constraintsNode.isMissingNode() && !constraintsNode.isNull() && !constraintsNode.isObject()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at 'constraints' failed to satisfy constraint: "
- + "Member must be a structure", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at 'constraints' failed to satisfy constraint: "
+ + "Member must be a structure");
}
Map<String, Object> constraints = constraintsNode.isObject()
? objectMapper.convertValue(constraintsNode, Map.class)
@@ -674,11 +674,11 @@ public class KmsJsonHandler {
private static String readDataKeySpec(JsonNode request) {
String spec = request.path("KeySpec").asText(null);
if (spec != null && !"AES_256".equals(spec) && !"AES_128".equals(spec)) {
- throw new AwsException("ValidationException", "1 validation error detected: Value '" + spec
+ throw SmithyValidationErrors.validationException("Value '" + spec
+ "' at 'keySpec' failed to satisfy constraint: Member must satisfy enum value set: [RSA_2048, "
+ "RSA_3072, RSA_4096, ECC_NIST_P256, ECC_NIST_P384, ECC_NIST_P521, ECC_SECG_P256K1, "
+ "ECC_NIST_EDWARDS25519, SYMMETRIC_DEFAULT, HMAC_224, HMAC_256, HMAC_384, HMAC_512, SM2, "
- + "ML_DSA_44, ML_DSA_65, ML_DSA_87]", 400);
+ + "ML_DSA_44, ML_DSA_65, ML_DSA_87]");
}
return spec;
}
@@ -694,12 +694,12 @@ public class KmsJsonHandler {
private static void validateRange(String member, int value, int min, int max) {
if (value < min) {
- throw new AwsException("ValidationException", "1 validation error detected: Value '" + value + "' at '"
- + member + "' failed to satisfy constraint: Member must have value greater than or equal to " + min, 400);
+ throw SmithyValidationErrors.validationException("Value '" + value + "' at '"
+ + member + "' failed to satisfy constraint: Member must have value greater than or equal to " + min);
}
if (max < value) {
- throw new AwsException("ValidationException", "1 validation error detected: Value '" + value + "' at '"
- + member + "' failed to satisfy constraint: Member must have value less than or equal to " + max, 400);
+ throw SmithyValidationErrors.validationException("Value '" + value + "' at '"
+ + member + "' failed to satisfy constraint: Member must have value less than or equal to " + max);
}
}
@@ -707,8 +707,8 @@ public class KmsJsonHandler {
String name = Character.toLowerCase(member.charAt(0)) + member.substring(1);
JsonNode value = request.path(member);
if (value.isMissingNode() || value.isNull()) {
- throw new AwsException("ValidationException", "1 validation error detected: Value null at '" + name
- + "' failed to satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationException("Value null at '" + name
+ + "' failed to satisfy constraint: Member must not be null");
}
String keyId = value.asText();
String pattern = "Value '" + keyId + "' at '" + name
@@ -727,8 +727,8 @@ public class KmsJsonHandler {
String name = Character.toLowerCase(member.charAt(0)) + member.substring(1);
JsonNode value = request.path(member);
if (value.isMissingNode() || value.isNull()) {
- throw new AwsException("ValidationException", "1 validation error detected: Value " + (sensitive ? "" : "null ")
- + "at '" + name + "' failed to satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationException("Value " + (sensitive ? "" : "null ")
+ + "at '" + name + "' failed to satisfy constraint: Member must not be null");
}
byte[] blob = decodeBlob(request, member);
KmsService.validateBlobLength(name, blob, max);
diff --git a/src/main/java/io/github/hectorvent/floci/services/kms/KmsKeyImport.java b/src/main/java/io/github/hectorvent/floci/services/kms/KmsKeyImport.java
index ecd763a954..94aa9a33ee 100644
--- a/src/main/java/io/github/hectorvent/floci/services/kms/KmsKeyImport.java
+++ b/src/main/java/io/github/hectorvent/floci/services/kms/KmsKeyImport.java
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.kms;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.kms.model.KmsKeySpec;
import org.jboss.logging.Logger;
@@ -48,10 +49,10 @@ final class KmsKeyImport {
case "RSA_4096" -> 4096;
case "SM2" -> throw new AwsException("UnsupportedOperationException",
"WrappingKeySpec SM2 is not supported.", 400);
- default -> throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + wrappingKeySpec + "' at 'wrappingKeySpec' failed to "
+ default -> throw SmithyValidationErrors.validationException(
+ "Value '" + wrappingKeySpec + "' at 'wrappingKeySpec' failed to "
+ "satisfy constraint: Member must satisfy enum value set: "
- + "[RSA_2048, RSA_3072, RSA_4096, SM2]", 400);
+ + "[RSA_2048, RSA_3072, RSA_4096, SM2]");
};
try {
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
@@ -118,11 +119,11 @@ final class KmsKeyImport {
"AWS KMS stopped supporting the RSAES_PKCS1_V1_5 wrapping algorithm on October 10, 2023. "
+ "Use RSA_AES_KEY_WRAP_SHA_1, RSA_AES_KEY_WRAP_SHA_256, "
+ "RSAES_OAEP_SHA_1 or RSAES_OAEP_SHA_256.", 400);
- default -> throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + wrappingAlgorithm + "' at 'wrappingAlgorithm' failed "
+ default -> throw SmithyValidationErrors.validationException(
+ "Value '" + wrappingAlgorithm + "' at 'wrappingAlgorithm' failed "
+ "to satisfy constraint: Member must satisfy enum value set: "
+ "[RSAES_OAEP_SHA_256, RSAES_OAEP_SHA_1, RSA_AES_KEY_WRAP_SHA_256, "
- + "RSA_AES_KEY_WRAP_SHA_1, SM2PKE, RSAES_PKCS1_V1_5]", 400);
+ + "RSA_AES_KEY_WRAP_SHA_1, SM2PKE, RSAES_PKCS1_V1_5]");
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/kms/KmsService.java b/src/main/java/io/github/hectorvent/floci/services/kms/KmsService.java
index 094efb3d07..dab0b78f73 100644
--- a/src/main/java/io/github/hectorvent/floci/services/kms/KmsService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/kms/KmsService.java
@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.core.common.Base64Url;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.ReservedTags;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.resource.ExplorerResource;
import io.github.hectorvent.floci.core.resource.ResourceProvider;
import io.github.hectorvent.floci.core.resource.SupportedResourceType;
@@ -102,12 +103,12 @@ public class KmsService implements ResourceProvider {
public byte[] generateRandom(int numberOfBytes) {
if (numberOfBytes < 1) {
- throw new AwsException("ValidationException", "1 validation error detected: Value '" + numberOfBytes
- + "' at 'numberOfBytes' failed to satisfy constraint: Member must have value greater than or equal to 1", 400);
+ throw SmithyValidationErrors.validationException("Value '" + numberOfBytes
+ + "' at 'numberOfBytes' failed to satisfy constraint: Member must have value greater than or equal to 1");
}
if (1024 < numberOfBytes) {
- throw new AwsException("ValidationException", "1 validation error detected: Value '" + numberOfBytes
- + "' at 'numberOfBytes' failed to satisfy constraint: Member must have value less than or equal to 1024", 400);
+ throw SmithyValidationErrors.validationException("Value '" + numberOfBytes
+ + "' at 'numberOfBytes' failed to satisfy constraint: Member must have value less than or equal to 1024");
}
byte[] bytes = new byte[numberOfBytes];
secureRandom.nextBytes(bytes);
@@ -415,9 +416,9 @@ public class KmsService implements ResourceProvider {
}
for (String member : constraints.keySet()) {
if (!GRANT_CONSTRAINT_MEMBERS.contains(member)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Unknown parameter in 'constraints': \"" + member
- + "\", must be one of: " + String.join(", ", GRANT_CONSTRAINT_MEMBERS), 400);
+ throw SmithyValidationErrors.validationException(
+ "Unknown parameter in 'constraints': \"" + member
+ + "\", must be one of: " + String.join(", ", GRANT_CONSTRAINT_MEMBERS));
}
}
for (String encryptionContextMember : List.of("EncryptionContextSubset", "EncryptionContextEquals")) {
@@ -426,15 +427,15 @@ public class KmsService implements ResourceProvider {
continue;
}
if (!(value instanceof Map<?, ?> map)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at 'constraints." + encryptionContextMember
- + "' failed to satisfy constraint: Member must be a map of string to string", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at 'constraints." + encryptionContextMember
+ + "' failed to satisfy constraint: Member must be a map of string to string");
}
for (Map.Entry<?, ?> entry : map.entrySet()) {
if (!(entry.getKey() instanceof String) || !(entry.getValue() instanceof String)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at 'constraints." + encryptionContextMember
- + "' failed to satisfy constraint: Member must be a map of string to string", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at 'constraints." + encryptionContextMember
+ + "' failed to satisfy constraint: Member must be a map of string to string");
}
}
}
@@ -443,10 +444,10 @@ public class KmsService implements ResourceProvider {
if (!(sourceArn instanceof String sourceArnValue)
|| sourceArnValue.length() < 20 || sourceArnValue.length() > 512
|| !GRANT_CONSTRAINT_SOURCE_ARN_PATTERN.matcher(sourceArnValue).matches()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at 'constraints.sourceArn' failed to satisfy "
+ throw SmithyValidationErrors.validationException(
+ "Value at 'constraints.sourceArn' failed to satisfy "
+ "constraint: Member must satisfy regular expression pattern: "
- + "^arn:aws[a-z0-9-]*:[a-z0-9-]+:[a-z0-9-]*:[0-9]{12}:.+$", 400); // partition-literal: model pattern quoted in AWS's message
+ + "^arn:aws[a-z0-9-]*:[a-z0-9-]+:[a-z0-9-]*:[0-9]{12}:.+$"); // partition-literal: model pattern quoted in AWS's message
}
}
}
@@ -474,28 +475,28 @@ public class KmsService implements ResourceProvider {
}
for (String operation : operations) {
if (!GRANT_OPERATIONS.contains(operation)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + operation + "' at 'operations' failed to satisfy "
+ throw SmithyValidationErrors.validationException(
+ "Value '" + operation + "' at 'operations' failed to satisfy "
+ "constraint: Member must satisfy enum value set: ["
- + String.join(", ", GRANT_OPERATIONS) + "]", 400);
+ + String.join(", ", GRANT_OPERATIONS) + "]");
}
}
if (name != null) {
if (name.isEmpty()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + name + "' at 'name' failed to satisfy "
- + "constraint: Member must have length greater than or equal to 1", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + name + "' at 'name' failed to satisfy "
+ + "constraint: Member must have length greater than or equal to 1");
}
if (name.length() > 256) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + name + "' at 'name' failed to satisfy "
- + "constraint: Member must have length less than or equal to 256", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + name + "' at 'name' failed to satisfy "
+ + "constraint: Member must have length less than or equal to 256");
}
if (!GRANT_NAME_PATTERN.matcher(name).matches()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + name + "' at 'name' failed to satisfy "
+ throw SmithyValidationErrors.validationException(
+ "Value '" + name + "' at 'name' failed to satisfy "
+ "constraint: Member must satisfy regular expression pattern: "
- + "^[a-zA-Z0-9:/_-]+$", 400);
+ + "^[a-zA-Z0-9:/_-]+$");
}
}
validateGrantConstraints(constraints);
@@ -1057,10 +1058,10 @@ public class KmsService implements ResourceProvider {
+ "KEY_MATERIAL_DOES_NOT_EXPIRE.", 400);
}
}
- default -> throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + expirationModel + "' at 'expirationModel' failed to "
+ default -> throw SmithyValidationErrors.validationException(
+ "Value '" + expirationModel + "' at 'expirationModel' failed to "
+ "satisfy constraint: Member must satisfy enum value set: "
- + "[KEY_MATERIAL_EXPIRES, KEY_MATERIAL_DOES_NOT_EXPIRE]", 400);
+ + "[KEY_MATERIAL_EXPIRES, KEY_MATERIAL_DOES_NOT_EXPIRE]");
}
return effective;
}
@@ -1101,10 +1102,10 @@ public class KmsService implements ResourceProvider {
+ "existing key material to reimport.", 400);
}
}
- default -> throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + importType + "' at 'importType' failed to "
+ default -> throw SmithyValidationErrors.validationException(
+ "Value '" + importType + "' at 'importType' failed to "
+ "satisfy constraint: Member must satisfy enum value set: "
- + "[NEW_KEY_MATERIAL, EXISTING_KEY_MATERIAL]", 400);
+ + "[NEW_KEY_MATERIAL, EXISTING_KEY_MATERIAL]");
}
}
@@ -1139,10 +1140,10 @@ public class KmsService implements ResourceProvider {
case EXTERNAL_ORIGIN -> requireImportableSpec(spec);
case "AWS_CLOUDHSM", "EXTERNAL_KEY_STORE" -> throw new AwsException("UnsupportedOperationException",
"Origin " + effective + " is not supported.", 400);
- default -> throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + origin + "' at 'origin' failed to satisfy "
+ default -> throw SmithyValidationErrors.validationException(
+ "Value '" + origin + "' at 'origin' failed to satisfy "
+ "constraint: Member must satisfy enum value set: "
- + "[AWS_KMS, EXTERNAL, AWS_CLOUDHSM, EXTERNAL_KEY_STORE]", 400);
+ + "[AWS_KMS, EXTERNAL, AWS_CLOUDHSM, EXTERNAL_KEY_STORE]");
};
}
@@ -1838,10 +1839,10 @@ public class KmsService implements ResourceProvider {
case "RSAES_OAEP_SHA_256" -> KmsKeySpec.Algorithm.RSAES_OAEP_SHA_256;
case "SM2PKE" -> throw new AwsException("UnsupportedOperationException",
"SM2PKE is not supported.", 400);
- default -> throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + name + "' at 'encryptionAlgorithm' failed to satisfy "
+ default -> throw SmithyValidationErrors.validationException(
+ "Value '" + name + "' at 'encryptionAlgorithm' failed to satisfy "
+ "constraint: Member must satisfy enum value set: "
- + "[RSAES_OAEP_SHA_1, RSAES_OAEP_SHA_256, SM2PKE, SYMMETRIC_DEFAULT]", 400);
+ + "[RSAES_OAEP_SHA_1, RSAES_OAEP_SHA_256, SM2PKE, SYMMETRIC_DEFAULT]");
};
}
@@ -1863,12 +1864,12 @@ public class KmsService implements ResourceProvider {
static void validateBlobLength(String member, byte[] value, int max) {
int length = value == null ? 0 : value.length;
if (length < 1) {
- throw new AwsException("ValidationException", "1 validation error detected: Value at '" + member
- + "' failed to satisfy constraint: Member must have length greater than or equal to 1", 400);
+ throw SmithyValidationErrors.validationException("Value at '" + member
+ + "' failed to satisfy constraint: Member must have length greater than or equal to 1");
}
if (max < length) {
- throw new AwsException("ValidationException", "1 validation error detected: Value at '" + member
- + "' failed to satisfy constraint: Member must have length less than or equal to " + max, 400);
+ throw SmithyValidationErrors.validationException("Value at '" + member
+ + "' failed to satisfy constraint: Member must have length less than or equal to " + max);
}
}
@@ -1938,15 +1939,15 @@ public class KmsService implements ResourceProvider {
private static void validateEnumMember(String member, String value, List<String> allowed) {
if (value == null) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at '" + member + "' failed to satisfy "
- + "constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at '" + member + "' failed to satisfy "
+ + "constraint: Member must not be null");
}
if (!allowed.contains(value)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + value + "' at '" + member + "' failed to "
+ throw SmithyValidationErrors.validationException(
+ "Value '" + value + "' at '" + member + "' failed to "
+ "satisfy constraint: Member must satisfy enum value set: ["
- + String.join(", ", allowed) + "]", 400);
+ + String.join(", ", allowed) + "]");
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/kms/model/KmsKeySpec.java b/src/main/java/io/github/hectorvent/floci/services/kms/model/KmsKeySpec.java
index 0142cc898f..7f220f9b6c 100644
--- a/src/main/java/io/github/hectorvent/floci/services/kms/model/KmsKeySpec.java
+++ b/src/main/java/io/github/hectorvent/floci/services/kms/model/KmsKeySpec.java
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.kms.model;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.ArrayList;
@@ -64,8 +65,8 @@ public enum KmsKeySpec {
try {
return KmsKeySpec.valueOf(keySpec);
} catch (IllegalArgumentException _) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + keySpec + "' at 'KeySpec' failed to satisfy constraint", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + keySpec + "' at 'KeySpec' failed to satisfy constraint");
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/kms/model/KmsKeyUsage.java b/src/main/java/io/github/hectorvent/floci/services/kms/model/KmsKeyUsage.java
index 2c488fba61..eada4e8a87 100644
--- a/src/main/java/io/github/hectorvent/floci/services/kms/model/KmsKeyUsage.java
+++ b/src/main/java/io/github/hectorvent/floci/services/kms/model/KmsKeyUsage.java
@@ -1,6 +1,6 @@
package io.github.hectorvent.floci.services.kms.model;
-import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
@@ -14,8 +14,8 @@ public enum KmsKeyUsage {
try {
return KmsKeyUsage.valueOf(usage);
} catch (IllegalArgumentException _) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + usage + "' at 'KeyUsage' failed to satisfy constraint", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + usage + "' at 'KeyUsage' failed to satisfy constraint");
}
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/kms/model/KmsMessageType.java b/src/main/java/io/github/hectorvent/floci/services/kms/model/KmsMessageType.java
index dd4fda383d..00ab34b0fa 100644
--- a/src/main/java/io/github/hectorvent/floci/services/kms/model/KmsMessageType.java
+++ b/src/main/java/io/github/hectorvent/floci/services/kms/model/KmsMessageType.java
@@ -1,6 +1,6 @@
package io.github.hectorvent.floci.services.kms.model;
-import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
@@ -11,9 +11,9 @@ public enum KmsMessageType {
try {
return KmsMessageType.valueOf(messageType);
} catch (IllegalArgumentException _) {
- throw new AwsException("ValidationException", "1 validation error detected: Value '" + messageType
+ throw SmithyValidationErrors.validationException("Value '" + messageType
+ "' at 'messageType' failed to satisfy constraint: Member must satisfy enum value set: "
- + "[RAW, DIGEST, EXTERNAL_MU]", 400);
+ + "[RAW, DIGEST, EXTERNAL_MU]");
}
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtils.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtils.java
index 7fda84677e..7f5486cd94 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtils.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtils.java
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.lambda;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import java.util.regex.Pattern;
@@ -230,9 +231,9 @@ public final class LambdaArnUtils {
}
private static AwsException validationFailure(String value, String constraint) {
- return new AwsException("ValidationException",
- "1 validation error detected: Value '" + value + "' at 'functionName' failed to satisfy "
- + "constraint: " + constraint, 400);
+ return SmithyValidationErrors.validationException(
+ "Value '" + value + "' at 'functionName' failed to satisfy "
+ + "constraint: " + constraint);
}
/**
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningConfigFunctionsController.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningConfigFunctionsController.java
index 2140856640..64a04b2aac 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningConfigFunctionsController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningConfigFunctionsController.java
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.lambda.model.CodeSigningConfig;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
@@ -177,10 +178,10 @@ public class LambdaCodeSigningConfigFunctionsController {
if (arn == null || arn.isBlank()
|| arn.length() > ARN_MAX_LENGTH
|| !CODE_SIGNING_CONFIG_ARN.matcher(arn).matches()) {
- throw new AwsException("InvalidParameterValueException",
- "1 validation error detected: Value '" + arn + "' at 'codeSigningConfigArn' "
+ throw SmithyValidationErrors.exception("InvalidParameterValueException",
+ "Value '" + arn + "' at 'codeSigningConfigArn' "
+ "failed to satisfy constraint: Member must satisfy regular expression pattern: "
- + CODE_SIGNING_CONFIG_ARN.pattern(), 400);
+ + CODE_SIGNING_CONFIG_ARN.pattern());
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaLayerService.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaLayerService.java
index 7301c03514..a44d305588 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaLayerService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaLayerService.java
@@ -447,16 +447,16 @@ public class LambdaLayerService {
*/
public LambdaLayerVersion getLayerVersionByArn(String layerVersionArn) {
if (layerVersionArn == null || layerVersionArn.isEmpty()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'arn' failed to satisfy constraint: "
- + "Member must not be null", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'arn' failed to satisfy constraint: "
+ + "Member must not be null");
}
if (layerVersionArn.length() > MAX_LAYER_VERSION_ARN_LENGTH
|| !LAYER_VERSION_ARN.matcher(layerVersionArn).matches()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + layerVersionArn + "' at 'arn' failed to satisfy"
+ throw SmithyValidationErrors.validationException(
+ "Value '" + layerVersionArn + "' at 'arn' failed to satisfy"
+ " constraint: Member must satisfy regular expression pattern: "
- + LAYER_VERSION_ARN_PATTERN, 400);
+ + LAYER_VERSION_ARN_PATTERN);
}
// The live service rejects a layer from another partition outright, and with a different
// error than an unresolvable ARN, so this precedes the lookup.
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java
index 57a1d6064e..7baea04307 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java
@@ -14,6 +14,7 @@ import io.github.hectorvent.floci.core.common.CustomResourceLiveness;
import io.github.hectorvent.floci.core.common.Digests;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.RequestScopes;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.resource.ExplorerResource;
import io.github.hectorvent.floci.core.resource.ResourceProvider;
import io.github.hectorvent.floci.core.resource.SupportedResourceType;
@@ -1056,10 +1057,10 @@ public class LambdaService implements ResourceProvider {
*/
private void deleteFunctionVersion(String region, String functionName, String qualifier) {
if (!QUALIFIER.matcher(qualifier).matches()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + qualifier + "' at 'qualifier' failed"
+ throw SmithyValidationErrors.validationException(
+ "Value '" + qualifier + "' at 'qualifier' failed"
+ " to satisfy constraint: Member must satisfy regular expression"
- + " pattern: " + QUALIFIER_PATTERN, 400);
+ + " pattern: " + QUALIFIER_PATTERN);
}
LambdaFunction fn = getFunction(region, functionName);
if ("$LATEST".equals(qualifier)) {
@@ -1620,19 +1621,17 @@ public class LambdaService implements ResourceProvider {
"FunctionResponseTypes must be a JSON array or null", 400);
}
if (types.size() > 1) {
- throw new AwsException("InvalidParameterValueException",
- "1 validation error detected: Value '" + types + "' at 'functionResponseTypes' "
- + "failed to satisfy constraint: Member must have length less than or equal to 1",
- 400);
+ throw SmithyValidationErrors.exception("InvalidParameterValueException",
+ "Value '" + types + "' at 'functionResponseTypes' "
+ + "failed to satisfy constraint: Member must have length less than or equal to 1");
}
List<String> validated = new ArrayList<>();
for (Object type : types) {
if (!FUNCTION_RESPONSE_TYPES.contains(type)) {
- throw new AwsException("InvalidParameterValueException",
- "1 validation error detected: Value '" + types + "' at 'functionResponseTypes' "
+ throw SmithyValidationErrors.exception("InvalidParameterValueException",
+ "Value '" + types + "' at 'functionResponseTypes' "
+ "failed to satisfy constraint: Member must satisfy constraint: "
- + "[Member must satisfy enum value set: " + FUNCTION_RESPONSE_TYPES + "]",
- 400);
+ + "[Member must satisfy enum value set: " + FUNCTION_RESPONSE_TYPES + "]");
}
validated.add((String) type);
}
@@ -2511,32 +2510,28 @@ public class LambdaService implements ResourceProvider {
return null;
}
if (!(value instanceof List<?> architectures)) {
- throw new AwsException("InvalidParameterValueException",
- "1 validation error detected: Value '" + value + "' at 'architectures' "
- + "failed to satisfy constraint: Member must be a list",
- 400);
+ throw SmithyValidationErrors.exception("InvalidParameterValueException",
+ "Value '" + value + "' at 'architectures' "
+ + "failed to satisfy constraint: Member must be a list");
}
if (architectures.isEmpty()) {
- throw new AwsException("InvalidParameterValueException",
- "1 validation error detected: Value '[]' at 'architectures' "
- + "failed to satisfy constraint: Member must have length greater than or equal to 1",
- 400);
+ throw SmithyValidationErrors.exception("InvalidParameterValueException",
+ "Value '[]' at 'architectures' "
+ + "failed to satisfy constraint: Member must have length greater than or equal to 1");
}
if (architectures.size() > 1) {
- throw new AwsException("InvalidParameterValueException",
- "1 validation error detected: Value '" + architectures + "' at 'architectures' "
- + "failed to satisfy constraint: Member must have length less than or equal to 1",
- 400);
+ throw SmithyValidationErrors.exception("InvalidParameterValueException",
+ "Value '" + architectures + "' at 'architectures' "
+ + "failed to satisfy constraint: Member must have length less than or equal to 1");
}
Object architecture = architectures.getFirst();
if (!FUNCTION_ARCHITECTURES.contains(architecture)) {
- throw new AwsException("InvalidParameterValueException",
- "1 validation error detected: Value '" + architecture
+ throw SmithyValidationErrors.exception("InvalidParameterValueException",
+ "Value '" + architecture
+ "' at 'architectures.1.member' "
+ "failed to satisfy constraint: Member must satisfy enum value set: "
- + FUNCTION_ARCHITECTURES,
- 400);
+ + FUNCTION_ARCHITECTURES);
}
return List.of((String) architecture);
}
@@ -2636,10 +2631,10 @@ public class LambdaService implements ResourceProvider {
}
Object applyOn = snapStart.get("ApplyOn");
if (applyOn != null && !"None".equals(applyOn) && !"PublishedVersions".equals(applyOn)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + applyOn + "' at 'snapStart.applyOn' failed to "
+ throw SmithyValidationErrors.validationException(
+ "Value '" + applyOn + "' at 'snapStart.applyOn' failed to "
+ "satisfy constraint: Member must satisfy enum value set: "
- + "[PublishedVersions, None]", 400);
+ + "[PublishedVersions, None]");
}
}
@@ -2683,9 +2678,9 @@ public class LambdaService implements ResourceProvider {
if (number < 1 || number > maximum) {
String field = "durableConfig." + Character.toLowerCase(member.charAt(0)) + member.substring(1);
String bound = number < 1 ? "greater than or equal to 1" : "less than or equal to " + maximum;
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + number + "' at '" + field + "' failed to satisfy "
- + "constraint: Member must have value " + bound, 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + number + "' at '" + field + "' failed to satisfy "
+ + "constraint: Member must have value " + bound);
}
return (int) number;
}
@@ -2748,10 +2743,10 @@ public class LambdaService implements ResourceProvider {
if (value == null || allowed.contains(value)) {
return;
}
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + value + "' at '" + field + "' failed to satisfy "
+ throw SmithyValidationErrors.validationException(
+ "Value '" + value + "' at '" + field + "' failed to satisfy "
+ "constraint: Member must satisfy enum value set: ["
- + String.join(", ", allowed) + "]", 400);
+ + String.join(", ", allowed) + "]");
}
/**
@@ -2782,9 +2777,9 @@ public class LambdaService implements ResourceProvider {
return;
}
if (!pattern.matcher(s).matches()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + s + "' at '" + field + "' failed to satisfy "
- + "constraint: Member must satisfy regular expression pattern: " + pattern.pattern(), 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + s + "' at '" + field + "' failed to satisfy "
+ + "constraint: Member must satisfy regular expression pattern: " + pattern.pattern());
}
}
@@ -2802,10 +2797,9 @@ public class LambdaService implements ResourceProvider {
/** Enforces a shape's 1-character minimum: an empty string is rejected, and null too when the member is required. */
private static void validateNonEmpty(String value, String field, boolean required) {
if ((value == null && required) || (value != null && value.isEmpty())) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + (value == null ? "" : value) + "' at '" + field
- + "' failed to satisfy constraint: Member must have length greater than or equal to 1",
- 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + (value == null ? "" : value) + "' at '" + field
+ + "' failed to satisfy constraint: Member must have length greater than or equal to 1");
}
}
@@ -2825,9 +2819,9 @@ public class LambdaService implements ResourceProvider {
private static void validateS3CodeLocation(String bucket, String key) {
if (bucket != null) {
if (bucket.length() < 3) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + bucket + "' at 's3Bucket' failed to satisfy constraint: "
- + "Member must have length greater than or equal to 3", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + bucket + "' at 's3Bucket' failed to satisfy constraint: "
+ + "Member must have length greater than or equal to 3");
}
validateMaxLength(bucket, "s3Bucket", 63);
validatePattern(bucket, "s3Bucket", S3_BUCKET_PATTERN);
@@ -2847,9 +2841,9 @@ public class LambdaService implements ResourceProvider {
private static void validateMaxItems(List<?> list, String field, int maxItems) {
if (list.size() > maxItems) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at '" + field + "' failed to satisfy constraint: "
- + "Member must have length less than or equal to " + maxItems, 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at '" + field + "' failed to satisfy constraint: "
+ + "Member must have length less than or equal to " + maxItems);
}
}
@@ -2857,9 +2851,9 @@ public class LambdaService implements ResourceProvider {
if (!(value instanceof String s) || s.length() <= maxLength) {
return;
}
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at '" + field + "' failed to satisfy constraint: "
- + "Member must have length less than or equal to " + maxLength, 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at '" + field + "' failed to satisfy constraint: "
+ + "Member must have length less than or equal to " + maxLength);
}
/**
@@ -2881,10 +2875,10 @@ public class LambdaService implements ResourceProvider {
return;
}
if (group.length() > 512 || !LOG_GROUP_PATTERN.matcher(group).matches()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + group + "' at 'loggingConfig.logGroup' failed to "
+ throw SmithyValidationErrors.validationException(
+ "Value '" + group + "' at 'loggingConfig.logGroup' failed to "
+ "satisfy constraint: Member must satisfy regular expression pattern: "
- + "[.\\-_/#A-Za-z0-9]+ or member must have length less than or equal to 512", 400);
+ + "[.\\-_/#A-Za-z0-9]+ or member must have length less than or equal to 512");
}
}
@@ -2894,10 +2888,10 @@ public class LambdaService implements ResourceProvider {
*/
private static void validateRoleArn(String role) {
if (role == null || !ROLE_ARN_PATTERN.matcher(role).matches()) {
- throw new AwsException("InvalidParameterValueException",
- "1 validation error detected: Value '" + role + "' at 'role' failed to satisfy "
+ throw SmithyValidationErrors.exception("InvalidParameterValueException",
+ "Value '" + role + "' at 'role' failed to satisfy "
+ "constraint: Member must satisfy regular expression pattern: "
- + ROLE_ARN_PATTERN.pattern(), 400);
+ + ROLE_ARN_PATTERN.pattern());
}
}
@@ -2909,19 +2903,19 @@ public class LambdaService implements ResourceProvider {
*/
private static void validateHandler(String handler) {
if (handler == null) {
- throw new AwsException("InvalidParameterValueException",
- "1 validation error detected: Value 'null' at 'handler' failed to satisfy "
- + "constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.exception("InvalidParameterValueException",
+ "Value 'null' at 'handler' failed to satisfy "
+ + "constraint: Member must not be null");
}
if (handler.isEmpty()) {
return;
}
if (handler.length() > MAX_HANDLER_LENGTH || !HANDLER_PATTERN.matcher(handler).matches()) {
- throw new AwsException("InvalidParameterValueException",
- "1 validation error detected: Value '" + handler + "' at 'handler' failed to satisfy "
+ throw SmithyValidationErrors.exception("InvalidParameterValueException",
+ "Value '" + handler + "' at 'handler' failed to satisfy "
+ "constraint: Member must satisfy regular expression pattern: "
+ HANDLER_PATTERN.pattern() + " or member must have length less than or equal to "
- + MAX_HANDLER_LENGTH, 400);
+ + MAX_HANDLER_LENGTH);
}
}
@@ -3904,11 +3898,11 @@ public class LambdaService implements ResourceProvider {
for (String key : tags.keySet()) {
if (key.isEmpty() || key.codePointCount(0, key.length()) > MAX_TAG_KEY_LENGTH
|| !TAG_KEY_PATTERN.matcher(key).matches()) {
- throw new AwsException("ValidationException", "1 validation error detected: Value '" + tags
+ 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() + "]", 400);
+ + TAG_KEY_PATTERN.pattern() + "]");
}
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableExecutionController.java b/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableExecutionController.java
index 29ac1b37c2..0b21d58169 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableExecutionController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableExecutionController.java
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.lambda.LambdaArnUtils;
import io.github.hectorvent.floci.services.lambda.LambdaService;
import io.github.hectorvent.floci.services.lambda.durable.model.DurableErrorObject;
@@ -186,9 +187,8 @@ public class DurableExecutionController {
public Response callbackSucceed(@Context HttpHeaders headers, @PathParam("callbackId") String callbackId,
byte[] body) {
if (body != null && MAX_CALLBACK_PAYLOAD_BYTES < body.length) {
- throw new AwsException("ValidationException", "1 validation error detected: Value at 'result' failed to "
- + "satisfy constraint: Member must have length less than or equal to " + MAX_CALLBACK_PAYLOAD_BYTES,
- 400);
+ throw SmithyValidationErrors.validationException("Value at 'result' failed to "
+ + "satisfy constraint: Member must have length less than or equal to " + MAX_CALLBACK_PAYLOAD_BYTES);
}
String result = body == null || body.length == 0 ? null : new String(body, StandardCharsets.UTF_8);
service.completeCallback(callbackId, regionResolver.getAccountId(), regionResolver.resolveRegion(headers), true,
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableExecutionService.java b/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableExecutionService.java
index 342ebe59e9..eb45cdda8e 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableExecutionService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableExecutionService.java
@@ -1064,10 +1064,10 @@ public class DurableExecutionService implements Resettable {
static ArnParts parseArn(String executionArn) {
Matcher matcher = executionArn == null ? null : LambdaArnUtils.DURABLE_EXECUTION_ARN.matcher(executionArn);
if (matcher == null || !matcher.matches()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + executionArn + "' at 'durableExecutionArn' failed to "
+ throw SmithyValidationErrors.validationException(
+ "Value '" + executionArn + "' at 'durableExecutionArn' failed to "
+ "satisfy constraint: Member must satisfy regular expression pattern: "
- + LambdaArnUtils.DURABLE_EXECUTION_ARN.pattern(), 400);
+ + LambdaArnUtils.DURABLE_EXECUTION_ARN.pattern());
}
return new ArnParts(executionArn, matcher.group(3), matcher.group(2), matcher.group(4), matcher.group(5),
matcher.group(6), matcher.group(7));
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableWire.java b/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableWire.java
index 66722a0b5b..fce0d83b93 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableWire.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableWire.java
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.lambda.durable.model.DurableErrorObject;
import io.github.hectorvent.floci.services.lambda.durable.model.DurableExecution;
import io.github.hectorvent.floci.services.lambda.durable.model.DurableHistoryEvent;
@@ -333,8 +334,8 @@ public final class DurableWire {
long seconds = number.longValue();
if (seconds < min || max < seconds) {
String bound = seconds < min ? "greater than or equal to " + min : "less than or equal to " + max;
- throw new AwsException("ValidationException", "1 validation error detected: Value '" + seconds
- + "' at '" + field + "' failed to satisfy constraint: Member must have value " + bound, 400);
+ throw SmithyValidationErrors.validationException("Value '" + seconds
+ + "' at '" + field + "' failed to satisfy constraint: Member must have value " + bound);
}
return (int) seconds;
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/pricing/PricingService.java b/src/main/java/io/github/hectorvent/floci/services/pricing/PricingService.java
index 47805b6f5d..74bb8b1f52 100644
--- a/src/main/java/io/github/hectorvent/floci/services/pricing/PricingService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/pricing/PricingService.java
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.Base64Url;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
@@ -212,8 +213,8 @@ public class PricingService {
requireNonEmpty(currencyCode, "CurrencyCode");
requireSafePathSegment(serviceCode, "ServiceCode");
if (effectiveDate == null) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at 'EffectiveDate' failed to satisfy constraint: Member must not be null.", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at 'EffectiveDate' failed to satisfy constraint: Member must not be null.");
}
if (!servicesByCode.containsKey(serviceCode)) {
@@ -385,8 +386,8 @@ public class PricingService {
private static void requireNonEmpty(String value, String field) {
if (value == null || value.isEmpty()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at '" + field + "' failed to satisfy constraint: Member must not be null.", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at '" + field + "' failed to satisfy constraint: Member must not be null.");
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/scheduler/SchedulerService.java b/src/main/java/io/github/hectorvent/floci/services/scheduler/SchedulerService.java
index cdcc0a9c9b..c77560163a 100644
--- a/src/main/java/io/github/hectorvent/floci/services/scheduler/SchedulerService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/scheduler/SchedulerService.java
@@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.ObjectReader;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
@@ -349,13 +350,13 @@ public class SchedulerService {
private void validateScheduleRequest(ScheduleRequest req) {
if (req.getScheduleExpression() == null || req.getScheduleExpression().isBlank()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'scheduleExpression' failed to satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'scheduleExpression' failed to satisfy constraint: Member must not be null");
}
if (req.getScheduleExpression().length() > 256) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + req.getScheduleExpression()
- + "' at 'scheduleExpression' failed to satisfy constraint: Member must have length less than or equal to 256", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + req.getScheduleExpression()
+ + "' at 'scheduleExpression' failed to satisfy constraint: Member must have length less than or equal to 256");
}
try {
SchedulerExpressionParser.validate(req.getScheduleExpression(), req.getScheduleExpressionTimezone());
@@ -364,62 +365,62 @@ public class SchedulerService {
"Invalid ScheduleExpression: " + e.getMessage(), 400);
}
if (req.getFlexibleTimeWindow() == null) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'flexibleTimeWindow' failed to satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'flexibleTimeWindow' failed to satisfy constraint: Member must not be null");
}
String flexibleTimeWindowMode = req.getFlexibleTimeWindow().getMode();
if (flexibleTimeWindowMode == null || flexibleTimeWindowMode.isBlank()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'flexibleTimeWindow.mode' failed to satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'flexibleTimeWindow.mode' failed to satisfy constraint: Member must not be null");
}
flexibleTimeWindowMode = flexibleTimeWindowMode.trim();
if (!"OFF".equals(flexibleTimeWindowMode) && !"FLEXIBLE".equals(flexibleTimeWindowMode)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + flexibleTimeWindowMode + "' at 'flexibleTimeWindow.mode' failed to satisfy constraint: Member must satisfy enum value set: [OFF, FLEXIBLE]", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + flexibleTimeWindowMode + "' at 'flexibleTimeWindow.mode' failed to satisfy constraint: Member must satisfy enum value set: [OFF, FLEXIBLE]");
}
if ("FLEXIBLE".equals(flexibleTimeWindowMode)
&& req.getFlexibleTimeWindow().getMaximumWindowInMinutes() == null) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'flexibleTimeWindow.maximumWindowInMinutes' failed to satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'flexibleTimeWindow.maximumWindowInMinutes' failed to satisfy constraint: Member must not be null");
}
if ("OFF".equals(flexibleTimeWindowMode)
&& req.getFlexibleTimeWindow().getMaximumWindowInMinutes() != null) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at 'flexibleTimeWindow.maximumWindowInMinutes' failed to satisfy constraint: Member must be null when flexibleTimeWindow.mode is OFF", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at 'flexibleTimeWindow.maximumWindowInMinutes' failed to satisfy constraint: Member must be null when flexibleTimeWindow.mode is OFF");
}
if (req.getTarget() == null) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'target' failed to satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'target' failed to satisfy constraint: Member must not be null");
}
if (req.getTarget().getArn() == null || req.getTarget().getArn().isBlank()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'target.arn' failed to satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'target.arn' failed to satisfy constraint: Member must not be null");
}
if (req.getTarget().getRoleArn() == null || req.getTarget().getRoleArn().isBlank()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'target.roleArn' failed to satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'target.roleArn' failed to satisfy constraint: Member must not be null");
}
if (req.getTarget().getRoleArn().length() > 1600) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + req.getTarget().getRoleArn()
- + "' at 'target.roleArn' failed to satisfy constraint: Member must have length less than or equal to 1600", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + req.getTarget().getRoleArn()
+ + "' at 'target.roleArn' failed to satisfy constraint: Member must have length less than or equal to 1600");
}
if (!ROLE_ARN_PATTERN.matcher(req.getTarget().getRoleArn()).matches()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + req.getTarget().getRoleArn()
+ throw SmithyValidationErrors.validationException(
+ "Value '" + req.getTarget().getRoleArn()
+ "' at 'target.roleArn' failed to satisfy constraint: Member must satisfy regular expression pattern: "
- + ROLE_ARN_MODEL_PATTERN, 400);
+ + ROLE_ARN_MODEL_PATTERN);
}
if (req.getTarget().getDeadLetterConfig() != null
&& (req.getTarget().getDeadLetterConfig().getArn() == null
|| req.getTarget().getDeadLetterConfig().getArn().isBlank())) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'target.deadLetterConfig.arn' failed to satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'target.deadLetterConfig.arn' failed to satisfy constraint: Member must not be null");
}
String input = req.getTarget().getInput();
if (input != null && requiresJsonInput(req.getTarget().getArn()) && !isWellFormedJson(input)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at 'target.input' failed to satisfy constraint: Member must be well-formed JSON for Lambda, Step Functions, and EventBridge targets", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at 'target.input' failed to satisfy constraint: Member must be well-formed JSON for Lambda, Step Functions, and EventBridge targets");
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ssm/SsmCommandService.java b/src/main/java/io/github/hectorvent/floci/services/ssm/SsmCommandService.java
index 5f5e65fcd2..da8bbc6b45 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ssm/SsmCommandService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ssm/SsmCommandService.java
@@ -9,6 +9,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.RequestScopes;
import io.github.hectorvent.floci.core.common.Resettable;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.ssm.model.Command;
@@ -156,10 +157,8 @@ public class SsmCommandService implements Resettable {
throw new AwsException("InvalidInstanceId", "At least one InstanceId is required.", 400);
}
if (instanceIds.size() > MAX_INSTANCE_IDS) {
- throw new AwsException(
- "ValidationException",
- "1 validation error detected: Value at 'instanceIds' failed to satisfy constraint: Member must have length less than or equal to " + MAX_INSTANCE_IDS,
- 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at 'instanceIds' failed to satisfy constraint: Member must have length less than or equal to " + MAX_INSTANCE_IDS);
}
boolean publicShell = "AWS-RunShellScript".equals(documentName);
@@ -294,10 +293,8 @@ public class SsmCommandService implements Resettable {
private static void validateTimeoutSeconds(int timeoutSeconds) {
if (timeoutSeconds < MIN_TIMEOUT_SECONDS) {
- throw new AwsException(
- "ValidationException",
- "1 validation error detected: Value '" + timeoutSeconds + "' at 'timeoutSeconds' failed to satisfy constraint: Member must have value greater than or equal to 30",
- 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + timeoutSeconds + "' at 'timeoutSeconds' failed to satisfy constraint: Member must have value greater than or equal to 30");
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ssm/SsmJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/ssm/SsmJsonHandler.java
index c90660fa04..356b6ed911 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ssm/SsmJsonHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ssm/SsmJsonHandler.java
@@ -11,6 +11,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.IamEnforcementFilter;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.ssm.model.Command;
import io.github.hectorvent.floci.services.ssm.model.CommandInvocation;
import io.github.hectorvent.floci.services.ssm.model.InstanceInformation;
@@ -315,10 +316,10 @@ public class SsmJsonHandler {
Integer maxResults = request.hasNonNull("MaxResults") ? request.path("MaxResults").asInt() : null;
if (maxResults != null && (maxResults < 1 || maxResults > DESCRIBE_PARAMETERS_MAX_RESULTS)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + maxResults + "' at 'maxResults' failed to "
+ throw SmithyValidationErrors.validationException(
+ "Value '" + maxResults + "' at 'maxResults' failed to "
+ "satisfy constraint: Member must have value between 1 and "
- + DESCRIBE_PARAMETERS_MAX_RESULTS, 400);
+ + DESCRIBE_PARAMETERS_MAX_RESULTS);
}
PaginatedResult<Parameter> page = Pagination.paginate(
ssmService.describeParameters(filters, region), Parameter::getName,
@@ -450,10 +451,9 @@ public class SsmJsonHandler {
JsonNode nameNode = request.path("Name");
String name = nameNode.asText();
if (!nameNode.isTextual() || !pattern.matcher(name).matches()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + name + "' at 'name' failed to satisfy constraint: "
- + "Member must satisfy regular expression pattern: " + pattern.pattern(),
- 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + name + "' at 'name' failed to satisfy constraint: "
+ + "Member must satisfy regular expression pattern: " + pattern.pattern());
}
return name;
}
@@ -468,10 +468,9 @@ public class SsmJsonHandler {
private void requireSharePermissionType(JsonNode request) {
String permissionType = request.path("PermissionType").asText();
if (permissionType == null || permissionType.isBlank()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'permissionType' failed to satisfy "
- + "constraint: Member must not be null",
- 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'permissionType' failed to satisfy "
+ + "constraint: Member must not be null");
}
if (!"Share".equals(permissionType)) {
throw new AwsException("InvalidPermissionType",
@@ -506,10 +505,9 @@ public class SsmJsonHandler {
private String requireDocumentType(JsonNode request) {
String documentType = request.path("DocumentType").asText("Command");
if (!DOCUMENT_TYPES.contains(documentType)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + documentType + "' at 'documentType' failed to "
- + "satisfy constraint: Member must satisfy enum value set: " + DOCUMENT_TYPES,
- 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + documentType + "' at 'documentType' failed to "
+ + "satisfy constraint: Member must satisfy enum value set: " + DOCUMENT_TYPES);
}
return documentType;
}
@@ -522,26 +520,23 @@ public class SsmJsonHandler {
private List<String> accountIds(JsonNode request, String field) {
JsonNode fieldNode = request.path(field);
if (!fieldNode.isMissingNode() && !fieldNode.isNull() && !fieldNode.isArray()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at '" + decapitalize(field) + "' failed to satisfy "
- + "constraint: Member must be a list",
- 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at '" + decapitalize(field) + "' failed to satisfy "
+ + "constraint: Member must be a list");
}
List<String> accountIds = new ArrayList<>();
fieldNode.forEach(node -> accountIds.add(node.asText()));
if (accountIds.size() > MAX_ACCOUNT_IDS) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at '" + decapitalize(field) + "' failed to satisfy "
- + "constraint: Member must have length less than or equal to " + MAX_ACCOUNT_IDS,
- 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at '" + decapitalize(field) + "' failed to satisfy "
+ + "constraint: Member must have length less than or equal to " + MAX_ACCOUNT_IDS);
}
for (String accountId : accountIds) {
if (!ACCOUNT_ID.matcher(accountId).matches()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + accountId + "' at '" + decapitalize(field)
+ throw SmithyValidationErrors.validationException(
+ "Value '" + accountId + "' at '" + decapitalize(field)
+ "' failed to satisfy constraint: Member must satisfy regular expression "
- + "pattern: (?i)all|[0-9]{12}",
- 400);
+ + "pattern: (?i)all|[0-9]{12}");
}
}
return accountIds;
@@ -598,10 +593,9 @@ public class SsmJsonHandler {
private String requireDocumentContent(JsonNode request) {
JsonNode contentNode = request.path("Content");
if (!contentNode.isTextual() || contentNode.asText().isBlank()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'content' failed to satisfy "
- + "constraint: Member must not be null",
- 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'content' failed to satisfy "
+ + "constraint: Member must not be null");
}
return contentNode.asText();
}
@@ -633,11 +627,10 @@ public class SsmJsonHandler {
List<String> accountIdsToAdd = accountIds(request, "AccountIdsToAdd");
List<String> accountIdsToRemove = accountIds(request, "AccountIdsToRemove");
if (accountIdsToAdd.isEmpty() && accountIdsToRemove.isEmpty()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'accountIdsToAdd' failed to satisfy "
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'accountIdsToAdd' failed to satisfy "
+ "constraint: Member must not be null, or a value must be specified for "
- + "'accountIdsToRemove'",
- 400);
+ + "'accountIdsToRemove'");
}
ssmService.modifyDocumentPermission(name, accountIdsToAdd, accountIdsToRemove, region);
@@ -767,9 +760,8 @@ public class SsmJsonHandler {
private Response handleCreateAssociation(JsonNode request, String region) {
JsonNode nameNode = request.path("Name");
if (!nameNode.isTextual() || nameNode.asText().isBlank()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'name' failed to satisfy constraint: Member must not be null",
- 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'name' failed to satisfy constraint: Member must not be null");
}
String name = nameNode.asText();
@@ -801,9 +793,8 @@ public class SsmJsonHandler {
private Response handleUpdateAssociation(JsonNode request, String region) {
String associationId = request.hasNonNull("AssociationId") ? request.path("AssociationId").asText() : null;
if (associationId == null || associationId.isBlank()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'associationId' failed to satisfy constraint: Member must not be null",
- 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'associationId' failed to satisfy constraint: Member must not be null");
}
String associationName = request.hasNonNull("AssociationName") ? request.path("AssociationName").asText() : null;
@@ -1209,10 +1200,9 @@ public class SsmJsonHandler {
private String requireSettingId(JsonNode request) {
String settingId = request.path("SettingId").asText();
if (settingId == null || settingId.isBlank()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'settingId' failed to satisfy "
- + "constraint: Member must not be null",
- 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'settingId' failed to satisfy "
+ + "constraint: Member must not be null");
}
return settingId;
}
@@ -1229,17 +1219,15 @@ public class SsmJsonHandler {
JsonNode valueNode = request.path("SettingValue");
String settingValue = valueNode.asText();
if (!valueNode.isTextual() || settingValue.isEmpty()) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value null at 'settingValue' failed to satisfy "
- + "constraint: Member must not be null",
- 400);
+ throw SmithyValidationErrors.validationException(
+ "Value null at 'settingValue' failed to satisfy "
+ + "constraint: Member must not be null");
}
if (settingValue.length() > MAX_SETTING_VALUE_LENGTH) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at 'settingValue' failed to satisfy "
+ throw SmithyValidationErrors.validationException(
+ "Value at 'settingValue' failed to satisfy "
+ "constraint: Member must have length less than or equal to "
- + MAX_SETTING_VALUE_LENGTH,
- 400);
+ + MAX_SETTING_VALUE_LENGTH);
}
return settingValue;
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ssm/SsmService.java b/src/main/java/io/github/hectorvent/floci/services/ssm/SsmService.java
index 34c53fcc80..a9fa650b5c 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ssm/SsmService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ssm/SsmService.java
@@ -208,9 +208,9 @@ public class SsmService implements ResourceProvider {
// Validation reads only the request, so it runs before the lock: an AllowedPattern match can take up
// to ALLOWED_PATTERN_TIMEOUT_NANOS and must not stall other SSM writers.
if (tier != null && !PARAMETER_TIERS.contains(tier)) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value '" + tier + "' at 'tier' failed to satisfy constraint: "
- + "Member must satisfy enum value set: [Standard, Advanced, Intelligent-Tiering]", 400);
+ throw SmithyValidationErrors.validationException(
+ "Value '" + tier + "' at 'tier' failed to satisfy constraint: "
+ + "Member must satisfy enum value set: [Standard, Advanced, Intelligent-Tiering]");
}
validateTagKeys(tags);
rejectReservedName(name);
@@ -229,9 +229,9 @@ public class SsmService implements ResourceProvider {
}
if (allowedPattern != null) {
if (allowedPattern.length() > MAX_ALLOWED_PATTERN_LENGTH) {
- throw new AwsException("ValidationException",
- "1 validation error detected: Value at 'allowedPattern' failed to satisfy constraint: "
- + "Member must have length less than or equal to " + MAX_ALLOWED_PATTERN_LENGTH, 400);
+ throw SmithyValidationErrors.validationException(
+ "Value at 'allowedPattern' failed to satisfy constraint: "
+ + "Member must have length less than or equal to " + MAX_ALLOWED_PATTERN_LENGTH);
}
Pattern pattern;
try {
@@ -933,8 +933,8 @@ public class SsmService implements ResourceProvider {
} else {
continue;
}
- throw new AwsException("ValidationException", "1 validation error detected: Value at 'tags."
- + position + ".member.key' failed to satisfy constraint: " + constraint, 400);
+ throw SmithyValidationErrors.validationException("Value at 'tags."
+ + position + ".member.key' failed to satisfy constraint: " + constraint);
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/transcribe/TranscribeService.java b/src/main/java/io/github/hectorvent/floci/services/transcribe/TranscribeService.java
index 215f321729..5a70e68b84 100644
--- a/src/main/java/io/github/hectorvent/floci/services/transcribe/TranscribeService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/transcribe/TranscribeService.java
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.Resettable;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.transcribe.model.TranscriptionJob;
@@ -255,10 +256,9 @@ public class TranscribeService implements Resettable {
private void requireNonBlank(String value, String fieldName) {
if (value == null || value.isBlank()) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value null at '" + fieldName
- + "' failed to satisfy constraint: Member must not be null",
- 400);
+ throw SmithyValidationErrors.badRequest(
+ "Value null at '" + fieldName
+ + "' failed to satisfy constraint: Member must not be null");
}
}