aws-sdk-rails 3.1.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c6f3ca6246615704132c2a690056d8c8636fd40947f756e79318affd6148720
4
- data.tar.gz: e17f171dba5c857c58358a6e35d962b398ada43439c78c8e0df496ed342dd1ef
3
+ metadata.gz: b16c1ca75c59341fdc3696d91648fda6901937f31b5b4c55b5d1ccf3bcc9af47
4
+ data.tar.gz: 9c9c22d4740ea76b06fa7ee6b8d525450fc982e3c73db0fe81234356dbd71a86
5
5
  SHA512:
6
- metadata.gz: 61effb18895b3c4de7aa1cb8e44de99f5c497ac0ff996e5d74ae99af1b363dc634bb753e2c2160d437ede22988cdcb145b6683989864ee42b4cc029487649a0c
7
- data.tar.gz: 3b7ebe7488bd432776e1c594dc0325b7d75a964276d7e5af1ab05bbb66f3139de581ccc8c77730d97d69b8b39d5ab0312cb9e5f1fb719b9c5da5f0ce9dde1c5b
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
@@ -1,51 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'aws/rails/mailer'
4
+ require_relative 'aws/rails/railtie'
5
+ require_relative 'aws/rails/notifications'
4
6
 
5
- module Aws
6
- # Use the Rails namespace.
7
- module Rails
8
- # @api private
9
- class Railtie < ::Rails::Railtie
10
- initializer 'aws-sdk-rails.initialize',
11
- before: :load_config_initializers do
12
- # Initialization Actions
13
- Aws::Rails.use_rails_encrypted_credentials
14
- Aws::Rails.add_action_mailer_delivery_method
15
- Aws::Rails.log_to_rails_logger
16
- end
17
- end
18
-
19
- # This is called automatically from the SDK's Railtie, but can be manually
20
- # called if you want to specify options for building the Aws::SES::Client.
21
- #
22
- # @param [Symbol] name The name of the ActionMailer delivery method to
23
- # register.
24
- # @param [Hash] options The options you wish to pass on to the
25
- # Aws::SES::Client initialization method.
26
- def self.add_action_mailer_delivery_method(name = :ses, options = {})
27
- ActiveSupport.on_load(:action_mailer) do
28
- add_delivery_method(name, Aws::Rails::Mailer, options)
29
- end
30
- end
31
-
32
- # Configures the AWS SDK for Ruby's logger to use the Rails logger.
33
- def self.log_to_rails_logger
34
- Aws.config[:logger] = ::Rails.logger
35
- nil
36
- end
37
-
38
- # Configures the AWS SDK with credentials from Rails encrypted credentials.
39
- def self.use_rails_encrypted_credentials
40
- # limit the config keys we merge to credentials only
41
- aws_credential_keys = %i[access_key_id secret_access_key session_token]
42
-
43
- Aws.config.merge!(
44
- ::Rails.application
45
- .try(:credentials)
46
- .try(:aws)
47
- .to_h.slice(*aws_credential_keys)
48
- )
49
- end
50
- end
51
- end
7
+ require_relative 'action_dispatch/session/dynamodb_store'
@@ -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
@@ -0,0 +1,9 @@
1
+ class <%= name.camelize %> < ActiveRecord::Migration[<%= migration_version %>]
2
+ def up
3
+ Aws::SessionStore::DynamoDB::Table.create_table
4
+ end
5
+
6
+ def down
7
+ Aws::SessionStore::DynamoDB::Table.delete_table
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ namespace 'dynamo_db' do
2
+ namespace 'session_store' do
3
+ desc 'Clean up old sessions in the Amazon DynamoDB session store table.'
4
+ task clean: :environment do
5
+ Aws::SessionStore::DynamoDB::GarbageCollection.collect_garbage
6
+ end
7
+ end
8
+ end
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: 3.1.0
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: 2020-04-06 00:00:00.000000000 Z
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,6 +24,20 @@ 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
@@ -54,19 +68,27 @@ dependencies:
54
68
  version: '0'
55
69
  description: Integrates the AWS Ruby SDK with Ruby on Rails
56
70
  email:
57
- - chejingy@amazon.com
58
71
  - mamuller@amazon.com
72
+ - alexwoo@amazon.com
59
73
  executables: []
60
74
  extensions: []
61
75
  extra_rdoc_files: []
62
76
  files:
77
+ - lib/action_dispatch/session/dynamodb_store.rb
63
78
  - lib/aws-sdk-rails.rb
64
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
65
87
  homepage: https://github.com/aws/aws-sdk-rails
66
88
  licenses:
67
89
  - Apache-2.0
68
90
  metadata: {}
69
- post_install_message:
91
+ post_install_message:
70
92
  rdoc_options: []
71
93
  require_paths:
72
94
  - lib
@@ -82,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
104
  version: '0'
83
105
  requirements: []
84
106
  rubygems_version: 3.0.3
85
- signing_key:
107
+ signing_key:
86
108
  specification_version: 4
87
109
  summary: AWS SDK for Ruby on Rails Plugin
88
110
  test_files: []