mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(dynamodb): enforce primary key size limits (#3354)
* fix(dynamodb): enforce primary key size limits * test(dynamodb): align key size test name with service convention
This commit is contained in:
1 parent
c5e1a7f7ac
commit
8624ccce83
4 files changed
+230
-1
No files matched your search
@@ -38,7 +38,7 @@ final class DynamoDbItemSize {
|
||||
return total;
|
||||
}
|
||||
|
||||
private static int attributeValueSize(JsonNode attr) {
|
||||
static int attributeValueSize(JsonNode attr) {
|
||||
if (attr == null) return 0;
|
||||
if (attr.has("S")) return utf8Length(attr.get("S").asText());
|
||||
if (attr.has("N")) return attr.get("N").asText().length();
|
||||
|
||||
@@ -3059,6 +3059,7 @@ public class DynamoDbService implements ResourceProvider {
|
||||
throw missingKeyException(surface);
|
||||
}
|
||||
validateKeyAttributeValue(table, pkAttr, pkName, surface);
|
||||
validateKeySize(pkAttr, true);
|
||||
|
||||
String pk = extractScalarValue(pkAttr);
|
||||
String skName = table.getSortKeyName();
|
||||
@@ -3068,11 +3069,22 @@ public class DynamoDbService implements ResourceProvider {
|
||||
throw missingKeyException(surface);
|
||||
}
|
||||
validateKeyAttributeValue(table, skAttr, skName, surface);
|
||||
validateKeySize(skAttr, false);
|
||||
return pk + "#" + extractScalarValue(skAttr);
|
||||
}
|
||||
return pk;
|
||||
}
|
||||
|
||||
private void validateKeySize(JsonNode attr, boolean partitionKey) {
|
||||
int limit = partitionKey ? 2048 : 1024;
|
||||
if ((attr.has("S") || attr.has("B")) && DynamoDbItemSize.attributeValueSize(attr) > limit) {
|
||||
throw new AwsException("ValidationException",
|
||||
"One or more parameter values were invalid: Size of "
|
||||
+ (partitionKey ? "hashkey" : "rangekey")
|
||||
+ " has exceeded the maximum size limit of " + limit + " bytes", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private AwsException missingKeyException(KeySurface surface) {
|
||||
if (surface == KeySurface.ITEM_BODY) {
|
||||
return new AwsException("ValidationException",
|
||||
|
||||
Reference in new issue
Block a user