From f1294ff5efa6db4944db5bbdb13fddc437b94882 Mon Sep 17 00:00:00 2001 From: "Peter J. Radics" Date: Wed, 13 Mar 2024 12:59:27 -0400 Subject: [PATCH 1/3] Fixed validation of read and write capacities --- src/main/java/gyro/aws/dynamodb/DynamoDbTableResource.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/gyro/aws/dynamodb/DynamoDbTableResource.java b/src/main/java/gyro/aws/dynamodb/DynamoDbTableResource.java index 68633b7be..aa93bc7d1 100644 --- a/src/main/java/gyro/aws/dynamodb/DynamoDbTableResource.java +++ b/src/main/java/gyro/aws/dynamodb/DynamoDbTableResource.java @@ -591,14 +591,14 @@ public void delete(GyroUI ui, State state) throws Exception { public List validate(Set configuredFields) { List errors = new ArrayList<>(); - if ("PROVISIONED".equals(getBillingMode()) && (getReadCapacity() == null || getWriteCapacity() == null)) { + if ("PROVISIONED".equals(getBillingMode()) && (getReadCapacity() == null || getWriteCapacity() == null || getReadCapacity() <= 0L || getWriteCapacity() <= 0L)) { errors.add(new ValidationError( this, null, "'read-capacity' and 'write-capacity' must both be provided when 'billing-mode' is set to 'PROVISIONED'!")); } - if ("PAY_PER_REQUEST".equals(getBillingMode()) && (getReadCapacity() != null || getWriteCapacity() != null)) { + if ("PAY_PER_REQUEST".equals(getBillingMode()) && ((getReadCapacity() != null && getReadCapacity() > 0) || (getWriteCapacity() != null && getWriteCapacity() > 0))) { errors.add(new ValidationError( this, null, From a7414301b5b97a4c4761e5f70fbf366daa69432e Mon Sep 17 00:00:00 2001 From: "Peter J. Radics" Date: Wed, 13 Mar 2024 15:40:09 -0400 Subject: [PATCH 2/3] Fixed validation of read & write capacities for GlobalSecondaryIndexes --- .../java/gyro/aws/dynamodb/DynamoDbGlobalSecondaryIndex.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/gyro/aws/dynamodb/DynamoDbGlobalSecondaryIndex.java b/src/main/java/gyro/aws/dynamodb/DynamoDbGlobalSecondaryIndex.java index dadf0670d..d78e3946c 100644 --- a/src/main/java/gyro/aws/dynamodb/DynamoDbGlobalSecondaryIndex.java +++ b/src/main/java/gyro/aws/dynamodb/DynamoDbGlobalSecondaryIndex.java @@ -227,15 +227,14 @@ public List validate(Set configuredFields) { } if ("PROVISIONED".equals(parentTable.getBillingMode()) && (getReadCapacity() == null - || getWriteCapacity() == null)) { + || getWriteCapacity() == null || getReadCapacity() <= 0L || getWriteCapacity() <= 0L)) { errors.add(new ValidationError( this, null, "'read-capacity' and 'write-capacity' must both be provided when the table 'billing-mode' is set to 'PROVISIONED'!")); } - if ("PAY_PER_REQUEST".equals(parentTable.getBillingMode()) && (getReadCapacity() != null - || getWriteCapacity() != null)) { + if ("PAY_PER_REQUEST".equals(parentTable.getBillingMode()) && ((getReadCapacity() != null && getReadCapacity() > 0) || (getWriteCapacity() != null && getWriteCapacity() > 0))) { errors.add(new ValidationError( this, null, From d0d5b5c68a0bfacda14f1203d226d93918627e63 Mon Sep 17 00:00:00 2001 From: "Peter J. Radics" Date: Wed, 13 Mar 2024 15:54:46 -0400 Subject: [PATCH 3/3] Added Min(1) to getters instead of explicitly validating --- .../java/gyro/aws/dynamodb/DynamoDbGlobalSecondaryIndex.java | 5 ++++- src/main/java/gyro/aws/dynamodb/DynamoDbTableResource.java | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/gyro/aws/dynamodb/DynamoDbGlobalSecondaryIndex.java b/src/main/java/gyro/aws/dynamodb/DynamoDbGlobalSecondaryIndex.java index d78e3946c..2a8362683 100644 --- a/src/main/java/gyro/aws/dynamodb/DynamoDbGlobalSecondaryIndex.java +++ b/src/main/java/gyro/aws/dynamodb/DynamoDbGlobalSecondaryIndex.java @@ -24,6 +24,7 @@ import gyro.aws.Copyable; import gyro.core.resource.Diffable; import gyro.core.resource.Updatable; +import gyro.core.validation.Min; import gyro.core.validation.Required; import gyro.core.validation.ValidStrings; import gyro.core.validation.ValidationError; @@ -84,6 +85,7 @@ public void setRangeKey(String rangeKey) { * The maximum number of writes per second for this table before an exception is thrown. Required if ``billing-mode`` is set to ``PROVISIONED``. */ @Updatable + @Min(1) public Long getWriteCapacity() { return writeCapacity; } @@ -96,6 +98,7 @@ public void setWriteCapacity(Long writeCapacity) { * The maximum number of reads per second for this table before an exception is thrown. Required if ``billing-mode`` is set to ``PROVISIONED``. */ @Updatable + @Min(1) public Long getReadCapacity() { return readCapacity; } @@ -227,7 +230,7 @@ public List validate(Set configuredFields) { } if ("PROVISIONED".equals(parentTable.getBillingMode()) && (getReadCapacity() == null - || getWriteCapacity() == null || getReadCapacity() <= 0L || getWriteCapacity() <= 0L)) { + || getWriteCapacity() == null)) { errors.add(new ValidationError( this, null, diff --git a/src/main/java/gyro/aws/dynamodb/DynamoDbTableResource.java b/src/main/java/gyro/aws/dynamodb/DynamoDbTableResource.java index aa93bc7d1..d1d8d8e4a 100644 --- a/src/main/java/gyro/aws/dynamodb/DynamoDbTableResource.java +++ b/src/main/java/gyro/aws/dynamodb/DynamoDbTableResource.java @@ -42,6 +42,7 @@ import gyro.core.resource.Resource; import gyro.core.resource.Updatable; import gyro.core.scope.State; +import gyro.core.validation.Min; import gyro.core.validation.Regex; import gyro.core.validation.Required; import gyro.core.validation.ValidStrings; @@ -253,6 +254,7 @@ public void setLocalSecondaryIndex(Set localSeconda * The maximum number of writes per second for this table before an exception is thrown. Required if ``billing-mode`` is set to ``PROVISIONED``. */ @Updatable + @Min(1) public Long getWriteCapacity() { return writeCapacity; } @@ -265,6 +267,7 @@ public void setWriteCapacity(Long writeCapacity) { * The maximum number of reads per second for this table before an exception is thrown. Required if ``billing-mode`` is set to ``PROVISIONED``. */ @Updatable + @Min(1) public Long getReadCapacity() { return readCapacity; } @@ -591,7 +594,7 @@ public void delete(GyroUI ui, State state) throws Exception { public List validate(Set configuredFields) { List errors = new ArrayList<>(); - if ("PROVISIONED".equals(getBillingMode()) && (getReadCapacity() == null || getWriteCapacity() == null || getReadCapacity() <= 0L || getWriteCapacity() <= 0L)) { + if ("PROVISIONED".equals(getBillingMode()) && (getReadCapacity() == null || getWriteCapacity() == null)) { errors.add(new ValidationError( this, null,