diff --git a/.github/workflows/partition-literals.yml b/.github/workflows/partition-literals.yml index 366d40ee21..20402a3462 100644 --- a/.github/workflows/partition-literals.yml +++ b/.github/workflows/partition-literals.yml @@ -6,8 +6,8 @@ name: Partition Literals # partition regexes in src/main/java against the checked-in per-file baseline: a # literal in a new file fails, growth in an existing file fails, and a drop fails until # the baseline is regenerated so the remaining count stays exact. The second job checks -# that the vendored partition data (src/main/resources/aws/partitions.json) still matches -# what tools/aws/regen_partitions.py produces from the pinned botocore release. Python-only, +# that the vendored AWS data (src/main/resources/aws/*.json) still matches what tools/aws/ +# produces from the pinned botocore release. Python-only, # so both are fast and independent of the Java build job. on: diff --git a/Makefile b/Makefile index c03dee2005..acb82aa1f7 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,8 @@ # # AWS partition data: src/main/resources/aws/partitions.json is generated from botocore's # published partition metadata (plus two CDK region rules) by tools/aws/regen_partitions.py. +# src/main/resources/aws/dynamodb-request-shapes.json is generated from botocore's DynamoDB +# model by tools/aws/regen_dynamodb_shapes.py. PYTHON ?= python3 @@ -175,8 +177,9 @@ partition-test: ## Run the partition tooling's unit tests aws-data-sync: ## Regenerate src/main/resources/aws/*.json from botocore, the CDK and Terraform (commit the result) $(PYTHON) tools/aws/regen_partitions.py $(PYTHON) tools/aws/regen_region_facts.py + $(PYTHON) tools/aws/regen_dynamodb_shapes.py -aws-data-check: ## CI gate: the vendored partition data must match a fresh generation +aws-data-check: ## CI gate: the vendored AWS data must match a fresh generation @$(PYTHON) tools/aws/regen_partitions.py --check || { \ echo ""; \ echo "error: src/main/resources/aws/partitions.json is out of date."; \ @@ -189,8 +192,14 @@ aws-data-check: ## CI gate: the vendored partition data must match a fresh gener echo " Run 'make aws-data-sync' with local/aws checked out and commit the result."; \ exit 1; \ } + @$(PYTHON) tools/aws/regen_dynamodb_shapes.py --check || { \ + echo ""; \ + echo "error: src/main/resources/aws/dynamodb-request-shapes.json is out of date."; \ + echo " Run 'make aws-data-sync' and commit the result."; \ + exit 1; \ + } -aws-data-test: ## Run the partition-data generator's unit tests +aws-data-test: ## Run the AWS data generators' unit tests $(PYTHON) -m pytest tools/aws -q iam-namespaces-sync: ## Regenerate src/main/resources/aws/iam-service-namespaces.json from AWS (commit the result) diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsJsonController.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsJsonController.java index 005c60c101..b9a7242393 100644 --- a/src/main/java/io/github/hectorvent/floci/core/common/AwsJsonController.java +++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsJsonController.java @@ -9,6 +9,7 @@ import io.github.hectorvent.floci.services.cloudcontrol.CloudControlJsonHandler; import io.github.hectorvent.floci.services.bcmpricingcalculator.BcmPricingCalculatorJsonHandler; import io.github.hectorvent.floci.services.cloudwatch.metrics.CloudWatchMetricsJsonHandler; import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler; +import io.github.hectorvent.floci.services.dynamodb.DynamoDbRequestShapes; import io.github.hectorvent.floci.services.dynamodb.DynamoDbResponses; import io.github.hectorvent.floci.services.dynamodb.DynamoDbStreamsJsonHandler; import io.github.hectorvent.floci.services.networkfirewall.NetworkFirewallJsonHandler; @@ -137,6 +138,7 @@ public class AwsJsonController { if (targetMatch.prefix().startsWith("DynamoDBStreams_")) { yield dynamoDbStreamsJsonHandler.handle(action, request, region); } + DynamoDbRequestShapes.check(action, request); yield dynamoDbJsonHandler.handle(action, request, region); } case "sqs" -> sqsJsonHandler.handle(action, request, region); diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbRequestShapes.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbRequestShapes.java new file mode 100644 index 0000000000..1159a2c6df --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbRequestShapes.java @@ -0,0 +1,198 @@ +package io.github.hectorvent.floci.services.dynamodb; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.github.hectorvent.floci.core.common.AwsException; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Rejects a DynamoDB request member of the wrong JSON type with the SerializationException + * DynamoDB answers before it runs the operation. The input shapes come from the vendored + * {@code aws/dynamodb-request-shapes.json}, generated from botocore's DynamoDB model by + * {@code tools/aws/regen_dynamodb_shapes.py}. + * + *

