Skip to content

Commit f64696a

Browse files
authored
Version Bump to V2 SDK (#17)
* Version Bump to V2 SDK * Update version * Update travis yml
1 parent 2369432 commit f64696a

29 files changed

+139
-110
lines changed

.travis.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: ruby
2+
3+
rvm:
4+
- 2.2.2
5+
- 2.3.0
6+
- 2.4.0
7+
8+
sudo: false
9+
10+
env:
11+
- AWS_REGION=foo
12+
13+
script: bundle exec rake
14+
15+
bundler_args: --without docs release repl

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ source 'https://rubygems.org'
1515

1616
gemspec
1717

18-
gem 'rake', '~> 10.0'
18+
gem 'rake', '~> 12.0'
1919

2020
group :documentation do
2121
gem 'yard', '~> 0.0'

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Ruby file using the following method:
3737

3838
require 'aws-sessionstore-dynamodb'
3939

40-
AWS::SessionStore::DynamoDB::Table.create_table
40+
Aws::SessionStore::DynamoDB::Table.create_table
4141

4242
Run the session store as a Rack middleware in the following way:
4343

@@ -46,7 +46,7 @@ Run the session store as a Rack middleware in the following way:
4646

4747
options = { :secret_key => 'SECRET_KEY' }
4848

49-
use AWS::SessionStore::DynamoDB::RackMiddleware.new(options)
49+
use Aws::SessionStore::DynamoDB::RackMiddleware.new(options)
5050
run SomeRackApp
5151

5252
Note that `:secret_key` is a mandatory configuration option that must be set.
@@ -71,7 +71,7 @@ Full API documentation of the library can be found on [RubyDoc.info][1].
7171
### Configuration Options
7272

7373
A number of options are available to be set in
74-
`AWS::SessionStore::DynamoDB::Configuration`, which is used by the
74+
`Aws::SessionStore::DynamoDB::Configuration`, which is used by the
7575
`RackMiddleware` class. These options can be set in the YAML configuration
7676
file in a Rails application (located in `config/sessionstore/dynamodb.yml`),
7777
directly by Ruby code, or through environment variables.
@@ -126,7 +126,7 @@ You can create your own Rake task for garbage collection similar to below:
126126
desc 'Perform Garbage Collection'
127127
task :garbage_collect do |t|
128128
options = {:max_age => 3600*24, max_stale => 5*3600 }
129-
AWS::SessionStore::DynamoDB::GarbageCollection.collect_garbage(options)
129+
Aws::SessionStore::DynamoDB::GarbageCollection.collect_garbage(options)
130130
end
131131

132132
The above example will clear sessions older than one day or that have been
@@ -164,7 +164,7 @@ locking strategy according to your needs:
164164

165165
You can pass in your own error handler for raised exceptions or you can allow
166166
the default error handler to them for you. See the API documentation
167-
on the {AWS::SessionStore::DynamoDB::Errors::BaseHandler} class for more
167+
on the {Aws::SessionStore::DynamoDB::Errors::BaseHandler} class for more
168168
details.
169169

170170
[1]: http://rubydoc.org/gems/aws-sessionstore-dynamodb/frames

aws-sessionstore-dynamodb.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/lib/aws/session_store/dynamo_db/version'
22

33
Gem::Specification.new do |spec|
44
spec.name = "aws-sessionstore-dynamodb"
5-
spec.version = AWS::SessionStore::DynamoDB::VERSION
5+
spec.version = Aws::SessionStore::DynamoDB::VERSION
66
spec.authors = ["Ruby Robinson"]
77
spec.summary = "The Amazon DynamoDB Session Store handles sessions " +
88
"for Ruby web applications using a DynamoDB backend."
@@ -13,6 +13,6 @@ Gem::Specification.new do |spec|
1313
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
1414
spec.require_paths = ["lib"]
1515

16-
spec.add_dependency 'aws-sdk-v1'
17-
spec.add_dependency 'rack', '~> 1.0'
16+
spec.add_dependency 'aws-sdk', '~> 2.0'
17+
spec.add_dependency 'rack', '>= 1.6.4'
1818
end

lib/aws-sessionstore-dynamodb.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# language governing permissions and limitations under the License.
1313

1414

15-
module AWS
15+
module Aws
1616
module SessionStore
1717
module DynamoDB; end
1818
end

lib/aws/session_store/dynamo_db/configuration.rb

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
# language governing permissions and limitations under the License.
1313

1414
require 'yaml'
15-
require 'aws-sdk-v1'
15+
require 'aws-sdk'
1616

17-
module AWS::SessionStore::DynamoDB
17+
module Aws::SessionStore::DynamoDB
1818
# This class provides a Configuration object for all DynamoDB transactions
1919
# by pulling configuration options from Runtime, a YAML file, the ENV and
2020
# default settings.
@@ -66,8 +66,7 @@ class Configuration
6666
:lock_expiry_time => 500,
6767
:lock_retry_delay => 500,
6868
:lock_max_wait_time => 1,
69-
:secret_key => nil,
70-
:api_version => '2012-08-10'
69+
:secret_key => nil
7170
}
7271

