Skip to content

New MV #26

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

Merged
merged 9 commits into from
Nov 11, 2020
Merged
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
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
branches:
only:
- master

language: ruby

rvm:
Expand All @@ -17,6 +21,6 @@ sudo: false
env:
- AWS_REGION=us-west-2

script: bundle exec rake test
script: bundle exec rake test:unit

bundler_args: --without docs release repl
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Unreleased Changes
------------------

* Remove Rails support (moved to the `aws-sdk-rails` gem).

* Use V3 of Ruby SDK

* Fix a `dynamo_db.scan()` incompatibility from the V1 -> V2 upgrade in the garbage collector.

1.0.0 (2017-08-14)
------------------

* Use V2 of Ruby SDK (no history)


0.5.1 (2015-08-26)
------------------

* Bug Fix (no history)

0.5.0 (2013-08-27)
------------------

* Initial Release (no history)
File renamed without changes.
80 changes: 17 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,12 @@
# Amazon DynamoDB Session Store

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

## Installation

#### Rails Installation

Install the session store gem by placing the following command into your
Gemfile:

gem 'aws-sessionstore-dynamodb'

You will need to have an existing Amazon DynamoDB session table in order for the
application to work. You can generate a migration file for the session table
with the following command:

rails generate sessionstore:dynamodb

To create the table, run migrations as normal with:

rake db:migrate

Change the session store to `:dynamodb_store` by editing
`config/initializers/session_store.rb` to contain the following:

YourAppName::Application.config.session_store :dynamodb_store

You can now start your Rails application with session support.

#### Basic Rack Application Installation

For non-Rails applications, you can create the Amazon DynamoDB table in a
For Rack applications, you can create the Amazon DynamoDB table in a
Ruby file using the following method:

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

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

### Configuration Options

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

The full set of options along with defaults can be found in the
[Configuration class documentation][2].
[Configuration class documentation][3].

#### Environment Options

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

export DYNAMO_DB_SESSION_TABLE_NAME='sessions'

### Rails Generator Details

The generator command specified in the installation section will generate two
files: a migration file, `db/migration/VERSION_migration_name.rb`, and a
configuration YAML file, `config/sessionstore/dynamodb.yml`.

You can run the command with an argument that will define the name of the
migration file. Once the YAML file is created, you can uncomment any of the
lines to set configuration options to your liking. The session store will pull
options from `config/sessionstore/dynamodb.yml` by default if the file exists.
If you do not wish to place the configuration YAML file in that location,
you can also pass in a different file path to pull options from.

### Garbage Collection

You may want to delete old sessions from your session table. The
following examples show how to clear old sessions from your table.

#### Rails

A Rake task for garbage collection is provided for Rails applications.
By default sessions do not expire. See `config/sessionstore/dynamodb.yml` to
configure the max age or stale period of a session. Once you have configured
those values you can clear the old sessions with:

rake dynamo_db:collect_garbage

#### Outside of Rails
You may want to delete old sessions from your session table. You can use the
DynamoDB [Time to Live (TTL) feature][4] on the `expire_at` attribute to
automatically delete expired items.

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

require "aws-sessionstore-dynamodb"

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

[1]: http://rubydoc.org/gems/aws-sessionstore-dynamodb/frames
[2]: http://rubydoc.org/gems/aws-sessionstore-dynamodb/AWS/SessionStore/DynamoDB/Configuration#initialize-instance_method
[1]: https://github.com/aws/aws-sdk-rails/
[2]: https://docs.aws.amazon.com/sdk-for-ruby/aws-sessionstore-dynamodb/api/
[3]: https://docs.aws.amazon.com/sdk-for-ruby/aws-sessionstore-dynamodb/api/Aws/SessionStore/DynamoDB/Configuration.html
[4]: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html
24 changes: 20 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,37 @@ $REPO_ROOT = File.dirname(__FILE__)
$LOAD_PATH.unshift(File.join($REPO_ROOT, 'lib'))
$VERSION = ENV['VERSION'] || File.read(File.join($REPO_ROOT, 'VERSION')).strip

