aws-sdk-rails 3.6.1 → 3.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/action_dispatch/session/dynamodb_store.rb +5 -1
- data/lib/active_job/queue_adapters/amazon_sqs_adapter.rb +11 -9
- data/lib/active_job/queue_adapters/amazon_sqs_async_adapter.rb +12 -9
- data/lib/aws/rails/middleware/ebs_sqs_active_job_middleware.rb +4 -4
- data/lib/aws/rails/railtie.rb +9 -4
- data/lib/aws/rails/{mailer.rb → ses_mailer.rb} +11 -10
- data/lib/aws/rails/sesv2_mailer.rb +45 -0
- data/lib/aws/rails/sqs_active_job/configuration.rb +17 -4
- data/lib/aws/rails/sqs_active_job/poller.rb +0 -1
- data/lib/aws-sdk-rails.rb +2 -1
- data/lib/generators/aws_record/model/model_generator.rb +2 -2
- data/lib/generators/aws_record/model/templates/{model.rb → model.erb} +0 -0
- data/lib/generators/aws_record/model/templates/{table_config.rb → table_config.erb} +0 -0
- data/lib/generators/dynamo_db/session_store_migration/session_store_migration_generator.rb +1 -1
- data/lib/generators/dynamo_db/session_store_migration/templates/{session_store_migration.rb → session_store_migration.erb} +0 -0
- metadata +22 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4a36f06cb28402d5c089672aa4e88a7ec087d61496c5d2f2855a61c11b3ca4b
|
4
|
+
data.tar.gz: 19f617df06780135dd75d1f6e76911c2104f8b3f2201b0654b97d29a2fd61bbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d0fb987757cb4b86b660e3180355a8d9870df3f85798f4ab1d085cd03fb448cba686438f0ee7bc96687daeac5faeeee44e8bdf0e88097c243d70bf1531dd0c5
|
7
|
+
data.tar.gz: ad77218a0c85cf43fe3eb8123dedd52d7914bdbfa6323a46299b743c97340edf5fe59774efae0fece141b9ae4e02949e2d17ad2cb00bb119e514e6367442c929
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.7.0
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'aws-sessionstore-dynamodb'
|
2
|
+
require 'action_dispatch/middleware/session/abstract_store'
|
2
3
|
|
3
4
|
module ActionDispatch
|
4
5
|
module Session
|
@@ -9,11 +10,14 @@ module ActionDispatch
|
|
9
10
|
# This class will use the Rails secret_key_base unless otherwise provided.
|
10
11
|
#
|
11
12
|
# Configuration can also be provided in YAML files from Rails config, either
|
12
|
-
# in "config/session_store.yml" or "config/session_store
|
13
|
+
# in "config/session_store.yml" or "config/session_store/#\\{Rails.env}.yml".
|
13
14
|
# Configuration files that are environment-specific will take precedence.
|
14
15
|
#
|
15
16
|
# @see https://docs.aws.amazon.com/sdk-for-ruby/aws-sessionstore-dynamodb/api/Aws/SessionStore/DynamoDB/Configuration.html
|
16
17
|
class DynamodbStore < Aws::SessionStore::DynamoDB::RackMiddleware
|
18
|
+
include StaleSessionCheck
|
19
|
+
include SessionObject
|
20
|
+
|
17
21
|
def initialize(app, options = {})
|
18
22
|
options[:config_file] ||= config_file if config_file.exist?
|
19
23
|
options[:secret_key] ||= Rails.application.secret_key_base
|
@@ -11,16 +11,16 @@ module ActiveJob
|
|
11
11
|
_enqueue(job)
|
12
12
|
end
|
13
13
|
|
14
|
-
def enqueue_at(job, timestamp
|
14
|
+
def enqueue_at(job, timestamp)
|
15
15
|
delay = (timestamp - Time.now.to_f).floor
|
16
16
|
raise ArgumentError, 'Unable to queue a job with a delay great than 15 minutes' if delay > 15.minutes
|
17
|
-
_enqueue(job, delay_seconds: delay)
|
17
|
+
_enqueue(job, nil, delay_seconds: delay)
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
-
def _enqueue(job, send_message_opts = {})
|
23
|
-
body
|
22
|
+
def _enqueue(job, body = nil, send_message_opts = {})
|
23
|
+
body ||= job.serialize
|
24
24
|
queue_url = Aws::Rails::SqsActiveJob.config.queue_url_for(job.queue_name)
|
25
25
|
send_message_opts[:queue_url] = queue_url
|
26
26
|
send_message_opts[:message_body] = Aws::Json.dump(body)
|
@@ -30,13 +30,15 @@ module ActiveJob
|
|
30
30
|
# job_id is unique per initialization of job
|
31
31
|
# Remove it from message dup id to ensure run-once behavior
|
32
32
|
# with ActiveJob retries
|
33
|
-
|
34
|
-
|
35
|
-
Aws::Json.dump(body.except('job_id'))
|
36
|
-
)
|
33
|
+
send_message_opts[:message_deduplication_id] =
|
34
|
+
Digest::SHA256.hexdigest(Aws::Json.dump(body.except('job_id')))
|
37
35
|
|
38
|
-
|
36
|
+
message_group_id = job.message_group_id if job.respond_to?(:message_group_id)
|
37
|
+
message_group_id ||= Aws::Rails::SqsActiveJob.config.message_group_id
|
38
|
+
|
39
|
+
send_message_opts[:message_group_id] = message_group_id
|
39
40
|
end
|
41
|
+
|
40
42
|
Aws::Rails::SqsActiveJob.config.client.send_message(send_message_opts)
|
41
43
|
end
|
42
44
|
|
@@ -18,19 +18,22 @@ module ActiveJob
|
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
-
def _enqueue(job, send_message_opts = {})
|
21
|
+
def _enqueue(job, body = nil, send_message_opts = {})
|
22
22
|
# FIFO jobs must be queued in order, so do not queue async
|
23
23
|
queue_url = Aws::Rails::SqsActiveJob.config.queue_url_for(job.queue_name)
|
24
24
|
if Aws::Rails::SqsActiveJob.fifo?(queue_url)
|
25
|
-
super(job, send_message_opts)
|
25
|
+
super(job, body, send_message_opts)
|
26
26
|
else
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
# Serialize is called here because the job’s locale needs to be
|
28
|
+
# determined in this thread and not in some other thread.
|
29
|
+
body = job.serialize
|
30
|
+
Concurrent::Promises
|
31
|
+
.future { super(job, body, send_message_opts) }
|
32
|
+
.rescue do |e|
|
33
|
+
Rails.logger.error "Failed to queue job #{job}. Reason: #{e}"
|
34
|
+
error_handler = Aws::Rails::SqsActiveJob.config.async_queue_error_handler
|
35
|
+
error_handler&.call(e, job, send_message_opts)
|
36
|
+
end
|
34
37
|
end
|
35
38
|
end
|
36
39
|
end
|
@@ -11,7 +11,7 @@ module Aws
|
|
11
11
|
|
12
12
|
def initialize(app)
|
13
13
|
@app = app
|
14
|
-
@logger =
|
14
|
+
@logger = ::Rails.logger
|
15
15
|
end
|
16
16
|
|
17
17
|
def call(env)
|
@@ -20,11 +20,11 @@ module Aws
|
|
20
20
|
# Pass through unless user agent is the SQS Daemon
|
21
21
|
return @app.call(env) unless from_sqs_daemon?(request)
|
22
22
|
|
23
|
-
@logger.debug('aws-rails
|
23
|
+
@logger.debug('aws-sdk-rails middleware detected call from Elastic Beanstalk SQS Daemon.')
|
24
24
|
|
25
25
|
# Only accept requests from this user agent if it is from localhost or a docker host in case of forgery.
|
26
26
|
unless request.local? || sent_from_docker_host?(request)
|
27
|
-
@logger.warn("SQSD request detected from untrusted address #{request.
|
27
|
+
@logger.warn("SQSD request detected from untrusted address #{request.ip}; returning 403 forbidden.")
|
28
28
|
return FORBIDDEN_RESPONSE
|
29
29
|
end
|
30
30
|
|
@@ -81,7 +81,7 @@ module Aws
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def sent_from_docker_host?(request)
|
84
|
-
app_runs_in_docker_container? && request.
|
84
|
+
app_runs_in_docker_container? && request.ip == '172.17.0.1'
|
85
85
|
end
|
86
86
|
|
87
87
|
def app_runs_in_docker_container?
|
data/lib/aws/rails/railtie.rb
CHANGED
@@ -10,6 +10,7 @@ module Aws
|
|
10
10
|
# Initialization Actions
|
11
11
|
Aws::Rails.use_rails_encrypted_credentials
|
12
12
|
Aws::Rails.add_action_mailer_delivery_method
|
13
|
+
Aws::Rails.add_action_mailer_delivery_method(:sesv2)
|
13
14
|
Aws::Rails.log_to_rails_logger
|
14
15
|
end
|
15
16
|
|
@@ -28,11 +29,15 @@ module Aws
|
|
28
29
|
#
|
29
30
|
# @param [Symbol] name The name of the ActionMailer delivery method to
|
30
31
|
# register.
|
31
|
-
# @param [Hash]
|
32
|
-
# Aws::SES::Client initialization method.
|
33
|
-
def self.add_action_mailer_delivery_method(name = :ses,
|
32
|
+
# @param [Hash] client_options The options you wish to pass on to the
|
33
|
+
# Aws::SES[V2]::Client initialization method.
|
34
|
+
def self.add_action_mailer_delivery_method(name = :ses, client_options = {})
|
34
35
|
ActiveSupport.on_load(:action_mailer) do
|
35
|
-
|
36
|
+
if name == :sesv2
|
37
|
+
add_delivery_method(name, Aws::Rails::Sesv2Mailer, client_options)
|
38
|
+
else
|
39
|
+
add_delivery_method(name, Aws::Rails::SesMailer, client_options)
|
40
|
+
end
|
36
41
|
end
|
37
42
|
end
|
38
43
|
|
@@ -15,7 +15,7 @@ module Aws
|
|
15
15
|
#
|
16
16
|
# Uses the AWS SDK for Ruby's credential provider chain when creating an SES
|
17
17
|
# client instance.
|
18
|
-
class
|
18
|
+
class SesMailer
|
19
19
|
# @param [Hash] options Passes along initialization options to
|
20
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 = {})
|
@@ -25,15 +25,12 @@ module Aws
|
|
25
25
|
# Rails expects this method to exist, and to handle a Mail::Message object
|
26
26
|
# correctly. Called during mail delivery.
|
27
27
|
def deliver!(message)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
@client.send_raw_email(send_opts).tap do |response|
|
28
|
+
params = {
|
29
|
+
raw_message: { data: message.to_s },
|
30
|
+
source: message.smtp_envelope_from, # defaults to From header
|
31
|
+
destinations: message.smtp_envelope_to # defaults to destinations (To,Cc,Bcc)
|
32
|
+
}
|
33
|
+
@client.send_raw_email(params).tap do |response|
|
37
34
|
message.header[:ses_message_id] = response.message_id
|
38
35
|
end
|
39
36
|
end
|
@@ -45,3 +42,7 @@ module Aws
|
|
45
42
|
end
|
46
43
|
end
|
47
44
|
end
|
45
|
+
|
46
|
+
# This is for backwards compatibility after introducing support for SESv2.
|
47
|
+
# The old mailer is now replaced with the new SES (v1) mailer.
|
48
|
+
Aws::Rails::Mailer = Aws::Rails::SesMailer
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aws-sdk-sesv2'
|
4
|
+
|
5
|
+
module Aws
|
6
|
+
module Rails
|
7
|
+
# Provides a delivery method for ActionMailer that uses Amazon Simple Email
|
8
|
+
# Service V2.
|
9
|
+
#
|
10
|
+
# Once you have an SESv2 delivery method you can configure Rails to
|
11
|
+
# use this for ActionMailer in your environment configuration
|
12
|
+
# (e.g. RAILS_ROOT/config/environments/production.rb)
|
13
|
+
#
|
14
|
+
# config.action_mailer.delivery_method = :sesv2
|
15
|
+
#
|
16
|
+
# Uses the AWS SDK for Ruby's credential provider chain when creating an SESV2
|
17
|
+
# client instance.
|
18
|
+
class Sesv2Mailer
|
19
|
+
# @param [Hash] options Passes along initialization options to
|
20
|
+
# [Aws::SESV2::Client.new](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/SESV2/Client.html#initialize-instance_method).
|
21
|
+
def initialize(options = {})
|
22
|
+
@client = SESV2::Client.new(options)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Rails expects this method to exist, and to handle a Mail::Message object
|
26
|
+
# correctly. Called during mail delivery.
|
27
|
+
def deliver!(message)
|
28
|
+
params = {
|
29
|
+
content: { raw: { data: message.to_s } },
|
30
|
+
from_email_address: message.smtp_envelope_from, # defaults to From header
|
31
|
+
# defaults to destinations (To,Cc,Bcc) - stick all on bcc to be delivered anyway
|
32
|
+
destination: { bcc_addresses: message.smtp_envelope_to }
|
33
|
+
}
|
34
|
+
@client.send_email(params).tap do |response|
|
35
|
+
message.header[:ses_message_id] = response.message_id
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# ActionMailer expects this method to be present and to return a hash.
|
40
|
+
def settings
|
41
|
+
{}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -26,7 +26,6 @@ module Aws
|
|
26
26
|
# @api private
|
27
27
|
DEFAULTS = {
|
28
28
|
max_messages: 10,
|
29
|
-
visibility_timeout: 120,
|
30
29
|
shutdown_timeout: 15,
|
31
30
|
queues: {},
|
32
31
|
logger: ::Rails.logger,
|
@@ -50,6 +49,8 @@ module Aws
|
|
50
49
|
# The max number of messages to poll for in a batch.
|
51
50
|
#
|
52
51
|
# @option options [Integer] :visibility_timeout
|
52
|
+
# If unset, the visibility timeout configured on the
|
53
|
+
# SQS queue will be used.
|
53
54
|
# The visibility timeout is the number of seconds
|
54
55
|
# that a message will not be processable by any other consumers.
|
55
56
|
# You should set this value to be longer than your expected job runtime
|
@@ -99,7 +100,7 @@ module Aws
|
|
99
100
|
job_queue = job_queue.to_sym
|
100
101
|
raise ArgumentError, "No queue defined for #{job_queue}" unless queues.key? job_queue
|
101
102
|
|
102
|
-
queues[job_queue
|
103
|
+
queues[job_queue]
|
103
104
|
end
|
104
105
|
|
105
106
|
# @api private
|
@@ -144,8 +145,7 @@ module Aws
|
|
144
145
|
|
145
146
|
# Load options from YAML file
|
146
147
|
def load_from_file(file_path)
|
147
|
-
|
148
|
-
opts = YAML.load(ERB.new(File.read(file_path)).result) || {}
|
148
|
+
opts = load_yaml(file_path) || {}
|
149
149
|
opts.deep_symbolize_keys
|
150
150
|
end
|
151
151
|
|
@@ -157,6 +157,19 @@ module Aws
|
|
157
157
|
def user_agent
|
158
158
|
"ft/aws-sdk-rails-activejob/#{Aws::Rails::VERSION}"
|
159
159
|
end
|
160
|
+
|
161
|
+
def load_yaml(file_path)
|
162
|
+
require "erb"
|
163
|
+
source = ERB.new(File.read(file_path)).result
|
164
|
+
|
165
|
+
# Avoid incompatible changes with Psych 4.0.0
|
166
|
+
# https://bugs.ruby-lang.org/issues/17866
|
167
|
+
begin
|
168
|
+
YAML.load(source, aliases: true) || {}
|
169
|
+
rescue ArgumentError
|
170
|
+
YAML.load(source) || {}
|
171
|
+
end
|
172
|
+
end
|
160
173
|
end
|
161
174
|
end
|
162
175
|
end
|
data/lib/aws-sdk-rails.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'aws/rails/
|
3
|
+
require_relative 'aws/rails/ses_mailer'
|
4
|
+
require_relative 'aws/rails/sesv2_mailer'
|
4
5
|
require_relative 'aws/rails/railtie'
|
5
6
|
require_relative 'aws/rails/notifications'
|
6
7
|
require_relative 'aws/rails/sqs_active_job/configuration'
|
@@ -9,11 +9,11 @@ module AwsRecord
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def create_model
|
12
|
-
template "model.
|
12
|
+
template "model.erb", File.join("app/models", class_path, "#{file_name}.rb")
|
13
13
|
end
|
14
14
|
|
15
15
|
def create_table_config
|
16
|
-
template "table_config.
|
16
|
+
template "table_config.erb", File.join("db/table_config", class_path, "#{file_name}_config.rb") if options["table_config"]
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
File without changes
|
File without changes
|
File without changes
|
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.
|
4
|
+
version: 3.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amazon Web Services
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-record
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: aws-sdk-sesv2
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: aws-sdk-sqs
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,10 +137,11 @@ files:
|
|
123
137
|
- lib/active_job/queue_adapters/amazon_sqs_adapter.rb
|
124
138
|
- lib/active_job/queue_adapters/amazon_sqs_async_adapter.rb
|
125
139
|
- lib/aws-sdk-rails.rb
|
126
|
-
- lib/aws/rails/mailer.rb
|
127
140
|
- lib/aws/rails/middleware/ebs_sqs_active_job_middleware.rb
|
128
141
|
- lib/aws/rails/notifications.rb
|
129
142
|
- lib/aws/rails/railtie.rb
|
143
|
+
- lib/aws/rails/ses_mailer.rb
|
144
|
+
- lib/aws/rails/sesv2_mailer.rb
|
130
145
|
- lib/aws/rails/sqs_active_job/configuration.rb
|
131
146
|
- lib/aws/rails/sqs_active_job/executor.rb
|
132
147
|
- lib/aws/rails/sqs_active_job/job_runner.rb
|
@@ -136,13 +151,13 @@ files:
|
|
136
151
|
- lib/generators/aws_record/generated_attribute.rb
|
137
152
|
- lib/generators/aws_record/model/USAGE
|
138
153
|
- lib/generators/aws_record/model/model_generator.rb
|
139
|
-
- lib/generators/aws_record/model/templates/model.
|
140
|
-
- lib/generators/aws_record/model/templates/table_config.
|
154
|
+
- lib/generators/aws_record/model/templates/model.erb
|
155
|
+
- lib/generators/aws_record/model/templates/table_config.erb
|
141
156
|
- lib/generators/aws_record/secondary_index.rb
|
142
157
|
- lib/generators/dynamo_db/session_store_migration/USAGE
|
143
158
|
- lib/generators/dynamo_db/session_store_migration/session_store_migration_generator.rb
|
144
159
|
- lib/generators/dynamo_db/session_store_migration/templates/dynamo_db_session_store.yml
|
145
|
-
- lib/generators/dynamo_db/session_store_migration/templates/session_store_migration.
|
160
|
+
- lib/generators/dynamo_db/session_store_migration/templates/session_store_migration.erb
|
146
161
|
- lib/tasks/aws_record/migrate.rake
|
147
162
|
- lib/tasks/dynamo_db/session_store.rake
|
148
163
|
homepage: https://github.com/aws/aws-sdk-rails
|
@@ -164,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
179
|
- !ruby/object:Gem::Version
|
165
180
|
version: '0'
|
166
181
|
requirements: []
|
167
|
-
rubygems_version: 3.2.
|
182
|
+
rubygems_version: 3.2.7
|
168
183
|
signing_key:
|
169
184
|
specification_version: 4
|
170
185
|
summary: AWS SDK for Ruby on Rails Plugin
|