Skip to content

Commit cb38b39

Browse files
authored
New MV (#26)
1 parent bd7e28b commit cb38b39

37 files changed

+351
-825
lines changed

.travis.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
branches:
2+
only:
3+
- master
4+
15
language: ruby
26

37
rvm:
@@ -17,6 +21,6 @@ sudo: false
1721
env:
1822
- AWS_REGION=us-west-2
1923

20-
script: bundle exec rake test
24+
script: bundle exec rake test:unit
2125

2226
bundler_args: --without docs release repl

CHANGELOG.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Unreleased Changes
2+
------------------
3+
4+
* Remove Rails support (moved to the `aws-sdk-rails` gem).
5+
6+
* Use V3 of Ruby SDK
7+
8+
* Fix a `dynamo_db.scan()` incompatibility from the V1 -> V2 upgrade in the garbage collector.
9+
10+
1.0.0 (2017-08-14)
11+
------------------
12+
13+
* Use V2 of Ruby SDK (no history)
14+
15+
16+
0.5.1 (2015-08-26)
17+
------------------
18+
19+
* Bug Fix (no history)
20+
21+
0.5.0 (2013-08-27)
22+
------------------
23+
24+
* Initial Release (no history)

LICENSE.txt renamed to LICENSE

File renamed without changes.

README.md

+17-63
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,12 @@
11
# Amazon DynamoDB Session Store
22

33
The **Amazon DynamoDB Session Store** handles sessions for Ruby web applications
4-
using a DynamoDB backend. The session store is compatible with Rails (3.x or 4.x)
5-
and other Rack based frameworks.
4+
using a DynamoDB backend. The session store is compatible with all Rack based
5+
frameworks. For Rails applications, use the [`aws-sdk-rails`][1] gem.
66

77
## Installation
88

9-
#### Rails Installation
10-
11-
Install the session store gem by placing the following command into your
12-
Gemfile:
13-
14-
gem 'aws-sessionstore-dynamodb'
15-
16-
You will need to have an existing Amazon DynamoDB session table in order for the
17-
application to work. You can generate a migration file for the session table
18-
with the following command:
19-
20-
rails generate sessionstore:dynamodb
21-
22-
To create the table, run migrations as normal with:
23-
24-
rake db:migrate
25-
26-
Change the session store to `:dynamodb_store` by editing
27-
`config/initializers/session_store.rb` to contain the following:
28-
29-
YourAppName::Application.config.session_store :dynamodb_store
30-
31-
You can now start your Rails application with session support.
32-
33-
#### Basic Rack Application Installation
34-
35-
For non-Rails applications, you can create the Amazon DynamoDB table in a
9+
For Rack applications, you can create the Amazon DynamoDB table in a
3610
Ruby file using the following method:
3711

3812
require 'aws-sessionstore-dynamodb'
@@ -66,18 +40,17 @@ discouraging sensitive data storage. It also forces strict data size
6640
limitations. DynamoDB takes care of these concerns by allowing for a safe and
6741
scalable storage container with a much larger data size limit for session data.
6842

69-
Full API documentation of the library can be found on [RubyDoc.info][1].
43+
For more developer information, see the [Full API documentation][2].
7044

7145
### Configuration Options
7246

7347
A number of options are available to be set in
7448
`Aws::SessionStore::DynamoDB::Configuration`, which is used by the
75-
`RackMiddleware` class. These options can be set in the YAML configuration
76-
file in a Rails application (located in `config/sessionstore/dynamodb.yml`),
77-
directly by Ruby code, or through environment variables.
49+
`RackMiddleware` class. These options can be set directly by Ruby code or
50+
through environment variables.
7851

7952
The full set of options along with defaults can be found in the
80-
[Configuration class documentation][2].
53+
[Configuration class documentation][3].
8154

8255
#### Environment Options
8356

@@ -90,36 +63,15 @@ The example below would be a valid way to set the session table name:
9063

9164
export DYNAMO_DB_SESSION_TABLE_NAME='sessions'
9265

93-
### Rails Generator Details
94-
95-
The generator command specified in the installation section will generate two
96-
files: a migration file, `db/migration/VERSION_migration_name.rb`, and a
97-
configuration YAML file, `config/sessionstore/dynamodb.yml`.
98-
99-
You can run the command with an argument that will define the name of the
100-
migration file. Once the YAML file is created, you can uncomment any of the
101-
lines to set configuration options to your liking. The session store will pull
102-
options from `config/sessionstore/dynamodb.yml` by default if the file exists.
103-
If you do not wish to place the configuration YAML file in that location,
104-
you can also pass in a different file path to pull options from.
105-
10666
### Garbage Collection
10767

108-
You may want to delete old sessions from your session table. The
109-
following examples show how to clear old sessions from your table.
110-
111-
#### Rails
112-
113-
A Rake task for garbage collection is provided for Rails applications.
114-
By default sessions do not expire. See `config/sessionstore/dynamodb.yml` to
115-
configure the max age or stale period of a session. Once you have configured
116-
those values you can clear the old sessions with:
117-
118-
rake dynamo_db:collect_garbage
119-
120-
#### Outside of Rails
68+
You may want to delete old sessions from your session table. You can use the
69+
DynamoDB [Time to Live (TTL) feature][4] on the `expire_at` attribute to
70+
automatically delete expired items.
12171

122-
You can create your own Rake task for garbage collection similar to below:
72+
If you want to take other attributes into consideration for deletion, you could
73+
instead use the `GarbageCollection` class. You can create your own Rake task for
74+
garbage collection similar to below:
12375

12476
require "aws-sessionstore-dynamodb"
12577

@@ -167,5 +119,7 @@ the default error handler to them for you. See the API documentation
167119
on the {Aws::SessionStore::DynamoDB::Errors::BaseHandler} class for more
168120
details.
169121

170-
[1]: http://rubydoc.org/gems/aws-sessionstore-dynamodb/frames
171-
[2]: http://rubydoc.org/gems/aws-sessionstore-dynamodb/AWS/SessionStore/DynamoDB/Configuration#initialize-instance_method
122+
[1]: https://github.com/aws/aws-sdk-rails/
123+
[2]: https://docs.aws.amazon.com/sdk-for-ruby/aws-sessionstore-dynamodb/api/
124+
[3]: https://docs.aws.amazon.com/sdk-for-ruby/aws-sessionstore-dynamodb/api/Aws/SessionStore/DynamoDB/Configuration.html
125+
[4]: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html

Rakefile

+20-4
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,37 @@ $REPO_ROOT = File.dirname(__FILE__)
22
$LOAD_PATH.unshift(File.join($REPO_ROOT, 'lib'))
33
$VERSION = ENV['VERSION'] || File.read(File.join($REPO_ROOT, 'VERSION')).strip
44

5+
require 'rspec/core/rake_task'
6+
7+
Dir.glob('**/*.rake').each do |task_file|
8+
load task_file
9+
end
10+
511
task 'test:coverage:clear' do
612
sh("rm -rf #{File.join($REPO_ROOT, 'coverage')}")
713
end
814

15+
# Override the test task definitions
16+
# this package uses rspec tags to define integration tests
17+
Rake::Task["test:unit"].clear
918
desc 'Runs unit tests'
19+
RSpec::Core::RakeTask.new('test:unit') do |t|
20+
t.rspec_opts = "-I #{$REPO_ROOT}/lib -I #{$REPO_ROOT}/spec --tag ~integration"
21+
t.pattern = "#{$REPO_ROOT}/spec"
22+
end
1023
task 'test:unit' => 'test:coverage:clear'
1124

25+
Rake::Task["test:integration"].clear
1226
desc 'Runs integration tests'
27+
RSpec::Core::RakeTask.new('test:integration') do |t|
28+
t.rspec_opts = "-I #{$REPO_ROOT}/lib -I #{$REPO_ROOT}/spec --tag integration"
29+
t.pattern = "#{$REPO_ROOT}/spec"
30+
end
1331
task 'test:integration' => 'test:coverage:clear'
1432

1533
desc 'Runs unit and integration tests'
1634
task 'test' => ['test:unit', 'test:integration']
1735

18-
task :default => :test
36+
task :default => 'test:unit'
37+
1938

20-
Dir.glob('**/*.rake').each do |task_file|
21-
load task_file
22-
end

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0
1+
2.0.0

lib/aws-sessionstore-dynamodb.rb

-15
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License"). You
4-
# may not use this file except in compliance with the License. A copy of
5-
# the License is located at
6-
#
7-
# http://aws.amazon.com/apache2.0/
8-
#
9-
# or in the "license" file accompanying this file. This file is
10-
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11-
# ANY KIND, either express or implied. See the License for the specific
12-
# language governing permissions and limitations under the License.
13-
14-
151
module Aws
162
module SessionStore
173
module DynamoDB; end
@@ -31,4 +17,3 @@ module DynamoDB; end
3117
require 'aws/session_store/dynamo_db/rack_middleware'
3218
require 'aws/session_store/dynamo_db/table'
3319
require 'aws/session_store/dynamo_db/version'
34-
require 'aws/session_store/dynamo_db/railtie' if defined?(Rails)

lib/aws/session_store/dynamo_db/configuration.rb

+1-28
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License"). You
4-
# may not use this file except in compliance with the License. A copy of
5-
# the License is located at
6-
#
7-
# http://aws.amazon.com/apache2.0/
8-
#
9-
# or in the "license" file accompanying this file. This file is
10-
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11-
# ANY KIND, either express or implied. See the License for the specific
12-
# language governing permissions and limitations under the License.
13-
141
require 'yaml'
152
require 'aws-sdk-dynamodb'
163

@@ -240,24 +227,15 @@ def file_options(options = {})
240227
file_path = config_file_path(options)
241228
if file_path
242229
load_from_file(file_path)
243-
elsif rails_defined && File.exists?(rails_config_file_path)
244-
load_from_file(rails_config_file_path)
245230
else
246231
{}
247232
end
248233
end
249234

250-
# @return [Boolean] Necessary Rails variables defined.
251-
def rails_defined
252-
defined?(Rails) && defined?(Rails.root) && defined?(Rails.env)
253-
end
254-
255-
# Load options from YAML file depending on existence of Rails
256-
# and possible development stage defined.
235+
# Load options from YAML file
257236
def load_from_file(file_path)
258237
require "erb"
259238
opts = YAML.load(ERB.new(File.read(file_path)).result) || {}
260-
opts = opts[Rails.env] if rails_defined && opts.key?(Rails.env)
261239
symbolize_keys(opts)
262240
end
263241

@@ -266,11 +244,6 @@ def config_file_path(options)
266244
options[:config_file] || ENV["DYNAMO_DB_SESSION_CONFIG_FILE"]
267245
end
268246

269-
# @return [String] Rails configuraton path to YAML file default.
270-
def rails_config_file_path
271-
File.join(Rails.root, "config", "sessionstore/dynamodb.yml")
272-
end
273-
274247
# Set accessible attributes after merged options.
275248
def set_attributes(options)
276249
@options.keys.each do |opt_name|

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

-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License"). You
4-
# may not use this file except in compliance with the License. A copy of
5-
# the License is located at
6-
#
7-
# http://aws.amazon.com/apache2.0/
8-
#
9-
# or in the "license" file accompanying this file. This file is
10-
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11-
# ANY KIND, either express or implied. See the License for the specific
12-
# language governing permissions and limitations under the License.
13-
14-
151
module Aws::SessionStore::DynamoDB::Errors
162
# BaseErrorHandler provides an interface for error handlers
173
# that can be passed in to {Aws::SessionStore::DynamoDB::RackMiddleware}.

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

-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License"). You
4-
# may not use this file except in compliance with the License. A copy of
5-
# the License is located at
6-
#
7-
# http://aws.amazon.com/apache2.0/
8-
#
9-
# or in the "license" file accompanying this file. This file is
10-
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11-
# ANY KIND, either express or implied. See the License for the specific
12-
# language governing permissions and limitations under the License.
13-
14-
151
module Aws::SessionStore::DynamoDB::Errors
162
# This class handles errors raised from DynamoDB.
173
class DefaultHandler < Aws::SessionStore::DynamoDB::Errors::BaseHandler

lib/aws/session_store/dynamo_db/garbage_collection.rb

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License"). You
4-
# may not use this file except in compliance with the License. A copy of
5-
# the License is located at
6-
#
7-
# http://aws.amazon.com/apache2.0/
8-
#
9-
# or in the "license" file accompanying this file. This file is
10-
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11-
# ANY KIND, either express or implied. See the License for the specific
12-
# language governing permissions and limitations under the License.
13-
141
require 'aws-sdk-dynamodb'
152

163
module Aws::SessionStore::DynamoDB
@@ -50,7 +37,7 @@ def scan_filter(config)
5037
# @api private
5138
def eliminate_unwanted_sessions(config, last_key = nil)
5239
scan_result = scan(config, last_key)
53-
batch_delete(config, scan_result[:member])
40+
batch_delete(config, scan_result[:items])
5441
scan_result[:last_evaluated_key] || {}
5542
end
5643

lib/aws/session_store/dynamo_db/invalid_id_error.rb

-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License"). You
4-
# may not use this file except in compliance with the License. A copy of
5-
# the License is located at
6-
#
7-
# http://aws.amazon.com/apache2.0/
8-
#
9-
# or in the "license" file accompanying this file. This file is
10-
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11-
# ANY KIND, either express or implied. See the License for the specific
12-
# language governing permissions and limitations under the License.
13-
14-
151
module Aws::SessionStore::DynamoDB
162
class InvalidIDError < RuntimeError
173
def initialize(msg = "Corrupt Session ID!")

lib/aws/session_store/dynamo_db/lock_wait_timeout_error.rb

-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License"). You
4-
# may not use this file except in compliance with the License. A copy of
5-
# the License is located at
6-
#
7-
# http://aws.amazon.com/apache2.0/
8-
#
9-
# or in the "license" file accompanying this file. This file is
10-
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11-
# ANY KIND, either express or implied. See the License for the specific
12-
# language governing permissions and limitations under the License.
13-
14-
151
module Aws::SessionStore::DynamoDB
162
class LockWaitTimeoutError < RuntimeError
173
def initialize(msg = 'Maximum time spent to acquire lock has been exceeded!')

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

-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License"). You
4-
# may not use this file except in compliance with the License. A copy of
5-
# the License is located at
6-
#
7-
# http://aws.amazon.com/apache2.0/
8-
#
9-
# or in the "license" file accompanying this file. This file is
10-
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11-
# ANY KIND, either express or implied. See the License for the specific
12-
# language governing permissions and limitations under the License.
13-
14-
151
module Aws::SessionStore::DynamoDB::Locking
162
# This class provides a framework for implementing
173
# locking strategies.

0 commit comments

Comments
 (0)