mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(dynamodb): enforce DeletionProtectionEnabled on create, update, and delete (#583)
This commit is contained in:
1 parent
eed72e6222
commit
2d1fe19d88
3 files changed
+99
-1
No files matched your search
+14
-1
@@ -139,9 +139,13 @@ public class DynamoDbJsonHandler {
|
||||
String billingMode = request.has("BillingMode")
|
||||
? request.get("BillingMode").asText() : null;
|
||||
|
||||
boolean deletionProtection = request.path("DeletionProtectionEnabled").asBoolean(false);
|
||||
|
||||
TableDefinition table = dynamoDbService.createTable(tableName, keySchema, attrDefs,
|
||||
readCapacity, writeCapacity, gsis, lsis, region);
|
||||
|
||||
table.setDeletionProtectionEnabled(deletionProtection);
|
||||
|
||||
if ("PAY_PER_REQUEST".equals(billingMode)) {
|
||||
table.setBillingMode("PAY_PER_REQUEST");
|
||||
table.getProvisionedThroughput().setReadCapacityUnits(0L);
|
||||
@@ -176,6 +180,10 @@ public class DynamoDbJsonHandler {
|
||||
private Response handleDeleteTable(JsonNode request, String region) {
|
||||
String tableName = request.path("TableName").asText();
|
||||
TableDefinition table = dynamoDbService.describeTable(tableName, region);
|
||||
if (table.isDeletionProtectionEnabled()) {
|
||||
throw new AwsException("ResourceInUseException",
|
||||
"Table " + tableName + " can't be deleted while DeletionProtectionEnabled is set to true", 400);
|
||||
}
|
||||
dynamoDbService.deleteTable(tableName, region);
|
||||
|
||||
table.setTableStatus("DELETING");
|
||||
@@ -507,6 +515,11 @@ public class DynamoDbJsonHandler {
|
||||
TableDefinition table = dynamoDbService.updateTable(tableName, readCapacity, writeCapacity,
|
||||
gsiCreates, gsiDeletes, newAttrDefs, region);
|
||||
|
||||
JsonNode deletionProtectionNode = request.path("DeletionProtectionEnabled");
|
||||
if (!deletionProtectionNode.isMissingNode()) {
|
||||
table.setDeletionProtectionEnabled(deletionProtectionNode.asBoolean());
|
||||
}
|
||||
|
||||
String billingMode = request.has("BillingMode")
|
||||
? request.get("BillingMode").asText() : null;
|
||||
if (billingMode != null) {
|
||||
@@ -851,7 +864,7 @@ public class DynamoDbJsonHandler {
|
||||
node.put("CreationDateTime", table.getCreationDateTime().getEpochSecond());
|
||||
node.put("ItemCount", table.getItemCount());
|
||||
node.put("TableSizeBytes", table.getTableSizeBytes());
|
||||
node.put("DeletionProtectionEnabled", false);
|
||||
node.put("DeletionProtectionEnabled", table.isDeletionProtectionEnabled());
|
||||
|
||||
if ("PAY_PER_REQUEST".equals(table.getBillingMode())) {
|
||||
ObjectNode billing = objectMapper.createObjectNode();
|
||||
|
||||
@@ -34,6 +34,7 @@ public class TableDefinition {
|
||||
private boolean ttlEnabled;
|
||||
private boolean pointInTimeRecoveryEnabled;
|
||||
private int pointInTimeRecoveryRecoveryPeriodInDays;
|
||||
private boolean deletionProtectionEnabled;
|
||||
private boolean streamEnabled;
|
||||
private String streamArn;
|
||||
private String streamViewType;
|
||||
@@ -134,6 +135,9 @@ public class TableDefinition {
|
||||
this.pointInTimeRecoveryRecoveryPeriodInDays = pointInTimeRecoveryRecoveryPeriodInDays;
|
||||
}
|
||||
|
||||
public boolean isDeletionProtectionEnabled() { return deletionProtectionEnabled; }
|
||||
public void setDeletionProtectionEnabled(boolean deletionProtectionEnabled) { this.deletionProtectionEnabled = deletionProtectionEnabled; }
|
||||
|
||||
public boolean isStreamEnabled() { return streamEnabled; }
|
||||
public void setStreamEnabled(boolean streamEnabled) { this.streamEnabled = streamEnabled; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user