AWS reads the body in order and reports the first bad member, without naming it. A JSON + * null counts as an absent member, and a member the model does not know is ignored. + */ +public final class DynamoDbRequestShapes { + + static final String RESOURCE_NAME = "aws/dynamodb-request-shapes.json"; + + private static final ObjectMapper MAPPER = new ObjectMapper(); + + private static final String OBJECT_NOT_EXPECTED = "Start of structure or map found where not expected"; + private static final String UNKNOWN_ERROR = "UnknownError"; + private static final String UNEXPECTED_FIELD_TYPE = "Unexpected field type"; + private static final String UNEXPECTED_VALUE_TYPE = "Unexpected value type in payload"; + + record Shape(String type, Map members, String element) { + } + + record Model(Map operations, Map shapes) { + } + + private static final class Holder { + static final Model MODEL = load(); + } + + private DynamoDbRequestShapes() { + } + + /** Checks a DynamoDB request body against the input shape of {@code action}, if the model has one. */ + public static void check(String action, JsonNode request) { + check(Holder.MODEL, action, request); + } + + static void check(Model model, String action, JsonNode request) { + String input = model.operations().get(action); + if (input != null) { + checkValue(model, model.shapes().get(input), request, true); + } + } + + private static void checkValue(Model model, Shape shape, JsonNode value, boolean member) { + if (value.isNull()) { + return; + } + switch (shape.type()) { + case "structure" -> checkStructure(model, shape, value, member); + case "list" -> checkList(model, shape, value, member); + case "map" -> checkMap(model, shape, value, member); + default -> checkScalar(shape.type(), value); + } + } + + private static void checkStructure(Model model, Shape shape, JsonNode value, boolean member) { + if (value.isArray()) { + throw serialization(UNKNOWN_ERROR); + } + if (!value.isObject()) { + throw serialization(member ? UNEXPECTED_FIELD_TYPE : UNEXPECTED_VALUE_TYPE); + } + Iterator> fields = value.fields(); + while (fields.hasNext()) { + Map.Entry field = fields.next(); + String memberShape = shape.members().get(field.getKey()); + if (memberShape != null) { + checkValue(model, model.shapes().get(memberShape), field.getValue(), true); + } + } + } + + private static void checkList(Model model, Shape shape, JsonNode value, boolean member) { + if (value.isObject()) { + throw serialization(OBJECT_NOT_EXPECTED); + } + if (!value.isArray()) { + throw serialization(member ? UNEXPECTED_FIELD_TYPE : UNKNOWN_ERROR); + } + Shape element = model.shapes().get(shape.element()); + for (JsonNode item : value) { + checkValue(model, element, item, false); + } + } + + private static void checkMap(Model model, Shape shape, JsonNode value, boolean member) { + if (value.isArray()) { + throw serialization(UNKNOWN_ERROR); + } + if (!value.isObject()) { + throw serialization(member ? UNEXPECTED_FIELD_TYPE : UNKNOWN_ERROR); + } + Shape element = model.shapes().get(shape.element()); + for (JsonNode item : value) { + checkValue(model, element, item, false); + } + } + + private static void checkScalar(String type, JsonNode value) { + if (value.isObject()) { + throw serialization(OBJECT_NOT_EXPECTED); + } + if (value.isArray()) { + throw serialization(UNKNOWN_ERROR); + } + switch (type) { + case "string" -> requireToken(value.isTextual(), value, "String"); + case "integer" -> requireToken(value.isNumber(), value, "Integer"); + case "long" -> requireToken(value.isNumber(), value, "Long"); + case "double" -> requireToken(value.isNumber(), value, "Double"); + case "timestamp" -> requireToken(value.isNumber(), value, "Date"); + case "boolean" -> checkBoolean(value); + case "blob" -> { + if (!value.isTextual() && !value.isBinary()) { + throw serialization("only base-64-encoded strings are convertible to bytes"); + } + } + default -> { + } + } + } + + private static void checkBoolean(JsonNode value) { + if (value.isTextual()) { + String text = value.asText(); + if (!"true".equalsIgnoreCase(text) && !"false".equalsIgnoreCase(text)) { + throw serialization("Unexpected token received from parser"); + } + return; + } + requireToken(value.isBoolean(), value, "Boolean"); + } + + private static void requireToken(boolean accepted, JsonNode value, String target) { + if (!accepted) { + throw serialization(token(value) + " cannot be converted to " + target); + } + } + + private static String token(JsonNode value) { + if (value.isIntegralNumber()) { + return "NUMBER_VALUE"; + } + if (value.isNumber()) { + return "DECIMAL_VALUE"; + } + if (value.isBoolean()) { + return value.booleanValue() ? "TRUE_VALUE" : "FALSE_VALUE"; + } + return "STRING_VALUE"; + } + + private static AwsException serialization(String message) { + return new AwsException("SerializationException", message, 400); + } + + private static Model load() { + try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(RESOURCE_NAME)) { + if (in == null) { + throw new IllegalStateException("DynamoDB request shape resource not found: " + RESOURCE_NAME); + } + return parse(MAPPER.readTree(in)); + } catch (IOException e) { + throw new IllegalStateException("Failed to read the DynamoDB request shapes " + RESOURCE_NAME, e); + } + } + + static Model parse(JsonNode root) { + Map operations = new HashMap<>(); + root.path("operations").fields().forEachRemaining(op -> operations.put(op.getKey(), op.getValue().asText())); + Map shapes = new HashMap<>(); + Iterator> entries = root.path("shapes").fields(); + while (entries.hasNext()) { + Map.Entry entry = entries.next(); + JsonNode node = entry.getValue(); + Map members = new LinkedHashMap<>(); + node.path("members").fields().forEachRemaining(m -> members.put(m.getKey(), m.getValue().asText())); + String element = node.hasNonNull("member") ? node.get("member").asText() : node.path("value").asText(null); + shapes.put(entry.getKey(), new Shape(node.path("type").asText(), members, element)); + } + return new Model(operations, shapes); + } +} diff --git a/src/main/resources/aws/dynamodb-request-shapes.json b/src/main/resources/aws/dynamodb-request-shapes.json new file mode 100644 index 0000000000..08ab80996c --- /dev/null +++ b/src/main/resources/aws/dynamodb-request-shapes.json @@ -0,0 +1,1663 @@ +{ + "_source": { + "generator": "tools/aws/regen_dynamodb_shapes.py", + "botocore": "botocore 1.43.98 (installed package)" + }, + "operations": { + "BatchExecuteStatement": "BatchExecuteStatementInput", + "BatchGetItem": "BatchGetItemInput", + "BatchWriteItem": "BatchWriteItemInput", + "CreateBackup": "CreateBackupInput", + "CreateGlobalTable": "CreateGlobalTableInput", + "CreateTable": "CreateTableInput", + "DeleteBackup": "DeleteBackupInput", + "DeleteItem": "DeleteItemInput", + "DeleteResourcePolicy": "DeleteResourcePolicyInput", + "DeleteTable": "DeleteTableInput", + "DescribeBackup": "DescribeBackupInput", + "DescribeContinuousBackups": "DescribeContinuousBackupsInput", + "DescribeContributorInsights": "DescribeContributorInsightsInput", + "DescribeEndpoints": "DescribeEndpointsRequest", + "DescribeExport": "DescribeExportInput", + "DescribeGlobalTable": "DescribeGlobalTableInput", + "DescribeGlobalTableSettings": "DescribeGlobalTableSettingsInput", + "DescribeImport": "DescribeImportInput", + "DescribeKinesisStreamingDestination": "DescribeKinesisStreamingDestinationInput", + "DescribeLimits": "DescribeLimitsInput", + "DescribeTable": "DescribeTableInput", + "DescribeTableReplicaAutoScaling": "DescribeTableReplicaAutoScalingInput", + "DescribeTimeToLive": "DescribeTimeToLiveInput", + "DisableKinesisStreamingDestination": "KinesisStreamingDestinationInput", + "EnableKinesisStreamingDestination": "KinesisStreamingDestinationInput", + "ExecuteStatement": "ExecuteStatementInput", + "ExecuteTransaction": "ExecuteTransactionInput", + "ExportTableToPointInTime": "ExportTableToPointInTimeInput", + "GetItem": "GetItemInput", + "GetResourcePolicy": "GetResourcePolicyInput", + "ImportTable": "ImportTableInput", + "ListBackups": "ListBackupsInput", + "ListContributorInsights": "ListContributorInsightsInput", + "ListExports": "ListExportsInput", + "ListGlobalTables": "ListGlobalTablesInput", + "ListImports": "ListImportsInput", + "ListTables": "ListTablesInput", + "ListTagsOfResource": "ListTagsOfResourceInput", + "PutItem": "PutItemInput", + "PutResourcePolicy": "PutResourcePolicyInput", + "Query": "QueryInput", + "RestoreTableFromBackup": "RestoreTableFromBackupInput", + "RestoreTableToPointInTime": "RestoreTableToPointInTimeInput", + "Scan": "ScanInput", + "SearchVectors": "SearchVectorsInput", + "TagResource": "TagResourceInput", + "TransactGetItems": "TransactGetItemsInput", + "TransactWriteItems": "TransactWriteItemsInput", + "UntagResource": "UntagResourceInput", + "UpdateContinuousBackups": "UpdateContinuousBackupsInput", + "UpdateContributorInsights": "UpdateContributorInsightsInput", + "UpdateGlobalTable": "UpdateGlobalTableInput", + "UpdateGlobalTableSettings": "UpdateGlobalTableSettingsInput", + "UpdateItem": "UpdateItemInput", + "UpdateKinesisStreamingDestination": "UpdateKinesisStreamingDestinationInput", + "UpdateTable": "UpdateTableInput", + "UpdateTableReplicaAutoScaling": "UpdateTableReplicaAutoScalingInput", + "UpdateTimeToLive": "UpdateTimeToLiveInput" + }, + "shapes": { + "ApproximateCreationDateTimePrecision": { + "type": "string" + }, + "AttributeAction": { + "type": "string" + }, + "AttributeDefinition": { + "type": "structure", + "members": { + "AttributeName": "KeySchemaAttributeName", + "AttributeType": "ScalarAttributeType" + } + }, + "AttributeDefinitions": { + "type": "list", + "member": "AttributeDefinition" + }, + "AttributeName": { + "type": "string" + }, + "AttributeNameList": { + "type": "list", + "member": "AttributeName" + }, + "AttributeUpdates": { + "type": "map", + "value": "AttributeValueUpdate" + }, + "AttributeValue": { + "type": "structure", + "members": { + "S": "StringAttributeValue", + "N": "NumberAttributeValue", + "B": "BinaryAttributeValue", + "SS": "StringSetAttributeValue", + "NS": "NumberSetAttributeValue", + "BS": "BinarySetAttributeValue", + "M": "MapAttributeValue", + "L": "ListAttributeValue", + "NULL": "NullAttributeValue", + "BOOL": "BooleanAttributeValue" + } + }, + "AttributeValueList": { + "type": "list", + "member": "AttributeValue" + }, + "AttributeValueUpdate": { + "type": "structure", + "members": { + "Value": "AttributeValue", + "Action": "AttributeAction" + } + }, + "AutoScalingPolicyName": { + "type": "string" + }, + "AutoScalingPolicyUpdate": { + "type": "structure", + "members": { + "PolicyName": "AutoScalingPolicyName", + "TargetTrackingScalingPolicyConfiguration": "AutoScalingTargetTrackingScalingPolicyConfigurationUpdate" + } + }, + "AutoScalingRoleArn": { + "type": "string" + }, + "AutoScalingSettingsUpdate": { + "type": "structure", + "members": { + "MinimumUnits": "PositiveLongObject", + "MaximumUnits": "PositiveLongObject", + "AutoScalingDisabled": "BooleanObject", + "AutoScalingRoleArn": "AutoScalingRoleArn", + "ScalingPolicyUpdate": "AutoScalingPolicyUpdate" + } + }, + "AutoScalingTargetTrackingScalingPolicyConfigurationUpdate": { + "type": "structure", + "members": { + "DisableScaleIn": "BooleanObject", + "ScaleInCooldown": "IntegerObject", + "ScaleOutCooldown": "IntegerObject", + "TargetValue": "DoubleObject" + } + }, + "BackupArn": { + "type": "string" + }, + "BackupName": { + "type": "string" + }, + "BackupTypeFilter": { + "type": "string" + }, + "BackupsInputLimit": { + "type": "integer" + }, + "BatchExecuteStatementInput": { + "type": "structure", + "members": { + "Statements": "PartiQLBatchRequest", + "ReturnConsumedCapacity": "ReturnConsumedCapacity" + } + }, + "BatchGetItemInput": { + "type": "structure", + "members": { + "RequestItems": "BatchGetRequestMap", + "ReturnConsumedCapacity": "ReturnConsumedCapacity" + } + }, + "BatchGetRequestMap": { + "type": "map", + "value": "KeysAndAttributes" + }, + "BatchStatementRequest": { + "type": "structure", + "members": { + "Statement": "PartiQLStatement", + "Parameters": "PreparedStatementParameters", + "ConsistentRead": "ConsistentRead", + "ReturnValuesOnConditionCheckFailure": "ReturnValuesOnConditionCheckFailure" + } + }, + "BatchWriteItemInput": { + "type": "structure", + "members": { + "RequestItems": "BatchWriteItemRequestMap", + "ReturnConsumedCapacity": "ReturnConsumedCapacity", + "ReturnItemCollectionMetrics": "ReturnItemCollectionMetrics" + } + }, + "BatchWriteItemRequestMap": { + "type": "map", + "value": "WriteRequests" + }, + "BillingMode": { + "type": "string" + }, + "BinaryAttributeValue": { + "type": "blob" + }, + "BinarySetAttributeValue": { + "type": "list", + "member": "BinaryAttributeValue" + }, + "BooleanAttributeValue": { + "type": "boolean" + }, + "BooleanObject": { + "type": "boolean" + }, + "ClientRequestToken": { + "type": "string" + }, + "ClientToken": { + "type": "string" + }, + "ComparisonOperator": { + "type": "string" + }, + "Condition": { + "type": "structure", + "members": { + "AttributeValueList": "AttributeValueList", + "ComparisonOperator": "ComparisonOperator" + } + }, + "ConditionCheck": { + "type": "structure", + "members": { + "Key": "Key", + "TableName": "TableArn", + "ConditionExpression": "ConditionExpression", + "ExpressionAttributeNames": "ExpressionAttributeNameMap", + "ExpressionAttributeValues": "ExpressionAttributeValueMap", + "ReturnValuesOnConditionCheckFailure": "ReturnValuesOnConditionCheckFailure" + } + }, + "ConditionExpression": { + "type": "string" + }, + "ConditionalOperator": { + "type": "string" + }, + "ConfirmRemoveSelfResourceAccess": { + "type": "boolean" + }, + "ConsistentRead": { + "type": "boolean" + }, + "ContributorInsightsAction": { + "type": "string" + }, + "ContributorInsightsMode": { + "type": "string" + }, + "CreateBackupInput": { + "type": "structure", + "members": { + "TableName": "TableArn", + "BackupName": "BackupName" + } + }, + "CreateGlobalSecondaryIndexAction": { + "type": "structure", + "members": { + "IndexName": "IndexName", + "KeySchema": "KeySchema", + "Projection": "Projection", + "ProvisionedThroughput": "ProvisionedThroughput", + "OnDemandThroughput": "OnDemandThroughput", + "WarmThroughput": "WarmThroughput" + } + }, + "CreateGlobalTableInput": { + "type": "structure", + "members": { + "GlobalTableName": "TableName", + "ReplicationGroup": "ReplicaList" + } + }, + "CreateGlobalTableWitnessGroupMemberAction": { + "type": "structure", + "members": { + "RegionName": "RegionName" + } + }, + "CreateReplicaAction": { + "type": "structure", + "members": { + "RegionName": "RegionName" + } + }, + "CreateReplicationGroupMemberAction": { + "type": "structure", + "members": { + "RegionName": "RegionName", + "KMSMasterKeyId": "KMSMasterKeyId", + "ProvisionedThroughputOverride": "ProvisionedThroughputOverride", + "OnDemandThroughputOverride": "OnDemandThroughputOverride", + "GlobalSecondaryIndexes": "ReplicaGlobalSecondaryIndexList", + "TableClassOverride": "TableClass" + } + }, + "CreateTableInput": { + "type": "structure", + "members": { + "AttributeDefinitions": "AttributeDefinitions", + "TableName": "TableArn", + "KeySchema": "KeySchema", + "LocalSecondaryIndexes": "LocalSecondaryIndexList", + "GlobalSecondaryIndexes": "GlobalSecondaryIndexList", + "BillingMode": "BillingMode", + "ProvisionedThroughput": "ProvisionedThroughput", + "StreamSpecification": "StreamSpecification", + "SSESpecification": "SSESpecification", + "Tags": "TagList", + "TableClass": "TableClass", + "DeletionProtectionEnabled": "DeletionProtectionEnabled", + "WarmThroughput": "WarmThroughput", + "ResourcePolicy": "ResourcePolicy", + "OnDemandThroughput": "OnDemandThroughput", + "GlobalTableSourceArn": "TableArn", + "GlobalTableSettingsReplicationMode": "GlobalTableSettingsReplicationMode", + "VectorIndexes": "VectorIndexList" + } + }, + "CreateVectorIndexAction": { + "type": "structure", + "members": { + "IndexName": "IndexName", + "VectorAttribute": "VectorAttributeDefinition", + "SearchSchema": "SearchSchema", + "Projection": "Projection", + "Dimensions": "PositiveLongObject", + "DistanceFunction": "VectorDistanceFunction" + } + }, + "CsvDelimiter": { + "type": "string" + }, + "CsvHeader": { + "type": "string" + }, + "CsvHeaderList": { + "type": "list", + "member": "CsvHeader" + }, + "CsvOptions": { + "type": "structure", + "members": { + "Delimiter": "CsvDelimiter", + "HeaderList": "CsvHeaderList" + } + }, + "Date": { + "type": "timestamp" + }, + "Delete": { + "type": "structure", + "members": { + "Key": "Key", + "TableName": "TableArn", + "ConditionExpression": "ConditionExpression", + "ExpressionAttributeNames": "ExpressionAttributeNameMap", + "ExpressionAttributeValues": "ExpressionAttributeValueMap", + "ReturnValuesOnConditionCheckFailure": "ReturnValuesOnConditionCheckFailure" + } + }, + "DeleteBackupInput": { + "type": "structure", + "members": { + "BackupArn": "BackupArn" + } + }, + "DeleteGlobalSecondaryIndexAction": { + "type": "structure", + "members": { + "IndexName": "IndexName" + } + }, + "DeleteGlobalTableWitnessGroupMemberAction": { + "type": "structure", + "members": { + "RegionName": "RegionName" + } + }, + "DeleteItemInput": { + "type": "structure", + "members": { + "TableName": "TableArn", + "Key": "Key", + "Expected": "ExpectedAttributeMap", + "ConditionalOperator": "ConditionalOperator", + "ReturnValues": "ReturnValue", + "ReturnConsumedCapacity": "ReturnConsumedCapacity", + "ReturnItemCollectionMetrics": "ReturnItemCollectionMetrics", + "ConditionExpression": "ConditionExpression", + "ExpressionAttributeNames": "ExpressionAttributeNameMap", + "ExpressionAttributeValues": "ExpressionAttributeValueMap", + "ReturnValuesOnConditionCheckFailure": "ReturnValuesOnConditionCheckFailure" + } + }, + "DeleteReplicaAction": { + "type": "structure", + "members": { + "RegionName": "RegionName" + } + }, + "DeleteReplicationGroupMemberAction": { + "type": "structure", + "members": { + "RegionName": "RegionName" + } + }, + "DeleteRequest": { + "type": "structure", + "members": { + "Key": "Key" + } + }, + "DeleteResourcePolicyInput": { + "type": "structure", + "members": { + "ResourceArn": "ResourceArnString", + "ExpectedRevisionId": "PolicyRevisionId" + } + }, + "DeleteTableInput": { + "type": "structure", + "members": { + "TableName": "TableArn" + } + }, + "DeleteVectorIndexAction": { + "type": "structure", + "members": { + "IndexName": "IndexName" + } + }, + "DeletionProtectionEnabled": { + "type": "boolean" + }, + "DescribeBackupInput": { + "type": "structure", + "members": { + "BackupArn": "BackupArn" + } + }, + "DescribeContinuousBackupsInput": { + "type": "structure", + "members": { + "TableName": "TableArn" + } + }, + "DescribeContributorInsightsInput": { + "type": "structure", + "members": { + "TableName": "TableArn", + "IndexName": "IndexName" + } + }, + "DescribeEndpointsRequest": { + "type": "structure", + "members": {} + }, + "DescribeExportInput": { + "type": "structure", + "members": { + "ExportArn": "ExportArn" + } + }, + "DescribeGlobalTableInput": { + "type": "structure", + "members": { + "GlobalTableName": "TableName" + } + }, + "DescribeGlobalTableSettingsInput": { + "type": "structure", + "members": { + "GlobalTableName": "TableName" + } + }, + "DescribeImportInput": { + "type": "structure", + "members": { + "ImportArn": "ImportArn" + } + }, + "DescribeKinesisStreamingDestinationInput": { + "type": "structure", + "members": { + "TableName": "TableArn" + } + }, + "DescribeLimitsInput": { + "type": "structure", + "members": {} + }, + "DescribeTableInput": { + "type": "structure", + "members": { + "TableName": "TableArn" + } + }, + "DescribeTableReplicaAutoScalingInput": { + "type": "structure", + "members": { + "TableName": "TableArn" + } + }, + "DescribeTimeToLiveInput": { + "type": "structure", + "members": { + "TableName": "TableArn" + } + }, + "DoubleObject": { + "type": "double" + }, + "EnableKinesisStreamingConfiguration": { + "type": "structure", + "members": { + "ApproximateCreationDateTimePrecision": "ApproximateCreationDateTimePrecision" + } + }, + "ExecuteStatementInput": { + "type": "structure", + "members": { + "Statement": "PartiQLStatement", + "Parameters": "PreparedStatementParameters", + "ConsistentRead": "ConsistentRead", + "NextToken": "PartiQLNextToken", + "ReturnConsumedCapacity": "ReturnConsumedCapacity", + "Limit": "PositiveIntegerObject", + "ReturnValuesOnConditionCheckFailure": "ReturnValuesOnConditionCheckFailure" + } + }, + "ExecuteTransactionInput": { + "type": "structure", + "members": { + "TransactStatements": "ParameterizedStatements", + "ClientRequestToken": "ClientRequestToken", + "ReturnConsumedCapacity": "ReturnConsumedCapacity" + } + }, + "ExpectedAttributeMap": { + "type": "map", + "value": "ExpectedAttributeValue" + }, + "ExpectedAttributeValue": { + "type": "structure", + "members": { + "Value": "AttributeValue", + "Exists": "BooleanObject", + "ComparisonOperator": "ComparisonOperator", + "AttributeValueList": "AttributeValueList" + } + }, + "ExportArn": { + "type": "string" + }, + "ExportFormat": { + "type": "string" + }, + "ExportFromTime": { + "type": "timestamp" + }, + "ExportNextToken": { + "type": "string" + }, + "ExportTableToPointInTimeInput": { + "type": "structure", + "members": { + "TableArn": "TableArn", + "ExportTime": "ExportTime", + "ClientToken": "ClientToken", + "S3Bucket": "S3Bucket", + "S3BucketOwner": "S3BucketOwner", + "S3Prefix": "S3Prefix", + "S3SseAlgorithm": "S3SseAlgorithm", + "S3SseKmsKeyId": "S3SseKmsKeyId", + "ExportFormat": "ExportFormat", + "ExportType": "ExportType", + "IncrementalExportSpecification": "IncrementalExportSpecification" + } + }, + "ExportTime": { + "type": "timestamp" + }, + "ExportToTime": { + "type": "timestamp" + }, + "ExportType": { + "type": "string" + }, + "ExportViewType": { + "type": "string" + }, + "ExpressionAttributeNameMap": { + "type": "map", + "value": "AttributeName" + }, + "ExpressionAttributeValueMap": { + "type": "map", + "value": "AttributeValue" + }, + "FilterConditionMap": { + "type": "map", + "value": "Condition" + }, + "Get": { + "type": "structure", + "members": { + "Key": "Key", + "TableName": "TableArn", + "ProjectionExpression": "ProjectionExpression", + "ExpressionAttributeNames": "ExpressionAttributeNameMap" + } + }, + "GetItemInput": { + "type": "structure", + "members": { + "TableName": "TableArn", + "Key": "Key", + "AttributesToGet": "AttributeNameList", + "ConsistentRead": "ConsistentRead", + "ReturnConsumedCapacity": "ReturnConsumedCapacity", + "ProjectionExpression": "ProjectionExpression", + "ExpressionAttributeNames": "ExpressionAttributeNameMap" + } + }, + "GetResourcePolicyInput": { + "type": "structure", + "members": { + "ResourceArn": "ResourceArnString" + } + }, + "GlobalSecondaryIndex": { + "type": "structure", + "members": { + "IndexName": "IndexName", + "KeySchema": "KeySchema", + "Projection": "Projection", + "ProvisionedThroughput": "ProvisionedThroughput", + "OnDemandThroughput": "OnDemandThroughput", + "WarmThroughput": "WarmThroughput" + } + }, + "GlobalSecondaryIndexAutoScalingUpdate": { + "type": "structure", + "members": { + "IndexName": "IndexName", + "ProvisionedWriteCapacityAutoScalingUpdate": "AutoScalingSettingsUpdate" + } + }, + "GlobalSecondaryIndexAutoScalingUpdateList": { + "type": "list", + "member": "GlobalSecondaryIndexAutoScalingUpdate" + }, + "GlobalSecondaryIndexList": { + "type": "list", + "member": "GlobalSecondaryIndex" + }, + "GlobalSecondaryIndexUpdate": { + "type": "structure", + "members": { + "Update": "UpdateGlobalSecondaryIndexAction", + "Create": "CreateGlobalSecondaryIndexAction", + "Delete": "DeleteGlobalSecondaryIndexAction" + } + }, + "GlobalSecondaryIndexUpdateList": { + "type": "list", + "member": "GlobalSecondaryIndexUpdate" + }, + "GlobalTableGlobalSecondaryIndexSettingsUpdate": { + "type": "structure", + "members": { + "IndexName": "IndexName", + "ProvisionedWriteCapacityUnits": "PositiveLongObject", + "ProvisionedWriteCapacityAutoScalingSettingsUpdate": "AutoScalingSettingsUpdate" + } + }, + "GlobalTableGlobalSecondaryIndexSettingsUpdateList": { + "type": "list", + "member": "GlobalTableGlobalSecondaryIndexSettingsUpdate" + }, + "GlobalTableSettingsReplicationMode": { + "type": "string" + }, + "GlobalTableWitnessGroupUpdate": { + "type": "structure", + "members": { + "Create": "CreateGlobalTableWitnessGroupMemberAction", + "Delete": "DeleteGlobalTableWitnessGroupMemberAction" + } + }, + "GlobalTableWitnessGroupUpdateList": { + "type": "list", + "member": "GlobalTableWitnessGroupUpdate" + }, + "ImportArn": { + "type": "string" + }, + "ImportNextToken": { + "type": "string" + }, + "ImportTableInput": { + "type": "structure", + "members": { + "ClientToken": "ClientToken", + "S3BucketSource": "S3BucketSource", + "InputFormat": "InputFormat", + "InputFormatOptions": "InputFormatOptions", + "InputCompressionType": "InputCompressionType", + "TableCreationParameters": "TableCreationParameters" + } + }, + "IncrementalExportSpecification": { + "type": "structure", + "members": { + "ExportFromTime": "ExportFromTime", + "ExportToTime": "ExportToTime", + "ExportViewType": "ExportViewType" + } + }, + "IndexName": { + "type": "string" + }, + "InputCompressionType": { + "type": "string" + }, + "InputFormat": { + "type": "string" + }, + "InputFormatOptions": { + "type": "structure", + "members": { + "Csv": "CsvOptions" + } + }, + "IntegerObject": { + "type": "integer" + }, + "KMSMasterKeyId": { + "type": "string" + }, + "Key": { + "type": "map", + "value": "AttributeValue" + }, + "KeyConditions": { + "type": "map", + "value": "Condition" + }, + "KeyExpression": { + "type": "string" + }, + "KeyList": { + "type": "list", + "member": "Key" + }, + "KeySchema": { + "type": "list", + "member": "KeySchemaElement" + }, + "KeySchemaAttributeName": { + "type": "string" + }, + "KeySchemaElement": { + "type": "structure", + "members": { + "AttributeName": "KeySchemaAttributeName", + "KeyType": "KeyType" + } + }, + "KeyType": { + "type": "string" + }, + "KeysAndAttributes": { + "type": "structure", + "members": { + "Keys": "KeyList", + "AttributesToGet": "AttributeNameList", + "ConsistentRead": "ConsistentRead", + "ProjectionExpression": "ProjectionExpression", + "ExpressionAttributeNames": "ExpressionAttributeNameMap" + } + }, + "KinesisStreamingDestinationInput": { + "type": "structure", + "members": { + "TableName": "TableArn", + "StreamArn": "StreamArn", + "EnableKinesisStreamingConfiguration": "EnableKinesisStreamingConfiguration" + } + }, + "ListAttributeValue": { + "type": "list", + "member": "AttributeValue" + }, + "ListBackupsInput": { + "type": "structure", + "members": { + "TableName": "TableArn", + "Limit": "BackupsInputLimit", + "TimeRangeLowerBound": "TimeRangeLowerBound", + "TimeRangeUpperBound": "TimeRangeUpperBound", + "ExclusiveStartBackupArn": "BackupArn", + "BackupType": "BackupTypeFilter" + } + }, + "ListContributorInsightsInput": { + "type": "structure", + "members": { + "TableName": "TableArn", + "NextToken": "NextTokenString", + "MaxResults": "ListContributorInsightsLimit" + } + }, + "ListContributorInsightsLimit": { + "type": "integer" + }, + "ListExportsInput": { + "type": "structure", + "members": { + "TableArn": "TableArn", + "MaxResults": "ListExportsMaxLimit", + "NextToken": "ExportNextToken" + } + }, + "ListExportsMaxLimit": { + "type": "integer" + }, + "ListGlobalTablesInput": { + "type": "structure", + "members": { + "ExclusiveStartGlobalTableName": "TableName", + "Limit": "PositiveIntegerObject", + "RegionName": "RegionName" + } + }, + "ListImportsInput": { + "type": "structure", + "members": { + "TableArn": "TableArn", + "PageSize": "ListImportsMaxLimit", + "NextToken": "ImportNextToken" + } + }, + "ListImportsMaxLimit": { + "type": "integer" + }, + "ListTablesInput": { + "type": "structure", + "members": { + "ExclusiveStartTableName": "TableName", + "Limit": "ListTablesInputLimit" + } + }, + "ListTablesInputLimit": { + "type": "integer" + }, + "ListTagsOfResourceInput": { + "type": "structure", + "members": { + "ResourceArn": "ResourceArnString", + "NextToken": "NextTokenString" + } + }, + "LocalSecondaryIndex": { + "type": "structure", + "members": { + "IndexName": "IndexName", + "KeySchema": "KeySchema", + "Projection": "Projection" + } + }, + "LocalSecondaryIndexList": { + "type": "list", + "member": "LocalSecondaryIndex" + }, + "LongObject": { + "type": "long" + }, + "MapAttributeValue": { + "type": "map", + "value": "AttributeValue" + }, + "MultiRegionConsistency": { + "type": "string" + }, + "NextTokenString": { + "type": "string" + }, + "NonKeyAttributeName": { + "type": "string" + }, + "NonKeyAttributeNameList": { + "type": "list", + "member": "NonKeyAttributeName" + }, + "NullAttributeValue": { + "type": "boolean" + }, + "NumberAttributeValue": { + "type": "string" + }, + "NumberSetAttributeValue": { + "type": "list", + "member": "NumberAttributeValue" + }, + "OnDemandThroughput": { + "type": "structure", + "members": { + "MaxReadRequestUnits": "LongObject", + "MaxWriteRequestUnits": "LongObject" + } + }, + "OnDemandThroughputOverride": { + "type": "structure", + "members": { + "MaxReadRequestUnits": "LongObject" + } + }, + "ParameterizedStatement": { + "type": "structure", + "members": { + "Statement": "PartiQLStatement", + "Parameters": "PreparedStatementParameters", + "ReturnValuesOnConditionCheckFailure": "ReturnValuesOnConditionCheckFailure" + } + }, + "ParameterizedStatements": { + "type": "list", + "member": "ParameterizedStatement" + }, + "PartiQLBatchRequest": { + "type": "list", + "member": "BatchStatementRequest" + }, + "PartiQLNextToken": { + "type": "string" + }, + "PartiQLStatement": { + "type": "string" + }, + "PointInTimeRecoverySpecification": { + "type": "structure", + "members": { + "PointInTimeRecoveryEnabled": "BooleanObject", + "RecoveryPeriodInDays": "RecoveryPeriodInDays" + } + }, + "PolicyRevisionId": { + "type": "string" + }, + "PositiveIntegerObject": { + "type": "integer" + }, + "PositiveLongObject": { + "type": "long" + }, + "PreparedStatementParameters": { + "type": "list", + "member": "AttributeValue" + }, + "Projection": { + "type": "structure", + "members": { + "ProjectionType": "ProjectionType", + "NonKeyAttributes": "NonKeyAttributeNameList" + } + }, + "ProjectionExpression": { + "type": "string" + }, + "ProjectionType": { + "type": "string" + }, + "ProvisionedThroughput": { + "type": "structure", + "members": { + "ReadCapacityUnits": "PositiveLongObject", + "WriteCapacityUnits": "PositiveLongObject" + } + }, + "ProvisionedThroughputOverride": { + "type": "structure", + "members": { + "ReadCapacityUnits": "PositiveLongObject" + } + }, + "Put": { + "type": "structure", + "members": { + "Item": "PutItemInputAttributeMap", + "TableName": "TableArn", + "ConditionExpression": "ConditionExpression", + "ExpressionAttributeNames": "ExpressionAttributeNameMap", + "ExpressionAttributeValues": "ExpressionAttributeValueMap", + "ReturnValuesOnConditionCheckFailure": "ReturnValuesOnConditionCheckFailure" + } + }, + "PutItemInput": { + "type": "structure", + "members": { + "TableName": "TableArn", + "Item": "PutItemInputAttributeMap", + "Expected": "ExpectedAttributeMap", + "ReturnValues": "ReturnValue", + "ReturnConsumedCapacity": "ReturnConsumedCapacity", + "ReturnItemCollectionMetrics": "ReturnItemCollectionMetrics", + "ConditionalOperator": "ConditionalOperator", + "ConditionExpression": "ConditionExpression", + "ExpressionAttributeNames": "ExpressionAttributeNameMap", + "ExpressionAttributeValues": "ExpressionAttributeValueMap", + "ReturnValuesOnConditionCheckFailure": "ReturnValuesOnConditionCheckFailure" + } + }, + "PutItemInputAttributeMap": { + "type": "map", + "value": "AttributeValue" + }, + "PutRequest": { + "type": "structure", + "members": { + "Item": "PutItemInputAttributeMap" + } + }, + "PutResourcePolicyInput": { + "type": "structure", + "members": { + "ResourceArn": "ResourceArnString", + "Policy": "ResourcePolicy", + "ExpectedRevisionId": "PolicyRevisionId", + "ConfirmRemoveSelfResourceAccess": "ConfirmRemoveSelfResourceAccess" + } + }, + "QueryInput": { + "type": "structure", + "members": { + "TableName": "TableArn", + "IndexName": "IndexName", + "Select": "Select", + "AttributesToGet": "AttributeNameList", + "Limit": "PositiveIntegerObject", + "ConsistentRead": "ConsistentRead", + "KeyConditions": "KeyConditions", + "QueryFilter": "FilterConditionMap", + "ConditionalOperator": "ConditionalOperator", + "ScanIndexForward": "BooleanObject", + "ExclusiveStartKey": "Key", + "ReturnConsumedCapacity": "ReturnConsumedCapacity", + "ProjectionExpression": "ProjectionExpression", + "FilterExpression": "ConditionExpression", + "KeyConditionExpression": "KeyExpression", + "ExpressionAttributeNames": "ExpressionAttributeNameMap", + "ExpressionAttributeValues": "ExpressionAttributeValueMap" + } + }, + "RecoveryPeriodInDays": { + "type": "integer" + }, + "RegionName": { + "type": "string" + }, + "Replica": { + "type": "structure", + "members": { + "RegionName": "RegionName" + } + }, + "ReplicaAutoScalingUpdate": { + "type": "structure", + "members": { + "RegionName": "RegionName", + "ReplicaGlobalSecondaryIndexUpdates": "ReplicaGlobalSecondaryIndexAutoScalingUpdateList", + "ReplicaProvisionedReadCapacityAutoScalingUpdate": "AutoScalingSettingsUpdate" + } + }, + "ReplicaAutoScalingUpdateList": { + "type": "list", + "member": "ReplicaAutoScalingUpdate" + }, + "ReplicaGlobalSecondaryIndex": { + "type": "structure", + "members": { + "IndexName": "IndexName", + "ProvisionedThroughputOverride": "ProvisionedThroughputOverride", + "OnDemandThroughputOverride": "OnDemandThroughputOverride" + } + }, + "ReplicaGlobalSecondaryIndexAutoScalingUpdate": { + "type": "structure", + "members": { + "IndexName": "IndexName", + "ProvisionedReadCapacityAutoScalingUpdate": "AutoScalingSettingsUpdate" + } + }, + "ReplicaGlobalSecondaryIndexAutoScalingUpdateList": { + "type": "list", + "member": "ReplicaGlobalSecondaryIndexAutoScalingUpdate" + }, + "ReplicaGlobalSecondaryIndexList": { + "type": "list", + "member": "ReplicaGlobalSecondaryIndex" + }, + "ReplicaGlobalSecondaryIndexSettingsUpdate": { + "type": "structure", + "members": { + "IndexName": "IndexName", + "ProvisionedReadCapacityUnits": "PositiveLongObject", + "ProvisionedReadCapacityAutoScalingSettingsUpdate": "AutoScalingSettingsUpdate" + } + }, + "ReplicaGlobalSecondaryIndexSettingsUpdateList": { + "type": "list", + "member": "ReplicaGlobalSecondaryIndexSettingsUpdate" + }, + "ReplicaList": { + "type": "list", + "member": "Replica" + }, + "ReplicaSettingsUpdate": { + "type": "structure", + "members": { + "RegionName": "RegionName", + "ReplicaProvisionedReadCapacityUnits": "PositiveLongObject", + "ReplicaProvisionedReadCapacityAutoScalingSettingsUpdate": "AutoScalingSettingsUpdate", + "ReplicaGlobalSecondaryIndexSettingsUpdate": "ReplicaGlobalSecondaryIndexSettingsUpdateList", + "ReplicaTableClass": "TableClass" + } + }, + "ReplicaSettingsUpdateList": { + "type": "list", + "member": "ReplicaSettingsUpdate" + }, + "ReplicaUpdate": { + "type": "structure", + "members": { + "Create": "CreateReplicaAction", + "Delete": "DeleteReplicaAction" + } + }, + "ReplicaUpdateList": { + "type": "list", + "member": "ReplicaUpdate" + }, + "ReplicationGroupUpdate": { + "type": "structure", + "members": { + "Create": "CreateReplicationGroupMemberAction", + "Update": "UpdateReplicationGroupMemberAction", + "Delete": "DeleteReplicationGroupMemberAction" + } + }, + "ReplicationGroupUpdateList": { + "type": "list", + "member": "ReplicationGroupUpdate" + }, + "ResourceArnString": { + "type": "string" + }, + "ResourcePolicy": { + "type": "string" + }, + "RestoreTableFromBackupInput": { + "type": "structure", + "members": { + "TargetTableName": "TableName", + "BackupArn": "BackupArn", + "BillingModeOverride": "BillingMode", + "GlobalSecondaryIndexOverride": "GlobalSecondaryIndexList", + "LocalSecondaryIndexOverride": "LocalSecondaryIndexList", + "ProvisionedThroughputOverride": "ProvisionedThroughput", + "OnDemandThroughputOverride": "OnDemandThroughput", + "SSESpecificationOverride": "SSESpecification", + "VectorIndexOverride": "VectorIndexList" + } + }, + "RestoreTableToPointInTimeInput": { + "type": "structure", + "members": { + "SourceTableArn": "TableArn", + "SourceTableName": "TableName", + "TargetTableName": "TableName", + "UseLatestRestorableTime": "BooleanObject", + "RestoreDateTime": "Date", + "BillingModeOverride": "BillingMode", + "GlobalSecondaryIndexOverride": "GlobalSecondaryIndexList", + "LocalSecondaryIndexOverride": "LocalSecondaryIndexList", + "ProvisionedThroughputOverride": "ProvisionedThroughput", + "OnDemandThroughputOverride": "OnDemandThroughput", + "SSESpecificationOverride": "SSESpecification", + "VectorIndexOverride": "VectorIndexList" + } + }, + "ReturnConsumedCapacity": { + "type": "string" + }, + "ReturnItemCollectionMetrics": { + "type": "string" + }, + "ReturnValue": { + "type": "string" + }, + "ReturnValuesOnConditionCheckFailure": { + "type": "string" + }, + "S3Bucket": { + "type": "string" + }, + "S3BucketOwner": { + "type": "string" + }, + "S3BucketSource": { + "type": "structure", + "members": { + "S3BucketOwner": "S3BucketOwner", + "S3Bucket": "S3Bucket", + "S3KeyPrefix": "S3Prefix" + } + }, + "S3Prefix": { + "type": "string" + }, + "S3SseAlgorithm": { + "type": "string" + }, + "S3SseKmsKeyId": { + "type": "string" + }, + "SSEEnabled": { + "type": "boolean" + }, + "SSESpecification": { + "type": "structure", + "members": { + "Enabled": "SSEEnabled", + "SSEType": "SSEType", + "KMSMasterKeyId": "KMSMasterKeyId" + } + }, + "SSEType": { + "type": "string" + }, + "ScalarAttributeType": { + "type": "string" + }, + "ScanInput": { + "type": "structure", + "members": { + "TableName": "TableArn", + "IndexName": "IndexName", + "AttributesToGet": "AttributeNameList", + "Limit": "PositiveIntegerObject", + "Select": "Select", + "ScanFilter": "FilterConditionMap", + "ConditionalOperator": "ConditionalOperator", + "ExclusiveStartKey": "Key", + "ReturnConsumedCapacity": "ReturnConsumedCapacity", + "TotalSegments": "ScanTotalSegments", + "Segment": "ScanSegment", + "ProjectionExpression": "ProjectionExpression", + "FilterExpression": "ConditionExpression", + "ExpressionAttributeNames": "ExpressionAttributeNameMap", + "ExpressionAttributeValues": "ExpressionAttributeValueMap", + "ConsistentRead": "ConsistentRead" + } + }, + "ScanSegment": { + "type": "integer" + }, + "ScanTotalSegments": { + "type": "integer" + }, + "SearchSchema": { + "type": "list", + "member": "SearchSchemaElement" + }, + "SearchSchemaElement": { + "type": "structure", + "members": { + "AttributeName": "AttributeName", + "SearchSchemaElementType": "SearchSchemaElementType" + } + }, + "SearchSchemaElementType": { + "type": "string" + }, + "SearchVectorList": { + "type": "list", + "member": "AttributeValue" + }, + "SearchVectorsInput": { + "type": "structure", + "members": { + "TableName": "TableArn", + "IndexName": "IndexName", + "ReturnConsumedCapacity": "ReturnConsumedCapacity", + "ExpressionAttributeNames": "ExpressionAttributeNameMap", + "ExpressionAttributeValues": "ExpressionAttributeValueMap", + "ProjectionExpression": "ProjectionExpression", + "SearchVector": "SearchVectorList", + "SearchConditionExpression": "String", + "TopK": "TopKInteger" + } + }, + "Select": { + "type": "string" + }, + "StreamArn": { + "type": "string" + }, + "StreamEnabled": { + "type": "boolean" + }, + "StreamSpecification": { + "type": "structure", + "members": { + "StreamEnabled": "StreamEnabled", + "StreamViewType": "StreamViewType" + } + }, + "StreamViewType": { + "type": "string" + }, + "String": { + "type": "string" + }, + "StringAttributeValue": { + "type": "string" + }, + "StringSetAttributeValue": { + "type": "list", + "member": "StringAttributeValue" + }, + "TableArn": { + "type": "string" + }, + "TableClass": { + "type": "string" + }, + "TableCreationParameters": { + "type": "structure", + "members": { + "TableName": "TableName", + "AttributeDefinitions": "AttributeDefinitions", + "KeySchema": "KeySchema", + "BillingMode": "BillingMode", + "ProvisionedThroughput": "ProvisionedThroughput", + "OnDemandThroughput": "OnDemandThroughput", + "SSESpecification": "SSESpecification", + "GlobalSecondaryIndexes": "GlobalSecondaryIndexList", + "VectorIndexes": "VectorIndexList" + } + }, + "TableName": { + "type": "string" + }, + "Tag": { + "type": "structure", + "members": { + "Key": "TagKeyString", + "Value": "TagValueString" + } + }, + "TagKeyList": { + "type": "list", + "member": "TagKeyString" + }, + "TagKeyString": { + "type": "string" + }, + "TagList": { + "type": "list", + "member": "Tag" + }, + "TagResourceInput": { + "type": "structure", + "members": { + "ResourceArn": "ResourceArnString", + "Tags": "TagList" + } + }, + "TagValueString": { + "type": "string" + }, + "TimeRangeLowerBound": { + "type": "timestamp" + }, + "TimeRangeUpperBound": { + "type": "timestamp" + }, + "TimeToLiveAttributeName": { + "type": "string" + }, + "TimeToLiveEnabled": { + "type": "boolean" + }, + "TimeToLiveSpecification": { + "type": "structure", + "members": { + "Enabled": "TimeToLiveEnabled", + "AttributeName": "TimeToLiveAttributeName" + } + }, + "TopKInteger": { + "type": "integer" + }, + "TransactGetItem": { + "type": "structure", + "members": { + "Get": "Get" + } + }, + "TransactGetItemList": { + "type": "list", + "member": "TransactGetItem" + }, + "TransactGetItemsInput": { + "type": "structure", + "members": { + "TransactItems": "TransactGetItemList", + "ReturnConsumedCapacity": "ReturnConsumedCapacity" + } + }, + "TransactWriteItem": { + "type": "structure", + "members": { + "ConditionCheck": "ConditionCheck", + "Put": "Put", + "Delete": "Delete", + "Update": "Update" + } + }, + "TransactWriteItemList": { + "type": "list", + "member": "TransactWriteItem" + }, + "TransactWriteItemsInput": { + "type": "structure", + "members": { + "TransactItems": "TransactWriteItemList", + "ReturnConsumedCapacity": "ReturnConsumedCapacity", + "ReturnItemCollectionMetrics": "ReturnItemCollectionMetrics", + "ClientRequestToken": "ClientRequestToken" + } + }, + "UntagResourceInput": { + "type": "structure", + "members": { + "ResourceArn": "ResourceArnString", + "TagKeys": "TagKeyList" + } + }, + "Update": { + "type": "structure", + "members": { + "Key": "Key", + "UpdateExpression": "UpdateExpression", + "TableName": "TableArn", + "ConditionExpression": "ConditionExpression", + "ExpressionAttributeNames": "ExpressionAttributeNameMap", + "ExpressionAttributeValues": "ExpressionAttributeValueMap", + "ReturnValuesOnConditionCheckFailure": "ReturnValuesOnConditionCheckFailure" + } + }, + "UpdateContinuousBackupsInput": { + "type": "structure", + "members": { + "TableName": "TableArn", + "PointInTimeRecoverySpecification": "PointInTimeRecoverySpecification" + } + }, + "UpdateContributorInsightsInput": { + "type": "structure", + "members": { + "TableName": "TableArn", + "IndexName": "IndexName", + "ContributorInsightsAction": "ContributorInsightsAction", + "ContributorInsightsMode": "ContributorInsightsMode" + } + }, + "UpdateExpression": { + "type": "string" + }, + "UpdateGlobalSecondaryIndexAction": { + "type": "structure", + "members": { + "IndexName": "IndexName", + "ProvisionedThroughput": "ProvisionedThroughput", + "OnDemandThroughput": "OnDemandThroughput", + "WarmThroughput": "WarmThroughput" + } + }, + "UpdateGlobalTableInput": { + "type": "structure", + "members": { + "GlobalTableName": "TableName", + "ReplicaUpdates": "ReplicaUpdateList" + } + }, + "UpdateGlobalTableSettingsInput": { + "type": "structure", + "members": { + "GlobalTableName": "TableName", + "GlobalTableBillingMode": "BillingMode", + "GlobalTableProvisionedWriteCapacityUnits": "PositiveLongObject", + "GlobalTableProvisionedWriteCapacityAutoScalingSettingsUpdate": "AutoScalingSettingsUpdate", + "GlobalTableGlobalSecondaryIndexSettingsUpdate": "GlobalTableGlobalSecondaryIndexSettingsUpdateList", + "ReplicaSettingsUpdate": "ReplicaSettingsUpdateList" + } + }, + "UpdateItemInput": { + "type": "structure", + "members": { + "TableName": "TableArn", + "Key": "Key", + "AttributeUpdates": "AttributeUpdates", + "Expected": "ExpectedAttributeMap", + "ConditionalOperator": "ConditionalOperator", + "ReturnValues": "ReturnValue", + "ReturnConsumedCapacity": "ReturnConsumedCapacity", + "ReturnItemCollectionMetrics": "ReturnItemCollectionMetrics", + "UpdateExpression": "UpdateExpression", + "ConditionExpression": "ConditionExpression", + "ExpressionAttributeNames": "ExpressionAttributeNameMap", + "ExpressionAttributeValues": "ExpressionAttributeValueMap", + "ReturnValuesOnConditionCheckFailure": "ReturnValuesOnConditionCheckFailure" + } + }, + "UpdateKinesisStreamingConfiguration": { + "type": "structure", + "members": { + "ApproximateCreationDateTimePrecision": "ApproximateCreationDateTimePrecision" + } + }, + "UpdateKinesisStreamingDestinationInput": { + "type": "structure", + "members": { + "TableName": "TableArn", + "StreamArn": "StreamArn", + "UpdateKinesisStreamingConfiguration": "UpdateKinesisStreamingConfiguration" + } + }, + "UpdateReplicationGroupMemberAction": { + "type": "structure", + "members": { + "RegionName": "RegionName", + "KMSMasterKeyId": "KMSMasterKeyId", + "ProvisionedThroughputOverride": "ProvisionedThroughputOverride", + "OnDemandThroughputOverride": "OnDemandThroughputOverride", + "GlobalSecondaryIndexes": "ReplicaGlobalSecondaryIndexList", + "TableClassOverride": "TableClass" + } + }, + "UpdateTableInput": { + "type": "structure", + "members": { + "AttributeDefinitions": "AttributeDefinitions", + "TableName": "TableArn", + "BillingMode": "BillingMode", + "ProvisionedThroughput": "ProvisionedThroughput", + "GlobalSecondaryIndexUpdates": "GlobalSecondaryIndexUpdateList", + "StreamSpecification": "StreamSpecification", + "SSESpecification": "SSESpecification", + "ReplicaUpdates": "ReplicationGroupUpdateList", + "TableClass": "TableClass", + "DeletionProtectionEnabled": "DeletionProtectionEnabled", + "MultiRegionConsistency": "MultiRegionConsistency", + "GlobalTableWitnessUpdates": "GlobalTableWitnessGroupUpdateList", + "OnDemandThroughput": "OnDemandThroughput", + "WarmThroughput": "WarmThroughput", + "GlobalTableSettingsReplicationMode": "GlobalTableSettingsReplicationMode", + "VectorIndexUpdates": "VectorIndexUpdateList" + } + }, + "UpdateTableReplicaAutoScalingInput": { + "type": "structure", + "members": { + "GlobalSecondaryIndexUpdates": "GlobalSecondaryIndexAutoScalingUpdateList", + "TableName": "TableArn", + "ProvisionedWriteCapacityAutoScalingUpdate": "AutoScalingSettingsUpdate", + "ReplicaUpdates": "ReplicaAutoScalingUpdateList" + } + }, + "UpdateTimeToLiveInput": { + "type": "structure", + "members": { + "TableName": "TableArn", + "TimeToLiveSpecification": "TimeToLiveSpecification" + } + }, + "VectorAttributeDefinition": { + "type": "structure", + "members": { + "AttributeName": "VectorAttributeName" + } + }, + "VectorAttributeName": { + "type": "string" + }, + "VectorDistanceFunction": { + "type": "string" + }, + "VectorIndex": { + "type": "structure", + "members": { + "IndexName": "IndexName", + "VectorAttribute": "VectorAttributeDefinition", + "SearchSchema": "SearchSchema", + "Projection": "Projection", + "Dimensions": "PositiveLongObject", + "DistanceFunction": "VectorDistanceFunction" + } + }, + "VectorIndexList": { + "type": "list", + "member": "VectorIndex" + }, + "VectorIndexUpdate": { + "type": "structure", + "members": { + "Create": "CreateVectorIndexAction", + "Delete": "DeleteVectorIndexAction" + } + }, + "VectorIndexUpdateList": { + "type": "list", + "member": "VectorIndexUpdate" + }, + "WarmThroughput": { + "type": "structure", + "members": { + "ReadUnitsPerSecond": "LongObject", + "WriteUnitsPerSecond": "LongObject" + } + }, + "WriteRequest": { + "type": "structure", + "members": { + "PutRequest": "PutRequest", + "DeleteRequest": "DeleteRequest" + } + }, + "WriteRequests": { + "type": "list", + "member": "WriteRequest" + } + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathIntegrationTest.java index 7015656a83..31de391e07 100644 --- a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathIntegrationTest.java @@ -363,7 +363,8 @@ class DynamoDbAccessPathIntegrationTest { } """.formatted(TABLE)) .statusCode(400) - .body("__type", equalTo("ValidationException")); + .body("__type", equalTo("SerializationException")) + .body("message", equalTo("NUMBER_VALUE cannot be converted to String")); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java index cf9166cc05..12d0c844d7 100644 --- a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbIntegrationTest.java @@ -693,6 +693,43 @@ class DynamoDbIntegrationTest { .body("message", equalTo(message)); } + @Test + void aNonStringMemberFailsToDeserialize() { + given() + .header("X-Amz-Target", "DynamoDB_20120810.CreateTable") + .contentType(DYNAMODB_CONTENT_TYPE) + .body(""" + { + "TableName": "NonStringBillingModeTable", + "KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}], + "AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}], + "BillingMode": 5 + } + """) + .when() + .post("/") + .then() + .statusCode(400) + .body("__type", equalTo("SerializationException")) + .body("message", equalTo("NUMBER_VALUE cannot be converted to String")); + + given() + .header("X-Amz-Target", "DynamoDB_20120810.UpdateTable") + .contentType(DYNAMODB_CONTENT_TYPE) + .body(""" + { + "TableName": "NoSuchNonStringTable", + "GlobalSecondaryIndexUpdates": [{"Delete": {"IndexName": true}}] + } + """) + .when() + .post("/") + .then() + .statusCode(400) + .body("__type", equalTo("SerializationException")) + .body("message", equalTo("TRUE_VALUE cannot be converted to String")); + } + @Test void createTableWithGsiAndLsi() { given() diff --git a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbRequestShapesTest.java b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbRequestShapesTest.java new file mode 100644 index 0000000000..095f479c71 --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbRequestShapesTest.java @@ -0,0 +1,110 @@ +package io.github.hectorvent.floci.services.dynamodb; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.github.hectorvent.floci.core.common.AwsException; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class DynamoDbRequestShapesTest { + + private static final ObjectMapper MAPPER = new ObjectMapper(); + + @Test + void stringMemberNamesTheJsonTokenItGot() { + assertRejected("Scan", "{\"TableName\":\"t\",\"IndexName\":5}", "NUMBER_VALUE cannot be converted to String"); + assertRejected("Scan", "{\"TableName\":\"t\",\"IndexName\":5.5}", "DECIMAL_VALUE cannot be converted to String"); + assertRejected("Scan", "{\"TableName\":\"t\",\"IndexName\":1e3}", "DECIMAL_VALUE cannot be converted to String"); + assertRejected("Scan", "{\"TableName\":\"t\",\"IndexName\":true}", "TRUE_VALUE cannot be converted to String"); + assertRejected("Scan", "{\"TableName\":\"t\",\"IndexName\":false}", "FALSE_VALUE cannot be converted to String"); + assertRejected("Scan", "{\"TableName\":\"t\",\"IndexName\":{}}", "Start of structure or map found where not expected"); + assertRejected("Scan", "{\"TableName\":\"t\",\"IndexName\":[]}", "UnknownError"); + } + + @Test + void numericMembersAcceptAnyNumberAndNameTheirJavaType() { + assertAccepted("Scan", "{\"TableName\":\"t\",\"Limit\":5.5}"); + assertAccepted("Scan", "{\"TableName\":\"t\",\"Limit\":99999999999}"); + assertRejected("Scan", "{\"TableName\":\"t\",\"Limit\":\"5\"}", "STRING_VALUE cannot be converted to Integer"); + assertRejected("Scan", "{\"TableName\":\"t\",\"Limit\":false}", "FALSE_VALUE cannot be converted to Integer"); + assertRejected("UpdateTable", + "{\"TableName\":\"t\",\"ProvisionedThroughput\":{\"ReadCapacityUnits\":\"5\",\"WriteCapacityUnits\":5}}", + "STRING_VALUE cannot be converted to Long"); + assertRejected("UpdateTableReplicaAutoScaling", "{\"TableName\":\"t\",\"ProvisionedWriteCapacityAutoScalingUpdate\":" + + "{\"ScalingPolicyUpdate\":{\"TargetTrackingScalingPolicyConfiguration\":{\"TargetValue\":\"50\"}}}}", + "STRING_VALUE cannot be converted to Double"); + assertAccepted("ListBackups", "{\"TimeRangeLowerBound\":1577836800}"); + assertRejected("ListBackups", "{\"TimeRangeLowerBound\":\"2020-01-01T00:00:00Z\"}", + "STRING_VALUE cannot be converted to Date"); + } + + @Test + void booleanMemberAcceptsItsWordsAsStrings() { + assertAccepted("Scan", "{\"TableName\":\"t\",\"ConsistentRead\":\"false\"}"); + assertAccepted("Scan", "{\"TableName\":\"t\",\"ConsistentRead\":\"TRUE\"}"); + assertRejected("Scan", "{\"TableName\":\"t\",\"ConsistentRead\":\"abc\"}", "Unexpected token received from parser"); + assertRejected("Scan", "{\"TableName\":\"t\",\"ConsistentRead\":0}", "NUMBER_VALUE cannot be converted to Boolean"); + } + + @Test + void blobMemberTakesOnlyAString() { + assertRejected("PutItem", "{\"TableName\":\"t\",\"Item\":{\"a\":{\"B\":5}}}", + "only base-64-encoded strings are convertible to bytes"); + assertRejected("PutItem", "{\"TableName\":\"t\",\"Item\":{\"a\":{\"BS\":[true]}}}", + "only base-64-encoded strings are convertible to bytes"); + } + + @Test + void containerMessageDependsOnWhereTheValueSits() { + assertRejected("UpdateTable", "{\"TableName\":\"t\",\"ProvisionedThroughput\":\"a\"}", "Unexpected field type"); + assertRejected("UpdateTable", "{\"TableName\":\"t\",\"ProvisionedThroughput\":[]}", "UnknownError"); + assertRejected("Scan", "{\"TableName\":\"t\",\"AttributesToGet\":\"a\"}", "Unexpected field type"); + assertRejected("Scan", "{\"TableName\":\"t\",\"AttributesToGet\":{}}", "Start of structure or map found where not expected"); + assertRejected("Scan", "{\"TableName\":\"t\",\"ExpressionAttributeNames\":5}", "Unexpected field type"); + assertRejected("PutItem", "{\"TableName\":\"t\",\"Item\":{\"a\":5}}", "Unexpected value type in payload"); + assertRejected("UpdateTable", "{\"TableName\":\"t\",\"GlobalSecondaryIndexUpdates\":[\"a\"]}", + "Unexpected value type in payload"); + assertRejected("BatchWriteItem", "{\"RequestItems\":{\"t\":5}}", "UnknownError"); + assertRejected("BatchGetItem", "{\"RequestItems\":{\"t\":{\"Keys\":[5]}}}", "UnknownError"); + } + + @Test + void nestedMembersAreCheckedToo() { + assertRejected("UpdateTable", "{\"TableName\":\"t\",\"GlobalSecondaryIndexUpdates\":[{\"Delete\":{\"IndexName\":5}}]}", + "NUMBER_VALUE cannot be converted to String"); + assertRejected("CreateTable", "{\"TableName\":\"t\",\"BillingMode\":5}", "NUMBER_VALUE cannot be converted to String"); + assertRejected("Scan", "{\"TableName\":\"t\",\"ExclusiveStartKey\":{\"pk\":{\"S\":123}}}", + "NUMBER_VALUE cannot be converted to String"); + } + + @Test + void firstBadMemberInBodyOrderWins() { + assertRejected("Scan", "{\"TableName\":\"t\",\"Limit\":\"5\",\"IndexName\":5}", "STRING_VALUE cannot be converted to Integer"); + assertRejected("Scan", "{\"TableName\":\"t\",\"IndexName\":5,\"Limit\":\"5\"}", "NUMBER_VALUE cannot be converted to String"); + } + + @Test + void nullAndUnknownMembersAreLeftToTheOperation() { + assertAccepted("Scan", "{\"TableName\":\"t\",\"IndexName\":null,\"Limit\":null,\"Unknown\":5}"); + assertAccepted("Scan", "{\"TableName\":\"t\",\"AttributesToGet\":[null]}"); + assertAccepted("NoSuchOperation", "{\"TableName\":5}"); + } + + private static void assertRejected(String action, String body, String message) { + AwsException error = assertThrows(AwsException.class, () -> DynamoDbRequestShapes.check(action, json(body))); + assertEquals("SerializationException", error.getErrorCode()); + assertEquals(400, error.getHttpStatus()); + assertEquals(message, error.getMessage()); + } + + private static void assertAccepted(String action, String body) { + assertDoesNotThrow(() -> DynamoDbRequestShapes.check(action, json(body))); + } + + private static JsonNode json(String body) throws Exception { + return MAPPER.readTree(body); + } +} diff --git a/tools/aws/regen_dynamodb_shapes.py b/tools/aws/regen_dynamodb_shapes.py new file mode 100644 index 0000000000..1fb9b697bb --- /dev/null +++ b/tools/aws/regen_dynamodb_shapes.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python3 +"""Regenerate src/main/resources/aws/dynamodb-request-shapes.json from botocore's DynamoDB model. + +DynamoDB rejects a request member of the wrong JSON type with a SerializationException before +it runs the operation. The Java side (`DynamoDbRequestShapes`) needs each operation's input +shapes to do the same, so this script keeps only what that check reads: the input shape of +every operation, and for every shape reachable from one, its type and the shapes of its +members, list elements or map values. + +The model is botocore's `dynamodb/2012-08-10/service-2.json` (Apache-2.0, +https://github.com/boto/botocore). It is located, in order, at `--botocore-data`, the +`local/aws/botocore` checkout, then the installed `botocore` package, which +`requirements.txt` pins so CI regenerates the same bytes. + +Run from anywhere in the repo: + python3 tools/aws/regen_dynamodb_shapes.py # rewrite the vendored file in place + python3 tools/aws/regen_dynamodb_shapes.py --check # exit 1 when the vendored file is stale +""" +from __future__ import annotations + +import argparse +import gzip +import json +import sys +from pathlib import Path + +from regen_partitions import resolve_botocore_data, strip_source + +REPO_ROOT = Path(__file__).resolve().parents[2] +OUTPUT = REPO_ROOT / "src/main/resources/aws/dynamodb-request-shapes.json" +MODEL = Path("dynamodb/2012-08-10/service-2.json") + + +def load_model(data: Path) -> dict: + plain = data / MODEL + if plain.exists(): + return json.loads(plain.read_text(encoding="utf-8")) + compressed = plain.with_name(plain.name + ".gz") + if compressed.exists(): + with gzip.open(compressed, "rt", encoding="utf-8") as f: + return json.load(f) + raise SystemExit(f"error: {plain} not found") + + +def build(model: dict, provenance: str) -> dict: + shapes = model["shapes"] + kept: dict[str, dict] = {} + + def keep(name: str) -> None: + if name in kept: + return + shape = shapes[name] + kind = shape["type"] + entry: dict = {"type": kind} + kept[name] = entry + if kind == "structure": + entry["members"] = {member: spec["shape"] for member, spec in shape.get("members", {}).items()} + for spec in shape.get("members", {}).values(): + keep(spec["shape"]) + elif kind == "list": + entry["member"] = shape["member"]["shape"] + keep(shape["member"]["shape"]) + elif kind == "map": + entry["value"] = shape["value"]["shape"] + keep(shape["value"]["shape"]) + + operations = {} + for name, operation in sorted(model["operations"].items()): + if "input" in operation: + operations[name] = operation["input"]["shape"] + keep(operation["input"]["shape"]) + + return { + "_source": { + "generator": "tools/aws/regen_dynamodb_shapes.py", + "botocore": provenance, + }, + "operations": operations, + "shapes": dict(sorted(kept.items())), + } + + +def render(doc: dict) -> str: + return json.dumps(doc, indent=2, sort_keys=False) + "\n" + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument("--check", action="store_true", help="exit 1 when the vendored file differs from a fresh generation") + parser.add_argument("--botocore-data", type=Path, help="botocore data directory") + parser.add_argument("--output", type=Path, default=OUTPUT, help=argparse.SUPPRESS) + args = parser.parse_args(argv) + + data, provenance = resolve_botocore_data(args.botocore_data) + fresh = render(build(load_model(data), provenance)) + + if args.check: + current = args.output.read_text(encoding="utf-8") if args.output.exists() else "" + if strip_source(current) != strip_source(fresh): + print(f"{args.output} is stale (generated from {provenance}).", file=sys.stderr) + return 1 + return 0 + + args.output.write_text(fresh, encoding="utf-8") + print(f"wrote {args.output.relative_to(REPO_ROOT)} from {provenance}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/aws/test_regen_dynamodb_shapes.py b/tools/aws/test_regen_dynamodb_shapes.py new file mode 100644 index 0000000000..a5dfc584ef --- /dev/null +++ b/tools/aws/test_regen_dynamodb_shapes.py @@ -0,0 +1,72 @@ +"""Tests for regen_dynamodb_shapes. + +Run with: pytest tools/aws -q (or: make aws-data-test) +""" +from __future__ import annotations + +import regen_dynamodb_shapes as r + + +MODEL = { + "operations": { + "Scan": {"input": {"shape": "ScanInput"}, "output": {"shape": "ScanOutput"}}, + "DescribeLimits": {"input": {"shape": "DescribeLimitsInput"}}, + "NoInput": {}, + }, + "shapes": { + "ScanInput": {"type": "structure", "members": { + "TableName": {"shape": "TableName"}, + "AttributesToGet": {"shape": "AttributeNameList"}, + "ExclusiveStartKey": {"shape": "Key"}, + }}, + "ScanOutput": {"type": "structure", "members": {"Count": {"shape": "Integer"}}}, + "DescribeLimitsInput": {"type": "structure", "members": {}}, + "TableName": {"type": "string", "min": 3}, + "AttributeNameList": {"type": "list", "member": {"shape": "AttributeName"}}, + "AttributeName": {"type": "string"}, + "Key": {"type": "map", "key": {"shape": "AttributeName"}, "value": {"shape": "AttributeValue"}}, + "AttributeValue": {"type": "structure", "members": {"S": {"shape": "AttributeName"}}}, + "Integer": {"type": "integer"}, + }, +} + + +def test_keeps_only_input_shapes_and_their_types(): + doc = r.build(MODEL, "botocore test") + + assert doc["_source"] == {"generator": "tools/aws/regen_dynamodb_shapes.py", "botocore": "botocore test"} + assert doc["operations"] == {"DescribeLimits": "DescribeLimitsInput", "Scan": "ScanInput"} + assert "ScanOutput" not in doc["shapes"] + assert "Integer" not in doc["shapes"] + assert doc["shapes"]["ScanInput"] == {"type": "structure", "members": { + "TableName": "TableName", "AttributesToGet": "AttributeNameList", "ExclusiveStartKey": "Key"}} + assert doc["shapes"]["TableName"] == {"type": "string"} + assert doc["shapes"]["AttributeNameList"] == {"type": "list", "member": "AttributeName"} + assert doc["shapes"]["Key"] == {"type": "map", "value": "AttributeValue"} + + +def test_check_ignores_provenance(tmp_path, monkeypatch): + output = tmp_path / "shapes.json" + output.write_text(r.render(r.build(MODEL, "botocore 0.0.1 (local/aws/botocore)")), encoding="utf-8") + monkeypatch.setattr(r, "resolve_botocore_data", lambda explicit: (tmp_path, "--botocore-data /elsewhere")) + monkeypatch.setattr(r, "load_model", lambda data: MODEL) + + assert r.main(["--check", "--output", str(output)]) == 0 + + +def test_check_reports_changed_shapes(tmp_path, monkeypatch): + output = tmp_path / "shapes.json" + changed = {**MODEL, "shapes": {**MODEL["shapes"], "TableName": {"type": "integer"}}} + output.write_text(r.render(r.build(changed, "botocore test")), encoding="utf-8") + monkeypatch.setattr(r, "resolve_botocore_data", lambda explicit: (tmp_path, "botocore test")) + monkeypatch.setattr(r, "load_model", lambda data: MODEL) + + assert r.main(["--check", "--output", str(output)]) == 1 + + +def test_output_is_stable(): + first = r.render(r.build(MODEL, "botocore test")) + second = r.render(r.build(MODEL, "botocore test")) + + assert first == second + assert first.endswith("\n")