aws-sdk-rails 3.6.4 → 3.7.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: 12ed1c705f5676b3a71f11c40d1cbc86e2f64b70f1a3183d7dff6ee0dec093d0
4
- data.tar.gz: c5963b0723b65ccf6c0f098c878d9c024cb7c2bd0a3dee8773dc6a455c58eb8c
3
+ metadata.gz: 48698b21d8248ac597ad8fd9d334e52d9399cf5880c994ffe556aa2e988f81e6
4
+ data.tar.gz: bd88191e84e5676435a2d2135ad6f6835cb8c624eef573c688a81c3bd9e8f255
5
5
  SHA512:
6
- metadata.gz: 77f501b49eae2b7716206ddf37e5eded053d3383d084225e583660e06a637324103d5f83ffc5f003518fb57d4c64472b352ad7b3aeafc908441598de1ad1e178
7
- data.tar.gz: 50165f13f842c8d6d435905472666697253ea893d2edb18159f25645c2a50a299573d88a59b43c9e6513da61fd0af900a910a155fcb1f4573dfeff8fefc20d8a
6
+ metadata.gz: ec0f7a6f90b736285486d3a36d7aab50cf1d368d9ea69f4b76031634b16df1e899d8146586b9b806f0921f2afebecc5444fe25badf4f0d8bf54a3cf42f472b3c
7
+ data.tar.gz: bbfe9b2488cf8c141a5e196a2ebe9631705ed176327db28a1503213f82aac81f3ec37be4f77109665fbf3690c344c52870b39f5c12f35d031b89387b057bbe5a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.6.4
1
+ 3.7.1
@@ -81,12 +81,30 @@ module Aws
81
81
  end
82
82
 
83
83
  def sent_from_docker_host?(request)
84
- app_runs_in_docker_container? && request.ip == '172.17.0.1'
84
+ app_runs_in_docker_container? && default_gw_ips.include?(request.ip)
85
85
  end
86
86
 
87
87
  def app_runs_in_docker_container?
88
88
  @app_runs_in_docker_container ||= `[ -f /proc/1/cgroup ] && cat /proc/1/cgroup` =~ /docker/
89
89
  end
90
+
91
+ def default_gw_ips
92
+ default_gw_ips = ['172.17.0.1']
93
+
94
+ if File.exist?('/proc/net/route')
95
+ File.open('/proc/net/route').each_line do |line|
96
+ fields = line.strip.split
97
+ next if fields.size != 11
98
+
99
+ # Destination == 0.0.0.0 and Flags & RTF_GATEWAY != 0
100
+ if fields[1] == '00000000' && (fields[3].hex & 0x2) != 0
101
+ default_gw_ips << IPAddr.new_ntoh([fields[2].hex].pack('L')).to_s
102
+ end
103
+ end
104
+ end
105
+
106
+ default_gw_ips
107
+ end
90
108
  end
91
109
  end
92
110
  end
@@ -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] options The options you wish to pass on to the
32
- # Aws::SES::Client initialization method.
33
- def self.add_action_mailer_delivery_method(name = :ses, options = {})
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
- add_delivery_method(name, Aws::Rails::Mailer, options)
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 Mailer
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
- send_opts = {}
29
- send_opts[:raw_message] = {}
30
- send_opts[:raw_message][:data] = message.to_s
31
-
32
- if message.respond_to?(:destinations)
33
- send_opts[:destinations] = message.destinations
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,59 @@
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 = { content: { raw: { data: message.to_s } } }
29
+ # smtp_envelope_from will default to the From address *without* sender names.
30
+ # By omitting this param, SESv2 will correctly use sender names from the mail headers.
31
+ # We should only use smtp_envelope_from when it was explicitly set (instance variable set)
32
+ params[:from_email_address] = message.smtp_envelope_from if message.instance_variable_get(:@smtp_envelope_from)
33
+ params[:destination] = {
34
+ to_addresses: to_addresses(message),
35
+ cc_addresses: message.cc,
36
+ bcc_addresses: message.bcc
37
+ }
38
+
39
+ @client.send_email(params).tap do |response|
40
+ message.header[:ses_message_id] = response.message_id
41
+ end
42
+ end
43
+
44
+ # ActionMailer expects this method to be present and to return a hash.
45
+ def settings
46
+ {}
47
+ end
48
+
49
+ private
50
+
51
+ # smtp_envelope_to will default to the full destinations (To, Cc, Bcc)
52
+ # SES v2 API prefers each component split out into a destination hash.
53
+ # When smtp_envelope_to was set, use it explicitly for to_address only.
54
+ def to_addresses(message)
55
+ message.instance_variable_get(:@smtp_envelope_to) ? message.smtp_envelope_to : message.to
56
+ end
57
+ end
58
+ end
59
+ end
@@ -145,8 +145,7 @@ module Aws
145
145
 
146
146
  # Load options from YAML file
147
147
  def load_from_file(file_path)
148
- require "erb"
149
- opts = YAML.load(ERB.new(File.read(file_path)).result) || {}
148
+ opts = load_yaml(file_path) || {}
150
149
  opts.deep_symbolize_keys
151
150
  end
152
151
 
@@ -158,6 +157,19 @@ module Aws
158
157
  def user_agent
159
158
  "ft/aws-sdk-rails-activejob/#{Aws::Rails::VERSION}"
160
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
161
173
  end
162
174
  end
163
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/mailer'
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'
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.6.4
4
+ version: 3.7.1
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: 2022-10-13 00:00:00.000000000 Z
11
+ date: 2023-02-15 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
@@ -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.7
182
+ rubygems_version: 3.2.3
168
183
  signing_key:
169
184
  specification_version: 4
170
185
  summary: AWS SDK for Ruby on Rails Plugin