require 'rspec/core/rake_task'

Dir.glob('**/*.rake').each do |task_file|
load task_file
end

task 'test:coverage:clear' do
sh("rm -rf #{File.join($REPO_ROOT, 'coverage')}")
end

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

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

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

task :default => :test
task :default => 'test:unit'


Dir.glob('**/*.rake').each do |task_file|
load task_file
end
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
2.0.0
15 changes: 0 additions & 15 deletions lib/aws-sessionstore-dynamodb.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.


module Aws
module SessionStore
module DynamoDB; end
Expand All @@ -31,4 +17,3 @@ module DynamoDB; end
require 'aws/session_store/dynamo_db/rack_middleware'
require 'aws/session_store/dynamo_db/table'
require 'aws/session_store/dynamo_db/version'
require 'aws/session_store/dynamo_db/railtie' if defined?(Rails)
29 changes: 1 addition & 28 deletions lib/aws/session_store/dynamo_db/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

require 'yaml'
require 'aws-sdk-dynamodb'

Expand Down Expand Up @@ -240,24 +227,15 @@ def file_options(options = {})
file_path = config_file_path(options)
if file_path
load_from_file(file_path)
elsif rails_defined && File.exists?(rails_config_file_path)
load_from_file(rails_config_file_path)
else
{}
end
end

# @return [Boolean] Necessary Rails variables defined.
def rails_defined
defined?(Rails) && defined?(Rails.root) && defined?(Rails.env)
end

# Load options from YAML file depending on existence of Rails
# and possible development stage defined.
# Load options from YAML file
def load_from_file(file_path)
require "erb"
opts = YAML.load(ERB.new(File.read(file_path)).result) || {}
opts = opts[Rails.env] if rails_defined && opts.key?(Rails.env)
symbolize_keys(opts)
end

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

# @return [String] Rails configuraton path to YAML file default.
def rails_config_file_path
File.join(Rails.root, "config", "sessionstore/dynamodb.yml")
end

# Set accessible attributes after merged options.
def set_attributes(options)
@options.keys.each do |opt_name|
Expand Down
14 changes: 0 additions & 14 deletions lib/aws/session_store/dynamo_db/errors/base_handler.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.


module Aws::SessionStore::DynamoDB::Errors
# BaseErrorHandler provides an interface for error handlers
# that can be passed in to {Aws::SessionStore::DynamoDB::RackMiddleware}.
Expand Down
14 changes: 0 additions & 14 deletions lib/aws/session_store/dynamo_db/errors/default_handler.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.


module Aws::SessionStore::DynamoDB::Errors
# This class handles errors raised from DynamoDB.
class DefaultHandler < Aws::SessionStore::DynamoDB::Errors::BaseHandler
Expand Down
15 changes: 1 addition & 14 deletions lib/aws/session_store/dynamo_db/garbage_collection.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

require 'aws-sdk-dynamodb'

module Aws::SessionStore::DynamoDB
Expand Down Expand Up @@ -50,7 +37,7 @@ def scan_filter(config)
# @api private
def eliminate_unwanted_sessions(config, last_key = nil)
scan_result = scan(config, last_key)
batch_delete(config, scan_result[:member])
batch_delete(config, scan_result[:items])
scan_result[:last_evaluated_key] || {}
end

Expand Down
14 changes: 0 additions & 14 deletions lib/aws/session_store/dynamo_db/invalid_id_error.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.


module Aws::SessionStore::DynamoDB
class InvalidIDError < RuntimeError
def initialize(msg = "Corrupt Session ID!")
Expand Down
14 changes: 0 additions & 14 deletions lib/aws/session_store/dynamo_db/lock_wait_timeout_error.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.


module Aws::SessionStore::DynamoDB
class LockWaitTimeoutError < RuntimeError
def initialize(msg = 'Maximum time spent to acquire lock has been exceeded!')
Expand Down
14 changes: 0 additions & 14 deletions lib/aws/session_store/dynamo_db/locking/base.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# 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 provides a framework for implementing
# locking strategies.
Expand Down
Loading