Skip to content

Bump SDK #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ source 'https://rubygems.org'

gemspec

gem 'rake', '~> 10.0'
gem 'rake', '~> 12.0'

group :documentation do
gem 'yard', '~> 0.0'
Expand Down
4 changes: 2 additions & 2 deletions aws-sessionstore-dynamodb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_dependency 'aws-sdk-v1'
spec.add_dependency 'rack', '~> 1.0'
spec.add_dependency 'aws-sdk', '~> 2.0'
spec.add_dependency 'rack', '>= 1.6.4'
end
9 changes: 4 additions & 5 deletions lib/aws/session_store/dynamo_db/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# language governing permissions and limitations under the License.

require 'yaml'
require 'aws-sdk-v1'
require 'aws-sdk'

module AWS::SessionStore::DynamoDB
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thing I'm unsure about: If we should change the top-level module to be Aws to match the nomenclature across other such libraries. There are valid arguments to both sides of this question.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@awood45 it would be nice to change the top-level module, but I'd do that in it's own PR to make code review simpler which is why I didn't bother for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's reasonable enough. Like I said, there's probably a number of refactors we need to make or want to make before a full release of this. For example, I'm wondering if using Aws::Record wouldn't simplify a ton of this code, now that it exists.

# This class provides a Configuration object for all DynamoDB transactions
Expand Down Expand Up @@ -66,8 +66,7 @@ class Configuration
:lock_expiry_time => 500,
:lock_retry_delay => 500,
:lock_max_wait_time => 1,
:secret_key => nil,
:api_version => '2012-08-10'
:secret_key => nil
}

# @return [String] Session table name.
Expand Down Expand Up @@ -154,7 +153,7 @@ class Configuration
# See AWS DynamoDB documentation for table write_capacity for more
# information on this setting.
# @option options [DynamoDB Client] :dynamo_db_client
# (AWS::DynamoDB::ClientV2) DynamoDB client used to perform database
# (Aws::DynamoDB::Client) DynamoDB client used to perform database
# operations inside of middleware application.
# @option options [Boolean] :raise_errors (false) If true, all errors are
# raised up the stack when default ErrorHandler. If false, Only specified
Expand Down Expand Up @@ -203,7 +202,7 @@ def to_hash
# @return [Hash] DDB client.
def gen_dynamo_db_client
client_opts = client_subset(@options)
client = AWS::DynamoDB::Client
client = Aws::DynamoDB::Client
dynamo_db_client = @options[:dynamo_db_client] || client.new(client_opts)
{:dynamo_db_client => dynamo_db_client}
end
Expand Down
4 changes: 2 additions & 2 deletions lib/aws/session_store/dynamo_db/errors/base_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class BaseHandler
# error up the stack.
# You may reraise the error passed.
#
# @param [AWS::DynamoDB::Errors::Base] error error passed in from
# @param [Aws::DynamoDB::Errors::ServiceError] error error passed in from
# AWS::SessionStore::DynamoDB::RackMiddleware.
# @param [Rack::Request::Environment,nil] env Rack environment
# @return [false] If exception was handled and will not reraise exception.
# @raise [AWS::DynamoDB::Errors] If error has be reraised.
# @raise [Aws::DynamoDB::Errors] If error has be reraised.
def handle_error(error, env = {})
raise NotImplementedError
end
Expand Down
4 changes: 2 additions & 2 deletions lib/aws/session_store/dynamo_db/errors/default_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ module AWS::SessionStore::DynamoDB::Errors
class DefaultHandler < AWS::SessionStore::DynamoDB::Errors::BaseHandler
# Array of errors that will always be passed up the Rack stack.
HARD_ERRORS = [
AWS::DynamoDB::Errors::ResourceNotFoundException,
AWS::DynamoDB::Errors::ConditionalCheckFailedException,
Aws::DynamoDB::Errors::ResourceNotFoundException,
Aws::DynamoDB::Errors::ConditionalCheckFailedException,
AWS::SessionStore::DynamoDB::MissingSecretKeyError,
AWS::SessionStore::DynamoDB::LockWaitTimeoutError
]
Expand Down
2 changes: 1 addition & 1 deletion lib/aws/session_store/dynamo_db/garbage_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

require 'aws-sdk-v1'
require 'aws-sdk'

module AWS::SessionStore::DynamoDB
# Collects and deletes unwanted sessions based on
Expand Down
10 changes: 5 additions & 5 deletions lib/aws/session_store/dynamo_db/locking/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def delete_session(env, sid)
def handle_error(env = nil, &block)
begin
yield
rescue AWS::DynamoDB::Errors::Base => e
rescue Aws::DynamoDB::Errors::ServiceError => e
@config.error_handler.handle_error(e, env)
end
end
Expand Down Expand Up @@ -101,7 +101,7 @@ def unpack_data(packed_data)
def table_opts(sid)
{
:table_name => @config.table_name,
:key => {@config.table_key => {:s => sid}}
:key => { @config.table_key => sid }
}
end

Expand All @@ -116,7 +116,7 @@ def attr_updts(env, session, add_attrs = {})

