aws-sdk-rails 2.0.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/action_dispatch/session/dynamodb_store.rb +32 -0
- data/lib/aws-sdk-rails.rb +5 -35
- data/lib/aws/rails/mailer.rb +10 -10
- data/lib/aws/rails/notifications.rb +33 -0
- data/lib/aws/rails/railtie.rb +67 -0
- data/lib/generators/dynamo_db/session_store_migration/USAGE +13 -0
- data/lib/generators/dynamo_db/session_store_migration/session_store_migration_generator.rb +46 -0
- data/lib/generators/dynamo_db/session_store_migration/templates/dynamo_db_session_store.yml +70 -0
- data/lib/generators/dynamo_db/session_store_migration/templates/session_store_migration.rb +9 -0
- data/lib/tasks/dynamo_db/session_store.rake +8 -0
- metadata +49 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b16c1ca75c59341fdc3696d91648fda6901937f31b5b4c55b5d1ccf3bcc9af47
|
4
|
+
data.tar.gz: 9c9c22d4740ea76b06fa7ee6b8d525450fc982e3c73db0fe81234356dbd71a86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ef9e3bf5bde8d91b25635e2bed4028a163547f6e8eabb3ece2e08d1482e6edce16386a916240f344dcce27bc8efec3c5c424236fed6f150e4a6912165648914
|
7
|
+
data.tar.gz: 0052b3633ce5fc655f4b6fdd80851049196e1c7c7a7d6cc92e17d52fc6fcc8ae69712bc411d3f0feb369dfd835e23912c67802ff32abe3654cf3b4feee87c02a
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'aws-sessionstore-dynamodb'
|
2
|
+
|
3
|
+
module ActionDispatch
|
4
|
+
module Session
|
5
|
+
# Uses the Dynamo DB Session Store implementation to create a class that
|
6
|
+
# extends ActionDispatch::Session. Rails will create a :dynamodb_store
|
7
|
+
# configuration for session_store from this class name.
|
8
|
+
#
|
9
|
+
# This class will use the Rails secret_key_base unless otherwise provided.
|
10
|
+
#
|
11
|
+
# Configuration can also be provided in YAML files from Rails config, either
|
12
|
+
# in "config/session_store.yml" or "config/session_store/#{Rails.env}.yml".
|
13
|
+
# Configuration files that are environment-specific will take precedence.
|
14
|
+
#
|
15
|
+
# @see https://docs.aws.amazon.com/sdk-for-ruby/aws-sessionstore-dynamodb/api/Aws/SessionStore/DynamoDB/Configuration.html
|
16
|
+
class DynamodbStore < Aws::SessionStore::DynamoDB::RackMiddleware
|
17
|
+
def initialize(app, options = {})
|
18
|
+
options[:config_file] ||= config_file if config_file.exist?
|
19
|
+
options[:secret_key] ||= Rails.application.secret_key_base
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def config_file
|
26
|
+
file = Rails.root.join("config/dynamo_db_session_store/#{Rails.env}.yml")
|
27
|
+
file = Rails.root.join('config/dynamo_db_session_store.yml') unless file.exist?
|
28
|
+
file
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/aws-sdk-rails.rb
CHANGED
@@ -1,37 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Aws
|
4
|
-
module Rails
|
5
|
-
|
6
|
-
# @api private
|
7
|
-
class Railtie < ::Rails::Railtie
|
8
|
-
initializer "aws-sdk-rails.initialize" do |app|
|
9
|
-
# Initialization Actions
|
10
|
-
Aws::Rails.add_action_mailer_delivery_method
|
11
|
-
Aws::Rails.log_to_rails_logger
|
12
|
-
end
|
13
|
-
end
|
1
|
+
# frozen_string_literal: true
|
14
2
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
#
|
19
|
-
# @param [Symbol] name The name of the ActionMailer delivery method to
|
20
|
-
# register.
|
21
|
-
# @param [Hash] options The options you wish to pass on to the
|
22
|
-
# Aws::SES::Client initialization method.
|
23
|
-
def self.add_action_mailer_delivery_method(name = :aws_sdk, options = {})
|
24
|
-
ActiveSupport.on_load(:action_mailer) do
|
25
|
-
self.add_delivery_method(name, Aws::Rails::Mailer, options)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# Configures the AWS SDK for Ruby's logger to use the Rails logger.
|
30
|
-
def self.log_to_rails_logger
|
31
|
-
Aws.config[:logger] = ::Rails.logger
|
32
|
-
nil
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
3
|
+
require_relative 'aws/rails/mailer'
|
4
|
+
require_relative 'aws/rails/railtie'
|
5
|
+
require_relative 'aws/rails/notifications'
|
37
6
|
|
7
|
+
require_relative 'action_dispatch/session/dynamodb_store'
|
data/lib/aws/rails/mailer.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'aws-sdk-ses'
|
2
4
|
|
3
5
|
module Aws
|
4
6
|
module Rails
|
5
|
-
|
6
7
|
# Provides a delivery method for ActionMailer that uses Amazon Simple Email
|
7
8
|
# Service.
|
8
|
-
#
|
9
|
+
#
|
9
10
|
# Once you have an SES delivery method you can configure Rails to
|
10
11
|
# use this for ActionMailer in your environment configuration
|
11
12
|
# (e.g. RAILS_ROOT/config/environments/production.rb)
|
12
13
|
#
|
13
|
-
# config.action_mailer.delivery_method = :
|
14
|
+
# config.action_mailer.delivery_method = :ses
|
14
15
|
#
|
15
|
-
# Uses the AWS SDK for Ruby
|
16
|
-
#
|
16
|
+
# Uses the AWS SDK for Ruby's credential provider chain when creating an SES
|
17
|
+
# client instance.
|
17
18
|
class Mailer
|
18
|
-
|
19
19
|
# @param [Hash] options Passes along initialization options to
|
20
|
-
# [Aws::SES::Client.new](
|
20
|
+
# [Aws::SES::Client.new](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/SES/Client.html#initialize-instance_method).
|
21
21
|
def initialize(options = {})
|
22
22
|
@client = SES::Client.new(options)
|
23
23
|
end
|
@@ -33,15 +33,15 @@ module Aws
|
|
33
33
|
send_opts[:destinations] = message.destinations
|
34
34
|
end
|
35
35
|
|
36
|
-
@client.send_raw_email(send_opts)
|
37
|
-
|
36
|
+
@client.send_raw_email(send_opts).tap do |response|
|
37
|
+
message.header[:ses_message_id] = response.message_id
|
38
|
+
end
|
38
39
|
end
|
39
40
|
|
40
41
|
# ActionMailer expects this method to be present and to return a hash.
|
41
42
|
def settings
|
42
43
|
{}
|
43
44
|
end
|
44
|
-
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aws-sdk-core'
|
4
|
+
require 'active_support/notifications'
|
5
|
+
|
6
|
+
module Aws
|
7
|
+
module Rails
|
8
|
+
|
9
|
+
# Instruments client operation calls for ActiveSupport::Notifications
|
10
|
+
# Each client operation will produce an event with name:
|
11
|
+
# <operation>.<service>.aws
|
12
|
+
# @api private
|
13
|
+
class Notifications < Seahorse::Client::Plugin
|
14
|
+
|
15
|
+
def add_handlers(handlers, config)
|
16
|
+
# This plugin needs to be first
|
17
|
+
# which means it is called first in the stack, to start recording time,
|
18
|
+
# and returns last
|
19
|
+
handlers.add(Handler, step: :initialize, priority: 99)
|
20
|
+
end
|
21
|
+
|
22
|
+
class Handler < Seahorse::Client::Handler
|
23
|
+
|
24
|
+
def call(context)
|
25
|
+
event_name = "#{context.operation_name}.#{context.config.api.metadata['serviceId']}.aws"
|
26
|
+
ActiveSupport::Notifications.instrument(event_name, context: context) do
|
27
|
+
@handler.call(context)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
# Use the Rails namespace.
|
5
|
+
module Rails
|
6
|
+
# @api private
|
7
|
+
class Railtie < ::Rails::Railtie
|
8
|
+
initializer 'aws-sdk-rails.initialize',
|
9
|
+
before: :load_config_initializers do
|
10
|
+
# Initialization Actions
|
11
|
+
Aws::Rails.use_rails_encrypted_credentials
|
12
|
+
Aws::Rails.add_action_mailer_delivery_method
|
13
|
+
Aws::Rails.log_to_rails_logger
|
14
|
+
end
|
15
|
+
|
16
|
+
rake_tasks do
|
17
|
+
load 'tasks/dynamo_db/session_store.rake'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# This is called automatically from the SDK's Railtie, but can be manually
|
22
|
+
# called if you want to specify options for building the Aws::SES::Client.
|
23
|
+
#
|
24
|
+
# @param [Symbol] name The name of the ActionMailer delivery method to
|
25
|
+
# register.
|
26
|
+
# @param [Hash] options The options you wish to pass on to the
|
27
|
+
# Aws::SES::Client initialization method.
|
28
|
+
def self.add_action_mailer_delivery_method(name = :ses, options = {})
|
29
|
+
ActiveSupport.on_load(:action_mailer) do
|
30
|
+
add_delivery_method(name, Aws::Rails::Mailer, options)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Configures the AWS SDK for Ruby's logger to use the Rails logger.
|
35
|
+
def self.log_to_rails_logger
|
36
|
+
Aws.config[:logger] = ::Rails.logger
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
# Configures the AWS SDK with credentials from Rails encrypted credentials.
|
41
|
+
def self.use_rails_encrypted_credentials
|
42
|
+
# limit the config keys we merge to credentials only
|
43
|
+
aws_credential_keys = %i[access_key_id secret_access_key session_token]
|
44
|
+
|
45
|
+
Aws.config.merge!(
|
46
|
+
::Rails.application
|
47
|
+
.try(:credentials)
|
48
|
+
.try(:aws)
|
49
|
+
.to_h.slice(*aws_credential_keys)
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Adds ActiveSupport Notifications instrumentation to AWS SDK
|
54
|
+
# client operations. Each operation will produce an event with a name:
|
55
|
+
# <operation>.<service>.aws. For example, S3's put_object has an event
|
56
|
+
# name of: put_object.S3.aws
|
57
|
+
def self.instrument_sdk_operations
|
58
|
+
Aws.constants.each do |c|
|
59
|
+
m = Aws.const_get(c)
|
60
|
+
if m.is_a?(Module) && m.const_defined?(:Client) &&
|
61
|
+
m.const_get(:Client).superclass == Seahorse::Client::Base
|
62
|
+
m.const_get(:Client).add_plugin(Aws::Rails::Notifications)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Description:
|
2
|
+
Generates a migration file for deleting and a creating a DynamoDB
|
3
|
+
sessions table, and a configuration file for the session store.
|
4
|
+
|
5
|
+
Example:
|
6
|
+
rails generate dynamo_db:session_store_migration <MIGRATION_NAME>
|
7
|
+
|
8
|
+
This will create:
|
9
|
+
db/migrate/#{VERSION}_#{MIGRATION_NAME}.rb
|
10
|
+
config/dynamo_db_session_store.yml
|
11
|
+
|
12
|
+
The migration will be run when the command rake db:migrate is run
|
13
|
+
in the command line.
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
|
3
|
+
# This class generates a migration file for deleting and creating
|
4
|
+
# a DynamoDB sessions table.
|
5
|
+
module DynamoDb
|
6
|
+
module Generators
|
7
|
+
# Generates an ActiveRecord migration that creates and deletes a DynamoDB
|
8
|
+
# Session table.
|
9
|
+
class SessionStoreMigrationGenerator < Rails::Generators::NamedBase
|
10
|
+
include Rails::Generators::Migration
|
11
|
+
|
12
|
+
source_root File.expand_path('templates', __dir__)
|
13
|
+
|
14
|
+
# Desired name of migration class
|
15
|
+
argument :name, type: :string, default: 'create_dynamo_db_sessions_table'
|
16
|
+
|
17
|
+
# @return [Rails Migration File] migration file for creation and deletion
|
18
|
+
# of a DynamoDB session table.
|
19
|
+
def generate_migration_file
|
20
|
+
migration_template(
|
21
|
+
'session_store_migration.rb',
|
22
|
+
"db/migrate/#{name.underscore}.rb"
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def copy_sample_config_file
|
27
|
+
template(
|
28
|
+
'dynamo_db_session_store.yml',
|
29
|
+
'config/dynamo_db_session_store.yml'
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Next migration number - must be implemented
|
34
|
+
def self.next_migration_number(_dir = nil)
|
35
|
+
Time.now.utc.strftime('%Y%m%d%H%M%S')
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
# @return [String] activerecord migration version
|
41
|
+
def migration_version
|
42
|
+
"#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# Uncomment and manipulate the key value pairs below
|
2
|
+
# in order to configure the DynamoDB Session Store Application.
|
3
|
+
|
4
|
+
# [String] The secret key for HMAC encryption. This defaults to
|
5
|
+
# `Rails.application.secret_key_base`. You can use a different key if desired.
|
6
|
+
#
|
7
|
+
# secret_key: SECRET_KEY
|
8
|
+
|
9
|
+
# [String] Session table name.
|
10
|
+
#
|
11
|
+
# table_name: Sessions
|
12
|
+
|
13
|
+
# [String] Session table hash key name.
|
14
|
+
#
|
15
|
+
# table_key: session_id
|
16
|
+
|
17
|
+
# [Boolean] Define as true or false depending on if you want a strongly
|
18
|
+
# consistent read.
|
19
|
+
# See AWS DynamoDB documentation for table consistent_read for more
|
20
|
+
# information on this setting.
|
21
|
+
#
|
22
|
+
# consistent_read: true
|
23
|
+
|
24
|
+
# [Integer] Maximum number of reads consumed per second before
|
25
|
+
# DynamoDB returns a ThrottlingException. See AWS DynamoDB documentation
|
26
|
+
# or table read_capacity for more information on this setting.
|
27
|
+
#
|
28
|
+
# read_capacity: 10
|
29
|
+
|
30
|
+
# [Integer] Maximum number of writes consumed per second before
|
31
|
+
# DynamoDB returns a ThrottlingException. See AWS DynamoDB documentation
|
32
|
+
# or table write_capacity for more information on this setting.
|
33
|
+
#
|
34
|
+
# write_capacity: 5
|
35
|
+
|
36
|
+
# [Boolean] Define as true or false depending on whether you want all errors to be
|
37
|
+
# raised up the stack.
|
38
|
+
#
|
39
|
+
# raise_errors: false
|
40
|
+
|
41
|
+
# [Integer] Maximum number of seconds earlier
|
42
|
+
# from the current time that a session was created.
|
43
|
+
# By default this is 7 days.
|
44
|
+
#
|
45
|
+
# max_age: 604800
|
46
|
+
|
47
|
+
# [Integer] Maximum number of seconds
|
48
|
+
# before the current time that the session was last accessed.
|
49
|
+
# By default this is 5 hours.
|
50
|
+
#
|
51
|
+
# max_stale: 18000
|
52
|
+
|
53
|
+
# [Boolean] Define as true or false for whether you want to enable locking
|
54
|
+
# for all accesses to session data.
|
55
|
+
#
|
56
|
+
# enable_locking: false
|
57
|
+
|
58
|
+
# [Integer] Time in milleseconds after which lock will expire.
|
59
|
+
#
|
60
|
+
# lock_expiry_time: 500
|
61
|
+
|
62
|
+
# [Integer] Time in milleseconds to wait before retrying to obtain
|
63
|
+
# lock once an attempt to obtain lock has been made and has failed.
|
64
|
+
#
|
65
|
+
# lock_retry_delay: 500
|
66
|
+
|
67
|
+
# [Integer] Maximum time in seconds to wait to acquire lock
|
68
|
+
# before giving up.
|
69
|
+
#
|
70
|
+
# lock_max_wait_time: 1
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-sdk-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 3.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amazon Web Services
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-ses
|
@@ -24,34 +24,71 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-sessionstore-dynamodb
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: railties
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
47
|
+
version: 5.2.0
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
|
54
|
+
version: 5.2.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Integrates the AWS Ruby SDK with Ruby on Rails
|
42
70
|
email:
|
43
|
-
-
|
71
|
+
- mamuller@amazon.com
|
72
|
+
- alexwoo@amazon.com
|
44
73
|
executables: []
|
45
74
|
extensions: []
|
46
75
|
extra_rdoc_files: []
|
47
76
|
files:
|
77
|
+
- lib/action_dispatch/session/dynamodb_store.rb
|
48
78
|
- lib/aws-sdk-rails.rb
|
49
79
|
- lib/aws/rails/mailer.rb
|
80
|
+
- lib/aws/rails/notifications.rb
|
81
|
+
- lib/aws/rails/railtie.rb
|
82
|
+
- lib/generators/dynamo_db/session_store_migration/USAGE
|
83
|
+
- lib/generators/dynamo_db/session_store_migration/session_store_migration_generator.rb
|
84
|
+
- lib/generators/dynamo_db/session_store_migration/templates/dynamo_db_session_store.yml
|
85
|
+
- lib/generators/dynamo_db/session_store_migration/templates/session_store_migration.rb
|
86
|
+
- lib/tasks/dynamo_db/session_store.rake
|
50
87
|
homepage: https://github.com/aws/aws-sdk-rails
|
51
88
|
licenses:
|
52
|
-
- Apache
|
89
|
+
- Apache-2.0
|
53
90
|
metadata: {}
|
54
|
-
post_install_message:
|
91
|
+
post_install_message:
|
55
92
|
rdoc_options: []
|
56
93
|
require_paths:
|
57
94
|
- lib
|
@@ -66,9 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
103
|
- !ruby/object:Gem::Version
|
67
104
|
version: '0'
|
68
105
|
requirements: []
|
69
|
-
|
70
|
-
|
71
|
-
signing_key:
|
106
|
+
rubygems_version: 3.0.3
|
107
|
+
signing_key:
|
72
108
|
specification_version: 4
|
73
|
-
summary: AWS SDK for Ruby Rails Plugin
|
109
|
+
summary: AWS SDK for Ruby on Rails Plugin
|
74
110
|
test_files: []
|