From b190a36857adaf9f99a163070e0f684381d220aa Mon Sep 17 00:00:00 2001 From: Damien Mathieu Date: Wed, 23 Dec 2015 16:24:02 +0100 Subject: [PATCH] deprecate but fallback to older api support --- lib/fog/aws/requests/dynamodb/query.rb | 14 +++++++++++--- lib/fog/aws/requests/dynamodb/update_item.rb | 12 ++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/fog/aws/requests/dynamodb/query.rb b/lib/fog/aws/requests/dynamodb/query.rb index 9f8cb11bc..536ae6637 100644 --- a/lib/fog/aws/requests/dynamodb/query.rb +++ b/lib/fog/aws/requests/dynamodb/query.rb @@ -26,14 +26,22 @@ module Fog # # See DynamoDB Documentation: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html # - def query(table_name, options = {}) + def query(table_name, options = {}, hash_key_deprecated = nil) + if hash_key_deprecated || (options.keys.length == 1 && [:S, :N, :B].include?(options.keys.first.to_sym)) + Fog::Logger.deprecation("The `20111205` API version is deprecated. You need to use `KeyConditionExpression` instead of `HashKey`.") + apiVersion = '20111205' + hash_key = options + options = hash_key_deprecated + end + body = { - 'TableName' => table_name + 'TableName' => table_name, + 'HashKeyValue' => hash_key }.merge(options) request( :body => Fog::JSON.encode(body), - :headers => {'x-amz-target' => 'DynamoDB_20120810.Query'} + :headers => {'x-amz-target' => "DynamoDB_#{apiVersion || '20120810'}.Query"} ) end end diff --git a/lib/fog/aws/requests/dynamodb/update_item.rb b/lib/fog/aws/requests/dynamodb/update_item.rb index 6b0c8c88d..081ca534c 100644 --- a/lib/fog/aws/requests/dynamodb/update_item.rb +++ b/lib/fog/aws/requests/dynamodb/update_item.rb @@ -2,6 +2,7 @@ module Fog module AWS class DynamoDB class Real + class DeprecatedAttributeUpdates < Exception; end # Update DynamoDB item # # ==== Parameters @@ -24,10 +25,17 @@ module Fog # # See DynamoDB Documentation: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html # - def update_item(table_name, key, options = {}) + def update_item(table_name, key, options = {}, deprecated_attribute_updates = nil) + if deprecated_attribute_updates + raise DeprecatedAttributeUpdates, "The `20111205` DynamoDB API is deprecated. You need to use `ExpressionAttributeValues` instead of `AttributeUpdates`." + attribute_updates = options + options = deprecated_attribute_updates + end + body = { 'Key' => key, - 'TableName' => table_name + 'TableName' => table_name, + 'AttributeUpdates' => attribute_updates, }.merge(options) request(