7372
# @return [String] Session table name.
@@ -154,7 +153,7 @@ class Configuration
154153
# See AWS DynamoDB documentation for table write_capacity for more
155154
# information on this setting.
156155
# @option options [DynamoDB Client] :dynamo_db_client
157-
# (AWS::DynamoDB::ClientV2) DynamoDB client used to perform database
156+
# (Aws::DynamoDB::Client) DynamoDB client used to perform database
158157
# operations inside of middleware application.
159158
# @option options [Boolean] :raise_errors (false) If true, all errors are
160159
# raised up the stack when default ErrorHandler. If false, Only specified
@@ -203,14 +202,15 @@ def to_hash
203202
# @return [Hash] DDB client.
204203
def gen_dynamo_db_client
205204
client_opts = client_subset(@options)
206-
client = AWS::DynamoDB::Client
205+
client_opts[:user_agent_suffix] = _user_agent(@options.delete(:user_agent_suffix))
206+
client = Aws::DynamoDB::Client
207207
dynamo_db_client = @options[:dynamo_db_client] || client.new(client_opts)
208208
{:dynamo_db_client => dynamo_db_client}
209209
end
210210

211211
# @return [Hash] Default Error Handler
212212
def gen_error_handler
213-
default_handler = AWS::SessionStore::DynamoDB::Errors::DefaultHandler
213+
default_handler = Aws::SessionStore::DynamoDB::Errors::DefaultHandler
214214
error_handler = @options[:error_handler] ||
215215
default_handler.new(@options[:raise_errors])
216216
{:error_handler => error_handler}
@@ -294,5 +294,13 @@ def client_subset(options = {})
294294
opts
295295
end
296296
end
297+
298+
def _user_agent(custom)
299+
if custom
300+
custom
301+
else
302+
" aws-sessionstore/#{VERSION}"
303+
end
304+
end
297305
end
298306
end

lib/aws/session_store/dynamo_db/errors/base_handler.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
# language governing permissions and limitations under the License.
1313

1414

15-
module AWS::SessionStore::DynamoDB::Errors
15+
module Aws::SessionStore::DynamoDB::Errors
1616
# BaseErrorHandler provides an interface for error handlers
17-
# that can be passed in to {AWS::SessionStore::DynamoDB::RackMiddleware}.
17+
# that can be passed in to {Aws::SessionStore::DynamoDB::RackMiddleware}.
1818
# Each error handler must implement a handle_error method.
1919
#
2020
# @example Sample ErrorHandler class
@@ -33,11 +33,11 @@ class BaseHandler
3333
# error up the stack.
3434
# You may reraise the error passed.
3535
#
36-
# @param [AWS::DynamoDB::Errors::Base] error error passed in from
37-
# AWS::SessionStore::DynamoDB::RackMiddleware.
36+
# @param [Aws::DynamoDB::Errors::Base] error error passed in from
37+
# Aws::SessionStore::DynamoDB::RackMiddleware.
3838
# @param [Rack::Request::Environment,nil] env Rack environment
3939
# @return [false] If exception was handled and will not reraise exception.
40-
# @raise [AWS::DynamoDB::Errors] If error has be reraised.
40+
# @raise [Aws::DynamoDB::Errors] If error has be reraised.
4141
def handle_error(error, env = {})
4242
raise NotImplementedError
4343
end

lib/aws/session_store/dynamo_db/errors/default_handler.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
# language governing permissions and limitations under the License.
1313

1414