# Update client with current time attribute.
def updated_at
{ :value => {:n => "#{(Time.now).to_f}"}, :action => "PUT" }
{ :value => "#{(Time.now).to_f}", :action => "PUT" }
end

# Attribute for creation of session.
Expand All @@ -132,7 +132,7 @@ def updated_attr
end

def data_attr(session)
{ "data" => {:value => {:s => session}, :action => "PUT"} }
{ "data" => {:value => session, :action => "PUT"} }
end

# Determine if data has been manipulated
Expand All @@ -143,7 +143,7 @@ def data_unchanged?(env, session)

# Expected attributes
def expected_attributes(sid)
{ :expected => {@config.table_key => {:value => {:s => sid}, :exists => true}} }
{ :expected => {@config.table_key => {:value => sid, :exists => true}} }
end

# Attributes to be retrieved via client
Expand Down
6 changes: 2 additions & 4 deletions lib/aws/session_store/dynamo_db/locking/null.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.


module AWS::SessionStore::DynamoDB::Locking
# This class gets and sets sessions
# without a locking strategy.
Expand All @@ -32,9 +31,8 @@ def get_session_opts(sid)

# @return [String] Session data.
def extract_data(env, result = nil)
env['rack.initial_data'] = result[:item]["data"][:s] if result[:item]
unpack_data(result[:item]["data"][:s]) if result[:item]
env['rack.initial_data'] = result[:item]['data'] if result[:item]
unpack_data(result[:item]['data']) if result[:item]
end

end
end
14 changes: 7 additions & 7 deletions lib/aws/session_store/dynamo_db/locking/pessimistic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_session_with_lock(env, sid)
exceeded_wait_time?(max_attempt_date)
begin
result = attempt_set_lock(sid)
rescue AWS::DynamoDB::Errors::ConditionalCheckFailedException
rescue Aws::DynamoDB::Errors::ConditionalCheckFailedException
expires_at ||= get_expire_date(sid)
next if expires_at.nil?
result = bust_lock(sid, expires_at)
Expand All @@ -70,15 +70,15 @@ def get_lock_time_opts(sid)
# @return [Time] Time stamp for which the session was locked.
def lock_time(sid)
result = @config.dynamo_db_client.get_item(get_lock_time_opts(sid))
(result[:item]["locked_at"][:n]).to_f if result[:item]["locked_at"]
result[:item]["locked_at"].to_f if result[:item]["locked_at"]
end

# @return [String] Session data.
def get_data(env, result)
lock_time = result[:attributes]["locked_at"][:n]
lock_time = result[:attributes]["locked_at"]
env["locked_at"] = (lock_time).to_f
env['rack.initial_data'] = result[:item]["data"][:s] if result[:item]
unpack_data(result[:attributes]["data"][:s])
env['rack.initial_data'] = result[:item]["data"] if result[:item]
unpack_data(result[:attributes]["data"])
end

# Attempt to bust the lock if the expiration date has expired.
Expand Down Expand Up @@ -119,7 +119,7 @@ def lock_attr

# Time in which session was updated.
def updated_at
{ :value => {:n => "#{(Time.now).to_f}"}, :action => "PUT" }
{ :value => Time.now.to_f.to_s, :action => "PUT" }
end

# Attributes for locking.
Expand Down Expand Up @@ -147,7 +147,7 @@ def add_attr
# Expectation of when lock was set.
def expect_lock_time(env)
{ :expected => {"locked_at" => {
:value => {:n => "#{env["locked_at"]}"}, :exists => true}} }
:value => env["locked_at"].to_s, :exists => true}} }
end

# Attributes to be retrieved via client
Expand Down
8 changes: 4 additions & 4 deletions lib/aws/session_store/dynamo_db/rack_middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

require 'rack/session/abstract/id'
require 'openssl'
require 'aws-sdk-v1'
require 'aws-sdk'

module AWS::SessionStore::DynamoDB
# This class is an ID based Session Store Rack Middleware
Expand All @@ -24,7 +24,7 @@ class RackMiddleware < Rack::Session::Abstract::ID
#
# @param app Rack application.
# @option (see Configuration#initialize)
# @raise [AWS::DynamoDB::Errors::ResourceNotFoundException] If valid table
# @raise [Aws::DynamoDB::Errors::ResourceNotFoundException] If valid table
# name is not provided.
# @raise [AWS::SessionStore::DynamoDB::MissingSecretKey] If secret key is
# not provided.
Expand All @@ -51,7 +51,7 @@ def set_locking_strategy
# Determines if the correct session table name is being used for
# this application. Also tests existence of secret key.
#
# @raise [AWS::DynamoDB::Errors::ResourceNotFoundException] If wrong table
# @raise [Aws::DynamoDB::Errors::ResourceNotFoundException] If wrong table
# name.
def validate_config
raise MissingSecretKeyError unless @config.secret_key
Expand Down Expand Up @@ -99,7 +99,7 @@ def destroy_session(env, sid, options)
def handle_error(env = nil, &block)
begin
yield
rescue AWS::DynamoDB::Errors::Base,
rescue Aws::DynamoDB::Errors::ServiceError,
AWS::SessionStore::DynamoDB::InvalidIDError => e
@config.error_handler.handle_error(e, env)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/aws/session_store/dynamo_db/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

