aws-sdk-rails 4.0.3 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +239 -0
  3. data/LICENSE.txt +12 -0
  4. data/VERSION +1 -1
  5. data/lib/aws/rails/action_mailbox/rspec.rb +6 -65
  6. data/lib/aws/rails/middleware/elastic_beanstalk_sqsd.rb +134 -0
  7. data/lib/aws/rails/notifications.rb +3 -6
  8. data/lib/aws/rails/railtie.rb +50 -32
  9. data/lib/aws-sdk-rails.rb +16 -8
  10. metadata +25 -151
  11. data/app/controllers/action_mailbox/ingresses/ses/inbound_emails_controller.rb +0 -79
  12. data/bin/aws_sqs_active_job +0 -6
  13. data/config/routes.rb +0 -8
  14. data/lib/action_dispatch/session/dynamodb_store.rb +0 -38
  15. data/lib/active_job/queue_adapters/sqs_adapter/params.rb +0 -78
  16. data/lib/active_job/queue_adapters/sqs_adapter.rb +0 -58
  17. data/lib/active_job/queue_adapters/sqs_async_adapter.rb +0 -39
  18. data/lib/aws/rails/action_mailbox/engine.rb +0 -21
  19. data/lib/aws/rails/action_mailbox/rspec/email.rb +0 -50
  20. data/lib/aws/rails/action_mailbox/rspec/subscription_confirmation.rb +0 -37
  21. data/lib/aws/rails/action_mailbox/s3_client.rb +0 -28
  22. data/lib/aws/rails/action_mailbox/sns_message_verifier.rb +0 -18
  23. data/lib/aws/rails/action_mailbox/sns_notification.rb +0 -99
  24. data/lib/aws/rails/middleware/ebs_sqs_active_job_middleware.rb +0 -118
  25. data/lib/aws/rails/ses_mailer.rb +0 -49
  26. data/lib/aws/rails/sesv2_mailer.rb +0 -60
  27. data/lib/aws/rails/sqs_active_job/configuration.rb +0 -184
  28. data/lib/aws/rails/sqs_active_job/deduplication.rb +0 -21
  29. data/lib/aws/rails/sqs_active_job/executor.rb +0 -77
  30. data/lib/aws/rails/sqs_active_job/job_runner.rb +0 -27
  31. data/lib/aws/rails/sqs_active_job/lambda_handler.rb +0 -63
  32. data/lib/aws/rails/sqs_active_job/poller.rb +0 -160
  33. data/lib/aws/rails/sqs_active_job.rb +0 -33
  34. data/lib/generators/aws_record/base.rb +0 -213
  35. data/lib/generators/aws_record/generated_attribute.rb +0 -138
  36. data/lib/generators/aws_record/model/USAGE +0 -24
  37. data/lib/generators/aws_record/model/model_generator.rb +0 -25
  38. data/lib/generators/aws_record/model/templates/model.erb +0 -48
  39. data/lib/generators/aws_record/model/templates/table_config.erb +0 -18
  40. data/lib/generators/aws_record/secondary_index.rb +0 -66
  41. data/lib/generators/dynamo_db/session_store_migration/USAGE +0 -13
  42. data/lib/generators/dynamo_db/session_store_migration/session_store_migration_generator.rb +0 -48
  43. data/lib/generators/dynamo_db/session_store_migration/templates/dynamo_db_session_store.yml +0 -70
  44. data/lib/generators/dynamo_db/session_store_migration/templates/session_store_migration.erb +0 -9
  45. data/lib/tasks/aws_record/migrate.rake +0 -14
  46. data/lib/tasks/dynamo_db/session_store.rake +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9f40f2c54fa1d003ca66738e34591efcc53d951bed78e78efcccb5b8a33758c
4
- data.tar.gz: 6232d8200b719e7cb483a093c8e5b83e00197d80e49374d9209772f7097f9940
3
+ metadata.gz: e58942a12378042b0c5bdfe304b6b90f79dbc2d69c6dcdd00f0750a1faac0e2d
4
+ data.tar.gz: 0fbb662869d4f5bb6c4fe1c9481fcdb842b6cfe8f7099568e9770364bed046d1
5
5
  SHA512:
6
- metadata.gz: 32fcaa8266c130541fa7a8683caa51923ed94abc4796b64cbc01c4e8aca8665477c5afb0eca6a4a9285d69a1cc122fea200b8af5fbbe8d93924c58d852e9b634
7
- data.tar.gz: 21ff141deab6d1fe9185679e51f476e86c6e4d324cf3d771324a8e94da1fd57f835d2f1c11d3d89acd862dd5ccd5a3668fa70af8a8e52b4654e9e8c6083f9840
6
+ metadata.gz: 187ff26d189951811d49dad748c7722baf91cf1160e62cdfbb219ebb7684cd61b814cc024d85cd7694f0dffac48c85fd5e4ac1c87ce811b2d4bb1aa2dfb102b4
7
+ data.tar.gz: 9c3c281bc54ee18b98bde43c0f2832c08a131715af13e0f747544e2d78791e1579a00bb23486d72c74c7ad44784604fd9cf63befc9788c3cfe60c5637cb75e97
data/CHANGELOG.md ADDED
@@ -0,0 +1,239 @@
1
+ 4.2.0 (2024-11-20)
2
+ ------------------
3
+
4
+ * Feature - DynamoDB Session Storage features now live in the `aws-actiondispatch-dynamodb` gem. This gem depends on `aws-sessionstore-dynamodb ~> 3` which depends on `rack ~> 3`.
5
+
6
+ * Feature - Add session store config generation with `rails generate dynamo_db:session_store_config`. Config generation is no longer tied to the DynamoDB SessionStore ActiveRecord migration generator.
7
+
8
+ * Issue - `ActionDispatch::Session::DynamoDbStore` now inherits `ActionDispatch::Session::AbstractStore` by wrapping `Aws::SessionStore::DynamoDB::RackMiddleware`.
9
+
10
+ * Issue - `DynamoDbStore` is now configured with the `:dynamo_db_store` configuration instead of `:dynamodb_store`.
11
+
12
+ * Feature - Session Store configuration passed into `:dynamo_db_store` in an initializer will now be considered when using the ActiveRecord migrations or rake tasks that create, delete, or clean session tables.
13
+
14
+ * Feature - `AWS_DYNAMO_DB_SESSION_CONFIG_FILE` is now searched and with precedence over the default Rails configuration YAML file locations.
15
+
16
+ * Feature - Prepare modularization of `aws-record`.
17
+
18
+ * Issue - Do not skip autoload modules for `Aws::Rails.instrument_sdk_operations`.
19
+
20
+ * Feature - ActionMailer SES and SESV2 mailers now live in the `aws-actionmailer-ses` gem.
21
+
22
+ * Feature - New namespace and class names for SES and SESV2 mailers. `Aws::Rails::SesMailer` has been moved to `Aws::ActionMailer::SES::Mailer` and `Aws::Rails::Sesv2Mailer` has been moved to `Aws::ActionMailer::SESV2::Mailer`. The classes have been symlinked for backwards compatibility in this major version.
23
+
24
+ * Issue - Add deprecation warning to `Aws::Rails.add_action_mailer_delivery_method` to instead use `ActionMailer::Base.add_delivery_method`. This method will be removed in aws-sdk-rails ~> 5.
25
+
26
+ * Feature - ActionMailbox SES ingress now lives in the `aws-actionmailbox-ses` gem.
27
+
28
+ * Issue - The `Aws::Rails::ActionMailbox::RSpec` module has been moved to `Aws::ActionMailbox::SES::RSpec` and will be removed in aws-sdk-rails ~> 5.
29
+
30
+ * Feature - ActiveJob SQS now lives in the `aws-activejob-sqs` gem.
31
+
32
+ * Feature - New namespace and class names for SQS ActiveJob. Existing namespace has temporarily been kept for backward compatibility and will be removed in aws-sdk-rails ~> 5.
33
+
34
+ * Issue - Correctly determine if SQSD is running in a Docker container.
35
+
36
+ * Feature - Aws::Record scaffold generators now lives in the `aws-record-rails` gem.
37
+
38
+ 4.1.0 (2024-09-27)
39
+ ------------------
40
+
41
+ * Feature - Add SDK eager loading to optimize load times. See: https://github.com/aws/aws-sdk-ruby/pull/3105.
42
+
43
+ 4.0.3 (2024-07-31)
44
+ ------------------
45
+
46
+ * Issue - Revert validating `:ses` or `:sesv2` as ActionMailer configuration. (#136)
47
+
48
+ 4.0.2 (2024-07-22)
49
+ ------------------
50
+
51
+ * Issue - Do not require `action_mailbox/engine` in `Aws::Rails::ActionMailbox::Engine` and instead check for its existence.
52
+
53
+ * Issue - Refactor the loading of the SQS ActiveJob adapter to be in `aws/rails/sqs_active_job`.
54
+
55
+ 4.0.1 (2024-07-18)
56
+ ------------------
57
+
58
+ * Issue - Require `action_mailbox/engine` from `Aws::Rails::ActionMailbox::Engine`.
59
+
60
+ 4.0.0 (2024-07-18)
61
+ ------------------
62
+
63
+ * Feature - Add support for Action Mailbox with SES (#127).
64
+
65
+ * Issue - Ensure `:ses` or `:sesv2` as ActionMailer configuration.
66
+
67
+ * Issue - Do not allow `:amazon`, `amazon_sqs`, or `amazon_sqs_async` for SQS active job configuration. Instead use `:sqs` and `:sqs_async`.
68
+
69
+ 3.13.0 (2024-06-06)
70
+ ------------------
71
+
72
+ * Feature - Use `Concurrent.available_processor_count` to set default thread pool max threads (#125).
73
+
74
+ * Issue - No longer rely on `caller_runs` for backpressure in sqs active job executor (#123).
75
+
76
+ 3.12.0 (2024-04-02)
77
+ ------------------
78
+ * Feature - Drop support for Ruby 2.3 and Ruby 2.4 (#117).
79
+ * Issue - Fix `EbsSqsActiveJobMiddleware` to detect Docker container with cgroup2. (#116).
80
+
81
+ 3.11.0 (2024-03-01)
82
+ ------------------
83
+
84
+ * Feature - Add `retry_standard_errors` (default `true`) in SQS ActiveJob and improve retry logic (#114).
85
+
86
+ 3.10.0 (2024-01-19)
87
+ ------------------
88
+
89
+ * Feature - Support `enqueue_all` in the SQS ActiveJob adapter.
90
+
91
+ * Issue - Improve `to_h` method's performance of `Aws::Rails::SqsActiveJob::Configuration`.
92
+
93
+ 3.9.1 (2023-12-19)
94
+ ------------------
95
+
96
+ * Issue - Fix negative `delay_seconds` being passed to parameter in the SQS adapter.
97
+
98
+ 3.9.0 (2023-09-28)
99
+ ------------------
100
+
101
+ * Feature - Add support for selectively choosing deduplication keys.
102
+
103
+ * Feature - Set required Ruby version to >= 2.3 (#104)
104
+
105
+ * Issue - Run `rubocop` on all files. (#104)
106
+
107
+ 3.8.0 (2023-06-02)
108
+ ------------------
109
+
110
+ * Feature - Improve User-Agent tracking and bump minimum SQS and SES versions.
111
+
112
+ 3.7.1 (2023-02-15)
113
+ ------------------
114
+
115
+ * Issue - Fix detecting docker host in `EbsSqsActiveJobMiddleware`.
116
+
117
+ 3.7.0 (2023-01-24)
118
+ ------------------
119
+
120
+ * Feature - Add SES v2 Mailer.
121
+
122
+ * Feature - Support smtp_envelope_from and _to in SES Mailer.
123
+
124
+ * Issue - Fix Ruby 3.1 usage by handling Psych 4 BadAlias error.
125
+
126
+ 3.6.4 (2022-10-13)
127
+ ------------------
128
+
129
+ * Issue - Use `request.ip` in `sent_from_docker_host?`.
130
+
131
+ 3.6.3 (2022-09-06)
132
+ ------------------
133
+
134
+ * Issue - Remove defaults for `visibility_timeout`: fallback to value configured on queue.
135
+ * Issue - Fix I18n localization bug in SQS adapters.
136
+
137
+ 3.6.2 (2022-06-16)
138
+ ------------------
139
+
140
+ * Issue - Fix DynamoDB session store to work with Rails 7.
141
+ * Issue - Allow for dynamic message group ids in FIFO Queues.
142
+
143
+ 3.6.1 (2021-06-08)
144
+ ------------------
145
+
146
+ * Issue - Fix credential loading to work with Rails 7.
147
+
148
+ 3.6.0 (2021-01-20)
149
+ ------------------
150
+
151
+ * Feature - Support for forwarding Elastic Beanstalk SQS Daemon requests to Active Job.
152
+
153
+ 3.5.0 (2021-01-06)
154
+ ------------------
155
+
156
+ * Feature - Add support for FIFO Queues to AWS SQS ActiveJob.
157
+
158
+ 3.4.0 (2020-12-07)
159
+ ------------------
160
+
161
+ * Feature - Add a non-blocking async ActiveJob adapter: `:amazon_sqs_async`.
162
+
163
+ * Feature - Add a lambda handler for processing active jobs from an SQS trigger.
164
+
165
+ * Issue - Fix bug in default for backpressure config.
166
+
167
+ 3.3.0 (2020-12-01)
168
+ ------------------
169
+
170
+ * Feature - Add `aws-record` as a dependency, a rails generator for `aws-record` models, and a rake task for table migrations.
171
+
172
+ * Feature - Add AWS SQS ActiveJob - A lightweight, SQS backend for ActiveJob.
173
+
174
+ 3.2.1 (2020-11-13)
175
+ ------------------
176
+
177
+ * Issue - Include missing files into the gemspec.
178
+
179
+ 3.2.0 (2020-11-13)
180
+ ------------------
181
+
182
+ * Feature - Add support for `ActiveSupport::Notifications` for instrumenting AWS SDK service calls.
183
+
184
+ * Feature - Add support for DynamoDB as an `ActiveDispatch::Session`.
185
+
186
+ 3.1.0 (2020-04-06)
187
+ ------------------
188
+ * Issue - Merge only credential related keys from Rails encrypted credentials into `Aws.config`.
189
+
190
+ 3.0.5 (2019-10-17)
191
+ ------------------
192
+
193
+ * Upgrading - Adds support for Rails Encrypted Credentials, requiring Rails 5.2+
194
+ and thus needed a new major version. Consequently drops support for Ruby < 2.3
195
+ and for Rails < 5.2. Delivery method configuration changed from `:aws_sdk` to
196
+ `:ses`, to allow for future delivery methods. Adds rubocop to the package and
197
+ fixed many violations. This test framework now includes a dummy application for
198
+ testing future features.
199
+
200
+ 2.1.0 (2019-02-14)
201
+ ------------------
202
+
203
+ * Feature - Aws::Rails::Mailer - Adds the Amazon SES message ID as a header to
204
+ raw emails after sending, for tracking purposes. See
205
+ [related GitHub pull request #25](https://github.com/aws/aws-sdk-rails/pull/25).
206
+
207
+ 2.0.1 (2017-10-03)
208
+ ------------------
209
+
210
+ * Issue - Ensure `aws-sdk-rails.initialize` executes before
211
+ `load_config_initializers`
212
+
213
+ 2.0.0 (2017-08-29)
214
+ ------------------
215
+
216
+ * Upgrading - Support version 3 of the AWS SDK for Ruby. This is being released
217
+ as major version 2 of `aws-sdk-rails`, though the APIs remain the same. Do note,
218
+ however, that we've changed our SDK dependency to only depend on `aws-sdk-ses`.
219
+ This means that if you were depending on other service clients transitively via
220
+ `aws-sdk-rails`, you will need to add dependencies on the appropriate service
221
+ gems when upgrading. Logger integration will work for other service gems you
222
+ depend on, since it is wired up against `aws-sdk-core` which is included in
223
+ the `aws-sdk-ses` dependency.
224
+
225
+ 1.0.1 (2016-02-01)
226
+ ------------------
227
+
228
+ * Feature - Gemfile - Replaced `rails` gem dependency with `railties`
229
+ dependency. With this change, applications that bring their own dependencies
230
+ in place of, for example, ActiveRecord, can do so with reduced bloat.
231
+
232
+ See [related GitHub pull request
233
+ #4](https://github.com/aws/aws-sdk-rails/pull/4).
234
+
235
+ 1.0.0 (2015-03-17)
236
+ ------------------
237
+
238
+ * Initial Release: Support for Amazon Simple Email Service and Rails Logger
239
+ integration.
data/LICENSE.txt ADDED
@@ -0,0 +1,12 @@
1
+ Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ may not use this file except in compliance with the License. A copy of
5
+ the License is located at
6
+
7
+ http://aws.amazon.com/apache2.0/
8
+
9
+ or in the "license" file accompanying this file. This file is
10
+ distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ ANY KIND, either express or implied. See the License for the specific
12
+ language governing permissions and limitations under the License.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.0.3
1
+ 4.2.0
@@ -1,69 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'aws/rails/action_mailbox/rspec/email'
4
- require 'aws/rails/action_mailbox/rspec/subscription_confirmation'
5
- require 'aws-sdk-sns'
6
- require 'aws/rails/action_mailbox/sns_message_verifier'
3
+ # This can be deleted in aws-sdk-rails ~> 5
7
4
 
8
- module Aws
9
- module Rails
10
- module ActionMailbox
11
- # Include the `Aws::Rails::ActionMailbox::RSpec` extension in your tests, like so:
12
- # require 'aws/rails/action_mailbox/rspec'
13
- # RSpec.configure do |config|
14
- # config.include Aws::Rails::ActionMailbox::RSpec
15
- # end
16
- # Then, in a request spec, use like so:
17
- # RSpec.describe 'amazon emails', type: :request do
18
- # it 'delivers a subscription notification' do
19
- # action_mailbox_ses_deliver_subscription_confirmation
20
- # expect(response).to have_http_status :ok
21
- # end
5
+ require 'aws/action_mailbox/ses/rspec'
6
+ Aws::Rails::ActionMailbox::RSpec = Aws::ActionMailbox::SES::RSpec
22
7
 
23
- # it 'delivers an email notification' do
24
- # action_mailbox_ses_deliver_email(mail: Mail.new(to: 'user@example.com'))
25
- # expect(ActionMailbox::InboundEmail.last.mail.recipients).to eql ['user@example.com']
26
- # end
27
- # end
28
- module RSpec
29
- def action_mailbox_ses_deliver_subscription_confirmation(options = {})
30
- subscription_confirmation = SubscriptionConfirmation.new(**options)
31
- stub_aws_sns_message_verifier(subscription_confirmation)
32
- stub_aws_sns_subscription_request
33
-
34
- post subscription_confirmation.url,
35
- params: subscription_confirmation.params,
36
- headers: subscription_confirmation.headers,
37
- as: :json
38
- end
39
-
40
- def action_mailbox_ses_deliver_email(options = {})
41
- email = Email.new(**options)
42
- stub_aws_sns_message_verifier(email)
43
-
44
- post email.url,
45
- params: email.params,
46
- headers: email.headers,
47
- as: :json
48
- end
49
-
50
- private
51
-
52
- def message_verifier(subscription_confirmation)
53
- instance_double(Aws::SNS::MessageVerifier, authentic?: subscription_confirmation.authentic?)
54
- end
55
-
56
- def stub_aws_sns_message_verifier(notification)
57
- allow(Aws::Rails::ActionMailbox::SnsMessageVerifier).to receive(:verifier) { message_verifier(notification) }
58
- end
59
-
60
- def stub_aws_sns_subscription_request
61
- allow(Net::HTTP).to receive(:get_response).and_call_original
62
- allow(Net::HTTP)
63
- .to receive(:get_response)
64
- .with(URI('http://example.com/subscribe')) { double(code: '200') }
65
- end
66
- end
67
- end
68
- end
69
- end
8
+ Kernel.warn('Aws::Rails::ActionMailbox::RSpec is deprecated in aws-sdk-rails ~> 5. ' \
9
+ 'Use Aws::ActionMailbox::SES::RSpec instead.')
10
+ Kernel.warn('Please require "aws/action_mailbox/ses/rspec" instead of "aws/rails/action_mailbox/rspec"')
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Rails
5
+ module Middleware
6
+ # Middleware to handle requests from the SQS Daemon present on Elastic Beanstalk worker environments.
7
+ class ElasticBeanstalkSQSD
8
+ def initialize(app)
9
+ @app = app
10
+ @logger = ::Rails.logger
11
+ end
12
+
13
+ def call(env)
14
+ request = ::ActionDispatch::Request.new(env)
15
+
16
+ # Pass through unless user agent is the SQS Daemon
17
+ return @app.call(env) unless from_sqs_daemon?(request)
18
+
19
+ @logger.debug('aws-sdk-rails middleware detected call from Elastic Beanstalk SQS Daemon.')
20
+
21
+ # Only accept requests from this user agent if it is from localhost or a docker host in case of forgery.
22
+ unless request.local? || sent_from_docker_host?(request)
23
+ @logger.warn('SQSD request detected from untrusted address; returning 403 forbidden.')
24
+ return forbidden_response
25
+ end
26
+
27
+ # Execute job or periodic task based on HTTP request context
28
+ periodic_task?(request) ? execute_periodic_task(request) : execute_job(request)
29
+ end
30
+
31
+ private
32
+
33
+ def execute_job(request)
34
+ # Jobs queued from the Active Job SQS adapter contain the JSON message in the request body.
35
+ job = Aws::Json.load(request.body.string)
36
+ job_name = job['job_class']
37
+ @logger.debug("Executing job: #{job_name}")
38
+
39
+ begin
40
+ ::ActiveJob::Base.execute(job)
41
+ rescue NameError => e
42
+ @logger.error("Job #{job_name} could not resolve to a class that inherits from Active Job.")
43
+ @logger.error("Error: #{e}")
44
+ return internal_error_response
45
+ end
46
+
47
+ [200, { 'Content-Type' => 'text/plain' }, ["Successfully ran job #{job_name}."]]
48
+ end
49
+
50
+ def execute_periodic_task(request)
51
+ # The beanstalk worker SQS Daemon will add the 'X-Aws-Sqsd-Taskname' for periodic tasks set in cron.yaml.
52
+ job_name = request.headers['X-Aws-Sqsd-Taskname']
53
+ @logger.debug("Creating and executing periodic task: #{job_name}")
54
+
55
+ begin
56
+ job = job_name.constantize.new
57
+ job.perform_now
58
+ rescue NameError => e
59
+ @logger.error("Periodic task #{job_name} could not resolve to an Active Job class - check the spelling in cron.yaml.")
60
+ @logger.error("Error: #{e}.")
61
+ return internal_error_response
62
+ end
63
+
64
+ [200, { 'Content-Type' => 'text/plain' }, ["Successfully ran periodic task #{job_name}."]]
65
+ end
66
+
67
+ def internal_error_response
68
+ message = 'Failed to execute job - see Rails log for more details.'
69
+ [500, { 'Content-Type' => 'text/plain' }, [message]]
70
+ end
71
+
72
+ def forbidden_response
73
+ message = 'Request with aws-sqsd user agent was made from untrusted address.'
74
+ [403, { 'Content-Type' => 'text/plain' }, [message]]
75
+ end
76
+
77
+ # The beanstalk worker SQS Daemon sets a specific User-Agent headers that begins with 'aws-sqsd'.
78
+ def from_sqs_daemon?(request)
79
+ current_user_agent = request.headers['User-Agent']
80
+
81
+ !current_user_agent.nil? && current_user_agent.start_with?('aws-sqsd')
82
+ end
83
+
84
+ # The beanstalk worker SQS Daemon will add the custom 'X-Aws-Sqsd-Taskname' header
85
+ # for periodic tasks set in cron.yaml.
86
+ def periodic_task?(request)
87
+ !request.headers['X-Aws-Sqsd-Taskname'].nil? && request.headers['X-Aws-Sqsd-Taskname'].present?
88
+ end
89
+
90
+ def sent_from_docker_host?(request)
91
+ app_runs_in_docker_container? && ip_originates_from_docker_host?(request)
92
+ end
93
+
94
+ def app_runs_in_docker_container?
95
+ @app_runs_in_docker_container ||= in_docker_container_with_cgroup1? || in_docker_container_with_cgroup2?
96
+ end
97
+
98
+ def in_docker_container_with_cgroup1?
99
+ File.exist?('/proc/1/cgroup') && File.read('/proc/1/cgroup') =~ %r{/docker/}
100
+ end
101
+
102
+ def in_docker_container_with_cgroup2?
103
+ File.exist?('/proc/self/mountinfo') && File.read('/proc/self/mountinfo') =~ %r{/docker/containers/}
104
+ end
105
+
106
+ def ip_originates_from_docker_host?(request)
107
+ default_docker_ips.include?(request.remote_ip) ||
108
+ default_docker_ips.include?(request.remote_addr)
109
+ end
110
+
111
+ def default_docker_ips
112
+ @default_docker_ips ||= build_default_docker_ips
113
+ end
114
+
115
+ def build_default_docker_ips
116
+ default_gw_ips = ['172.17.0.1']
117
+
118
+ if File.exist?('/proc/net/route')
119
+ File.open('/proc/net/route').each_line do |line|
120
+ fields = line.strip.split
121
+ next if fields.size != 11
122
+ # Destination == 0.0.0.0 and Flags & RTF_GATEWAY != 0
123
+ next unless fields[1] == '00000000' && fields[3].hex.anybits?(0x2)
124
+
125
+ default_gw_ips << IPAddr.new_ntoh([fields[2].hex].pack('L')).to_s
126
+ end
127
+ end
128
+
129
+ default_gw_ips
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
@@ -5,18 +5,15 @@ require 'active_support/notifications'
5
5
 
6
6
  module Aws
7
7
  module Rails
8
- # Instruments client operation calls for ActiveSupport::Notifications
9
- # Each client operation will produce an event with name:
10
- # <operation>.<service>.aws
11
8
  # @api private
12
9
  class Notifications < Seahorse::Client::Plugin
10
+ # This plugin needs to be first, which means it is called first in the stack,
11
+ # to start recording time, and returns last
13
12
  def add_handlers(handlers, _config)
14
- # This plugin needs to be first
15
- # which means it is called first in the stack, to start recording time,
16
- # and returns last
17
13
  handlers.add(Handler, step: :initialize, priority: 99)
18
14
  end
19
15
 
16
+ # @api private
20
17
  class Handler < Seahorse::Client::Handler
21
18
  def call(context)
22
19
  event_name = "#{context.operation_name}.#{context.config.api.metadata['serviceId']}.aws"
@@ -8,22 +8,60 @@ module Aws
8
8
  initializer 'aws-sdk-rails.initialize',
9
9
  before: :load_config_initializers do
10
10
  # Initialization Actions
11
+ Aws::Rails.log_to_rails_logger
11
12
  Aws::Rails.use_rails_encrypted_credentials
12
13
  Aws::Rails.add_action_mailer_delivery_method
13
14
  Aws::Rails.add_action_mailer_delivery_method(:sesv2)
14
- Aws::Rails.log_to_rails_logger
15
+
16
+ if %i[ses sesv2].include?(::Rails.application.config.action_mailer.delivery_method)
17
+ ::Rails.logger.warn(<<~MSG)
18
+ ** Aws::Rails.add_action_mailer_delivery_method will be removed in aws-sdk-rails ~> 5.
19
+ In `aws-actionmailer-ses ~> 1`, configuration will be set using config settings:
20
+
21
+ config.action_mailer.delivery_method = :ses_v2
22
+ config.action_mailer.ses_v2_settings = { region: 'us-west-2' }
23
+
24
+ Existing Mailer classes have moved namespaces but will continue to work in this major version. **
25
+ MSG
26
+ end
15
27
  end
16
28
 
17
29
  initializer 'aws-sdk-rails.insert_middleware' do |app|
18
30
  Aws::Rails.add_sqsd_middleware(app)
19
31
  end
20
32
 
21
- rake_tasks do
22
- load 'tasks/dynamo_db/session_store.rake'
23
- load 'tasks/aws_record/migrate.rake'
33
+ initializer 'aws-sdk-rails.eager_load' do
34
+ Aws.define_singleton_method(:eager_load!) do
35
+ Aws.constants.each do |c|
36
+ m = Aws.const_get(c)
37
+ next unless m.is_a?(Module)
38
+
39
+ m.constants.each do |constant|
40
+ m.const_get(constant)
41
+ end
42
+ end
43
+ end
44
+
45
+ config.before_eager_load do
46
+ config.eager_load_namespaces << Aws
47
+ end
24
48
  end
25
49
  end
26
50
 
51
+ # Configures the AWS SDK for Ruby's logger to use the Rails logger.
52
+ def self.log_to_rails_logger
53
+ Aws.config[:logger] = ::Rails.logger
54
+ nil
55
+ end
56
+
57
+ # Configures the AWS SDK with credentials from Rails encrypted credentials.
58
+ def self.use_rails_encrypted_credentials
59
+ # limit the config keys we merge to credentials only
60
+ aws_credential_keys = %i[access_key_id secret_access_key session_token account_id]
61
+ creds = ::Rails.application.credentials[:aws].to_h.slice(*aws_credential_keys)
62
+ Aws.config.merge!(creds)
63
+ end
64
+
27
65
  # This is called automatically from the SDK's Railtie, but can be manually
28
66
  # called if you want to specify options for building the Aws::SES::Client or
29
67
  # Aws::SESV2::Client.
@@ -33,8 +71,7 @@ module Aws
33
71
  # @param [Hash] client_options The options you wish to pass on to the
34
72
  # Aws::SES[V2]::Client initialization method.
35
73
  def self.add_action_mailer_delivery_method(name = :ses, client_options = {})
36
- # TODO: on the next major version, add a "mailer" param to this method
37
- # and use it to determine which mailer to use, keeping name free-form.
74
+ # TODO: remove this method in aws-sdk-rails ~> 5
38
75
  ActiveSupport.on_load(:action_mailer) do
39
76
  if name == :sesv2
40
77
  add_delivery_method(name, Aws::Rails::Sesv2Mailer, client_options)
@@ -44,31 +81,14 @@ module Aws
44
81
  end
45
82
  end
46
83
 
47
- # Configures the AWS SDK for Ruby's logger to use the Rails logger.
48
- def self.log_to_rails_logger
49
- Aws.config[:logger] = ::Rails.logger
50
- nil
51
- end
52
-
53
- # Configures the AWS SDK with credentials from Rails encrypted credentials.
54
- def self.use_rails_encrypted_credentials
55
- # limit the config keys we merge to credentials only
56
- aws_credential_keys = %i[access_key_id secret_access_key session_token]
57
-
58
- Aws.config.merge!(
59
- ::Rails.application.credentials[:aws].to_h.slice(*aws_credential_keys)
60
- )
61
- end
62
-
63
- # Adds ActiveSupport Notifications instrumentation to AWS SDK
64
- # client operations. Each operation will produce an event with a name:
65
- # <operation>.<service>.aws. For example, S3's put_object has an event
66
- # name of: put_object.S3.aws
84
+ # Add ActiveSupport Notifications instrumentation to AWS SDK client operations.
85
+ # Each operation will produce an event with a name `<operation>.<service>.aws`.
86
+ # For example, S3's put_object has an event name of: put_object.S3.aws
67
87
  def self.instrument_sdk_operations
68
88
  Aws.constants.each do |c|
69
89
  m = Aws.const_get(c)
70
90
  if m.is_a?(Module) && m.const_defined?(:Client) &&
71
- m.const_get(:Client).superclass == Seahorse::Client::Base
91
+ (client = m.const_get(:Client)) && client.superclass == Seahorse::Client::Base
72
92
  m.const_get(:Client).add_plugin(Aws::Rails::Notifications)
73
93
  end
74
94
  end
@@ -78,15 +98,13 @@ module Aws
78
98
  # This will only be added in the presence of the AWS_PROCESS_BEANSTALK_WORKER_REQUESTS environment variable.
79
99
  # The expectation is this variable should only be set on EB worker environments.
80
100
  def self.add_sqsd_middleware(app)
81
- is_eb_worker_hosted = Aws::Util.str_2_bool(ENV['AWS_PROCESS_BEANSTALK_WORKER_REQUESTS'].to_s.downcase)
82
-
83
- return unless is_eb_worker_hosted
101
+ return unless ENV['AWS_PROCESS_BEANSTALK_WORKER_REQUESTS']
84
102
 
85
103
  if app.config.force_ssl
86
104
  # SQS Daemon sends requests over HTTP - allow and process them before enforcing SSL.
87
- app.config.middleware.insert_before(ActionDispatch::SSL, Aws::Rails::EbsSqsActiveJobMiddleware)
105
+ app.config.middleware.insert_before(::ActionDispatch::SSL, Aws::Rails::Middleware::ElasticBeanstalkSQSD)
88
106
  else
89
- app.config.middleware.use(Aws::Rails::EbsSqsActiveJobMiddleware)
107
+ app.config.middleware.use(Aws::Rails::Middleware::ElasticBeanstalkSQSD)
90
108
  end
91
109
  end
92
110
  end
data/lib/aws-sdk-rails.rb CHANGED
@@ -1,19 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'aws/rails/ses_mailer'
4
- require_relative 'aws/rails/sesv2_mailer'
3
+ require_relative 'aws/rails/middleware/elastic_beanstalk_sqsd'
5
4
  require_relative 'aws/rails/railtie'
6
- require_relative 'aws/rails/action_mailbox/engine'
7
5
  require_relative 'aws/rails/notifications'
8
- require_relative 'aws/rails/sqs_active_job'
9
- require_relative 'aws/rails/middleware/ebs_sqs_active_job_middleware'
10
6
 
11
- require_relative 'action_dispatch/session/dynamodb_store'
12
-
13
- require_relative 'generators/aws_record/base'
7
+ # remove these in aws-sdk-rails 5
8
+ require 'aws-actiondispatch-dynamodb'
9
+ require 'aws-actionmailbox-ses' if defined?(ActionMailbox::Engine)
10
+ require 'aws-actionmailer-ses'
11
+ require 'aws-activejob-sqs'
12
+ require 'aws-record-rails'
14
13
 
15
14
  module Aws
16
15
  module Rails
17
16
  VERSION = File.read(File.expand_path('../VERSION', __dir__)).strip
18
17
  end
19
18
  end
19
+
20
+ # remove these in aws-sdk-rails 5
21
+ Aws::Rails::SqsActiveJob = Aws::ActiveJob::SQS
22
+ Aws::Rails::EbsSqsActiveJobMiddleware = Aws::Rails::Middleware::ElasticBeanstalkSQSD
23
+ Aws::Rails::SesMailer = Aws::ActionMailer::SES::Mailer
24
+ Aws::Rails::Sesv2Mailer = Aws::ActionMailer::SESV2::Mailer
25
+ # This is for backwards compatibility after introducing support for SESv2.
26
+ # The old mailer is now replaced with the new SES (v1) mailer.
27
+ Aws::Rails::Mailer = Aws::Rails::SesMailer