15-
module AWS::SessionStore::DynamoDB::Errors
15+
module Aws::SessionStore::DynamoDB::Errors
1616
# This class handles errors raised from DynamoDB.
17-
class DefaultHandler < AWS::SessionStore::DynamoDB::Errors::BaseHandler
17+
class DefaultHandler < Aws::SessionStore::DynamoDB::Errors::BaseHandler
1818
# Array of errors that will always be passed up the Rack stack.
1919
HARD_ERRORS = [
20-
AWS::DynamoDB::Errors::ResourceNotFoundException,
21-
AWS::DynamoDB::Errors::ConditionalCheckFailedException,
22-
AWS::SessionStore::DynamoDB::MissingSecretKeyError,
23-
AWS::SessionStore::DynamoDB::LockWaitTimeoutError
20+
Aws::DynamoDB::Errors::ResourceNotFoundException,
21+
Aws::DynamoDB::Errors::ConditionalCheckFailedException,
22+
Aws::SessionStore::DynamoDB::MissingSecretKeyError,
23+
Aws::SessionStore::DynamoDB::LockWaitTimeoutError
2424
]
2525

2626
# Determines behavior of DefaultErrorHandler

lib/aws/session_store/dynamo_db/garbage_collection.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313

14-
require 'aws-sdk-v1'
14+
require 'aws-sdk'
1515

16-
module AWS::SessionStore::DynamoDB
16+
module Aws::SessionStore::DynamoDB
1717
# Collects and deletes unwanted sessions based on
1818
# their creation and update dates.
1919
module GarbageCollection
@@ -34,7 +34,7 @@ def collect_garbage(options = {})
3434
# @option (see Configuration#initialize)
3535
# @api private
3636
def load_config(options = {})
37-
AWS::SessionStore::DynamoDB::Configuration.new(options)
37+
Aws::SessionStore::DynamoDB::Configuration.new(options)
3838
end
3939

4040
# Sets scan filter attributes based on attributes specified.

lib/aws/session_store/dynamo_db/invalid_id_error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# language governing permissions and limitations under the License.
1313

1414

15-
module AWS::SessionStore::DynamoDB
15+
module Aws::SessionStore::DynamoDB
1616
class InvalidIDError < RuntimeError
1717
def initialize(msg = "Corrupt Session ID!")
1818
super

lib/aws/session_store/dynamo_db/lock_wait_timeout_error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# language governing permissions and limitations under the License.
1313

1414

15-
module AWS::SessionStore::DynamoDB
15+
module Aws::SessionStore::DynamoDB
1616
class LockWaitTimeoutError < RuntimeError
1717
def initialize(msg = 'Maximum time spent to acquire lock has been exceeded!')
1818
super

lib/aws/session_store/dynamo_db/locking/base.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# language governing permissions and limitations under the License.
1313

1414

15-
module AWS::SessionStore::DynamoDB::Locking
15+
module Aws::SessionStore::DynamoDB::Locking
1616
# This class provides a framework for implementing
1717
# locking strategies.
1818
class Base
@@ -56,7 +56,7 @@ def delete_session(env, sid)
5656
def handle_error(env = nil, &block)
5757
begin
5858
yield
59-
rescue AWS::DynamoDB::Errors::Base => e
59+
rescue Aws::DynamoDB::Errors::ServiceError => e
6060
@config.error_handler.handle_error(e, env)
6161
end
6262
end
@@ -101,7 +101,7 @@ def unpack_data(packed_data)
101101
def table_opts(sid)
102102
{
103103
:table_name => @config.table_name,
104-
:key => {@config.table_key => {:s => sid}}
104+
:key => { @config.table_key => sid }
105105
}
106106
end
107107

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

117117
# Update client with current time attribute.
118118
def updated_at
119-
{ :value => {:n => "#{(Time.now).to_f}"}, :action => "PUT" }
119+
{ :value => "#{(Time.now).to_f}", :action => "PUT" }
120120
end
121121

122122
# Attribute for creation of session.
@@ -132,7 +132,7 @@ def updated_attr
132132
end
133133

134134
def data_attr(session)
135-
{ "data" => {:value => {:s => session}, :action => "PUT"} }
135+
{ "data" => {:value => session, :action => "PUT"} }
136136
end
137137

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

144144
# Expected attributes
145145
def expected_attributes(sid)
146-
{ :expected => {@config.table_key => {:value => {:s => sid}, :exists => true}} }
146+
{ :expected => { @config.table_key => {:value => sid, :exists => true} } }
147147
end
148148

149149
# Attributes to be retrieved via client

lib/aws/session_store/dynamo_db/locking/null.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
# language governing permissions and limitations under the License.
1313