require 'aws-sdk-v1'
require 'aws-sdk'
require 'logger'

module AWS::SessionStore::DynamoDB
Expand All @@ -30,7 +30,7 @@ def create_table(options = {})
logger << "Table #{config.table_name} created, waiting for activation...\n"
block_until_created(config)
logger << "Table #{config.table_name} is now ready to use.\n"
rescue AWS::DynamoDB::Errors::ResourceInUseException
rescue Aws::DynamoDB::Errors::ResourceInUseException
logger << "Table #{config.table_name} already exists, skipping creation.\n"
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

let(:base_app) { MultiplierApplication.new }
let(:app) { AWS::SessionStore::DynamoDB::RackMiddleware.new(base_app, @options) }
let(:client) { double('AWS::DynamoDB::Client') }
let(:client) { double('Aws::DynamoDB::Client') }

context "Error handling for Rack Middleware with default error handler" do
it "raises error for missing secret key" do
Expand All @@ -41,8 +41,8 @@
it "catches exception for inaccurate table key" do
client.stub(:update_item).and_raise(key_error)
client.stub(:get_item).and_raise(key_error)
get "/"
last_request.env["rack.errors"].string.should include(key_error_msg)
get '/'
last_request.env['rack.errors'].string.should include(key_error_msg)
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/aws/session_store/dynamo_db/garbage_collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def collect_garbage
}
}

let(:dynamo_db_client) {AWS::DynamoDB::Client.new}
let(:dynamo_db_client) { Aws::DynamoDB::Client.new }

context "Mock DynamoDB client with garbage collection" do

Expand All @@ -113,7 +113,7 @@ def collect_garbage
dynamo_db_client.should_receive(:scan).
exactly(1).times.and_return(scan_resp2)
dynamo_db_client.should_receive(:scan).
exactly(1).times.with(hash_including({:exclusive_start_key => scan_resp2.last_evaluated_key})).
exactly(1).times.with(hash_including(exclusive_start_key: scan_resp2[:last_evaluated_key])).
and_return(scan_resp3)
dynamo_db_client.should_receive(:batch_write_item).
exactly(3).times.and_return(write_resp1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def update_item_mock(options, update_method)
get "/"
last_request.session[:multiplier].should eq(1)

t1 = thread_exception(AWS::DynamoDB::Errors::ConditionalCheckFailedException)
t1 = thread_exception(Aws::DynamoDB::Errors::ConditionalCheckFailedException)
t2 = thread(2, 0.25, true)
t1.join
t2.join
Expand Down
6 changes: 3 additions & 3 deletions spec/aws/session_store/dynamo_db/rack_middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def ensure_data_updated(mutated_data)
end

let(:dynamo_db_client) do
client = double('AWS::DynamoDB::Client')
client = double('Aws::DynamoDB::Client')
client.stub(:delete_item) { 'Deleted' }
client.stub(:list_tables) { {:table_names => ['Sessions']} }
client.stub(:get_item) do
{ :item => { 'data' => { :s => sample_packed_data } } }
{ :item => { 'data' => sample_packed_data } }
end
client.stub(:update_item) do
{ :attributes => { :created_at => 'now' } }
Expand All @@ -67,7 +67,7 @@ def ensure_data_updated(mutated_data)
it "creates a new HTTP cookie when Cookie not supplied" do
get "/"
last_response.body.should eq('All good!')
last_response['Set-Cookie'].should be_true
last_response['Set-Cookie'].should be_truthy
end

it "loads/manipulates a session based on id from HTTP-Cookie" do
Expand Down
6 changes: 3 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ def call(env)

ConstantHelpers = lambda do
let(:token_error_msg) { 'The security token included in the request is invalid' }
let(:resource_error) { AWS::DynamoDB::Errors::ResourceNotFoundException }
let(:key_error) { AWS::DynamoDB::Errors::ValidationException.new(key_error_msg) }
let(:resource_error) { Aws::DynamoDB::Errors::ResourceNotFoundException.new(double('Seahorse::Client::RequestContext'), 'Resource not found.') }
let(:key_error) { Aws::DynamoDB::Errors::ValidationException.new(double('Seahorse::Client::RequestContext'), key_error_msg) }
let(:key_error_msg) { 'The provided key element does not match the schema' }
let(:client_error) { AWS::DynamoDB::Errors::UnrecognizedClientException }
let(:client_error) { Aws::DynamoDB::Errors::UnrecognizedClientException.new(double('Seahorse::Client::RequestContext'), 'Unrecognized Client.') }
let(:invalid_cookie) { {"HTTP_COOKIE" => "rack.session=ApplePieBlueberries"} }
let(:invalid_session_data) { {"rack.session"=>{"multiplier" => 1}} }
let(:rack_default_error_msg) { "Warning! AWS::SessionStore::DynamoDB failed to save session. Content dropped.\n" }
Expand Down