1414

15-
module AWS::SessionStore::DynamoDB::Locking
15+
module Aws::SessionStore::DynamoDB::Locking
1616
# This class gets and sets sessions
1717
# without a locking strategy.
18-
class Null < AWS::SessionStore::DynamoDB::Locking::Base
18+
class Null < Aws::SessionStore::DynamoDB::Locking::Base
1919
# Retrieve session if it exists from the database by id.
2020
# Unpack the data once retrieved from the database.
2121
def get_session_data(env, sid)
@@ -32,8 +32,8 @@ def get_session_opts(sid)
3232

3333
# @return [String] Session data.
3434
def extract_data(env, result = nil)
35-
env['rack.initial_data'] = result[:item]["data"][:s] if result[:item]
36-
unpack_data(result[:item]["data"][:s]) if result[:item]
35+
env['rack.initial_data'] = result[:item]["data"] if result[:item]
36+
unpack_data(result[:item]["data"]) if result[:item]
3737
end
3838

3939
end

lib/aws/session_store/dynamo_db/locking/pessimistic.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
# language governing permissions and limitations under the License.
1313

1414

15-
module AWS::SessionStore::DynamoDB::Locking
15+
module Aws::SessionStore::DynamoDB::Locking
1616
# This class implements a pessimistic locking strategy for the
1717
# DynamoDB session handler. Sessions obtain an exclusive lock
1818
# for reads that is only released when the session is saved.
19-
class Pessimistic < AWS::SessionStore::DynamoDB::Locking::Base
19+
class Pessimistic < Aws::SessionStore::DynamoDB::Locking::Base
2020
WAIT_ERROR =
2121

2222
# Saves the session.
@@ -43,7 +43,7 @@ def get_session_with_lock(env, sid)
4343
exceeded_wait_time?(max_attempt_date)
4444
begin
4545
result = attempt_set_lock(sid)
46-
rescue AWS::DynamoDB::Errors::ConditionalCheckFailedException
46+
rescue Aws::DynamoDB::Errors::ConditionalCheckFailedException
4747
expires_at ||= get_expire_date(sid)
4848
next if expires_at.nil?
4949
result = bust_lock(sid, expires_at)
@@ -58,7 +58,7 @@ def get_session_with_lock(env, sid)
5858
# @raise [Error] When time for attempting to get lock has
5959
# been exceeded.
6060
def exceeded_wait_time?(max_attempt_date)
61-
lock_error = AWS::SessionStore::DynamoDB::LockWaitTimeoutError
61+
lock_error = Aws::SessionStore::DynamoDB::LockWaitTimeoutError
6262
raise lock_error if Time.now.to_f > max_attempt_date
6363
end
6464

@@ -70,15 +70,15 @@ def get_lock_time_opts(sid)
7070
# @return [Time] Time stamp for which the session was locked.
7171
def lock_time(sid)
7272
result = @config.dynamo_db_client.get_item(get_lock_time_opts(sid))
73-
(result[:item]["locked_at"][:n]).to_f if result[:item]["locked_at"]
73+
(result[:item]["locked_at"]).to_f if result[:item]["locked_at"]
7474
end
7575

7676
# @return [String] Session data.
7777
def get_data(env, result)
78-
lock_time = result[:attributes]["locked_at"][:n]
78+
lock_time = result[:attributes]["locked_at"]
7979
env["locked_at"] = (lock_time).to_f
80-
env['rack.initial_data'] = result[:item]["data"][:s] if result[:item]
81-
unpack_data(result[:attributes]["data"][:s])
80+
env['rack.initial_data'] = result[:item]["data"] if result.members.include? :item
81+
unpack_data(result[:attributes]["data"])
8282
end
8383

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

120120
# Time in which session was updated.
121121
def updated_at
122-
{ :value => {:n => "#{(Time.now).to_f}"}, :action => "PUT" }
122+
{ :value => "#{(Time.now).to_f}", :action => "PUT" }
123123
end
124124

125125
# Attributes for locking.
@@ -147,7 +147,7 @@ def add_attr
147147
# Expectation of when lock was set.
148148
def expect_lock_time(env)
149149
{ :expected => {"locked_at" => {
150-
:value => {:n => "#{env["locked_at"]}"}, :exists => true}} }
150+
:value => "#{env["locked_at"]}", :exists => true}} }
151151
end
152152

153153
# Attributes to be retrieved via client

0 commit comments

Comments
 (0)