aws-sdk-rails 4.1.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +256 -0
- data/LICENSE.txt +12 -0
- data/VERSION +1 -1
- data/lib/aws/rails/middleware/elastic_beanstalk_sqsd.rb +141 -0
- data/lib/aws/rails/notifications.rb +5 -7
- data/lib/aws/rails/railtie.rb +38 -77
- data/lib/aws-sdk-rails.rb +1 -9
- metadata +14 -197
- data/app/controllers/action_mailbox/ingresses/ses/inbound_emails_controller.rb +0 -79
- data/bin/aws_sqs_active_job +0 -6
- data/config/routes.rb +0 -8
- data/lib/action_dispatch/session/dynamodb_store.rb +0 -38
- data/lib/active_job/queue_adapters/sqs_adapter/params.rb +0 -78
- data/lib/active_job/queue_adapters/sqs_adapter.rb +0 -58
- data/lib/active_job/queue_adapters/sqs_async_adapter.rb +0 -39
- data/lib/aws/rails/action_mailbox/engine.rb +0 -21
- data/lib/aws/rails/action_mailbox/rspec/email.rb +0 -50
- data/lib/aws/rails/action_mailbox/rspec/subscription_confirmation.rb +0 -37
- data/lib/aws/rails/action_mailbox/rspec.rb +0 -69
- data/lib/aws/rails/action_mailbox/s3_client.rb +0 -28
- data/lib/aws/rails/action_mailbox/sns_message_verifier.rb +0 -18
- data/lib/aws/rails/action_mailbox/sns_notification.rb +0 -99
- data/lib/aws/rails/middleware/ebs_sqs_active_job_middleware.rb +0 -118
- data/lib/aws/rails/ses_mailer.rb +0 -49
- data/lib/aws/rails/sesv2_mailer.rb +0 -60
- data/lib/aws/rails/sqs_active_job/configuration.rb +0 -184
- data/lib/aws/rails/sqs_active_job/deduplication.rb +0 -21
- data/lib/aws/rails/sqs_active_job/executor.rb +0 -77
- data/lib/aws/rails/sqs_active_job/job_runner.rb +0 -27
- data/lib/aws/rails/sqs_active_job/lambda_handler.rb +0 -63
- data/lib/aws/rails/sqs_active_job/poller.rb +0 -160
- data/lib/aws/rails/sqs_active_job.rb +0 -33
- data/lib/generators/aws_record/base.rb +0 -213
- data/lib/generators/aws_record/generated_attribute.rb +0 -138
- data/lib/generators/aws_record/model/USAGE +0 -24
- data/lib/generators/aws_record/model/model_generator.rb +0 -25
- data/lib/generators/aws_record/model/templates/model.erb +0 -48
- data/lib/generators/aws_record/model/templates/table_config.erb +0 -18
- data/lib/generators/aws_record/secondary_index.rb +0 -66
- data/lib/generators/dynamo_db/session_store_migration/USAGE +0 -13
- data/lib/generators/dynamo_db/session_store_migration/session_store_migration_generator.rb +0 -48
- data/lib/generators/dynamo_db/session_store_migration/templates/dynamo_db_session_store.yml +0 -70
- data/lib/generators/dynamo_db/session_store_migration/templates/session_store_migration.erb +0 -9
- data/lib/tasks/aws_record/migrate.rake +0 -14
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7354b35727ee37128ccb8b13f94a4d0564518e02e1acaf87086a3664fbea719
|
4
|
+
data.tar.gz: 8c9aae1eb8fed5ee9c4dca9d74fadd95619a0d05c455c9164dca9310002199db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3c645120b3787a041900edd7365dec40d766807bc6c11fe81cd6788909d3f180c549fbd0e9071acfeefcd8608cc2e7d3d99f8f53d4ebf611742a33683eeddf0
|
7
|
+
data.tar.gz: 49743ff5d71ed4dfe915e6aa80cb6d1f1fdb6ba18d783330faae0e320435af92bb32ed78a042b3cb3be486e4a5cdf3826c723d36272a89a599c7f00c85ec0eca
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,256 @@
|
|
1
|
+
5.0.0 (2024-11-21)
|
2
|
+
------------------
|
3
|
+
|
4
|
+
* Feature - [Major Version] Remove dependencies on modular feature gems: `aws-actiondispatch-dynamodb`, `aws-actionmailer-ses`, `aws-actionmailbox-ses`, `aws-activejob-sqs`, and `aws-record-rails`.
|
5
|
+
|
6
|
+
* Issue - Remove `Aws::Rails.add_action_mailer_delivery_method` in favor of `ActionMailer::Base.add_delivery_method` or the Railtie and configuration in `aws-actionmailer-ses ~> 1`.
|
7
|
+
|
8
|
+
* Issue - Remove require of `aws/rails/action_mailbox/rspec` in favor of `aws/action_mailbox/ses/rspec`.
|
9
|
+
|
10
|
+
* Issue - Remove symlinked namespaces from previous major versions.
|
11
|
+
|
12
|
+
* Feature - `ActiveSupport::Notifications` are enabled by default and removes `Aws::Rails.instrument_sdk_operations`.
|
13
|
+
|
14
|
+
* Feature - Moved railtie initializations to their appropriate spots.
|
15
|
+
|
16
|
+
* Issue - Do not execute `ActiveJob` from EB cron without the root path.
|
17
|
+
|
18
|
+
4.2.0 (2024-11-20)
|
19
|
+
------------------
|
20
|
+
|
21
|
+
* 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`.
|
22
|
+
|
23
|
+
* 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.
|
24
|
+
|
25
|
+
* Issue - `ActionDispatch::Session::DynamoDbStore` now inherits `ActionDispatch::Session::AbstractStore` by wrapping `Aws::SessionStore::DynamoDB::RackMiddleware`.
|
26
|
+
|
27
|
+
* Issue - `DynamoDbStore` is now configured with the `:dynamo_db_store` configuration instead of `:dynamodb_store`.
|
28
|
+
|
29
|
+
* 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.
|
30
|
+
|
31
|
+
* Feature - `AWS_DYNAMO_DB_SESSION_CONFIG_FILE` is now searched and with precedence over the default Rails configuration YAML file locations.
|
32
|
+
|
33
|
+
* Feature - Prepare modularization of `aws-record`.
|
34
|
+
|
35
|
+
* Issue - Do not skip autoload modules for `Aws::Rails.instrument_sdk_operations`.
|
36
|
+
|
37
|
+
* Feature - ActionMailer SES and SESV2 mailers now live in the `aws-actionmailer-ses` gem.
|
38
|
+
|
39
|
+
* 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.
|
40
|
+
|
41
|
+
* 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.
|
42
|
+
|
43
|
+
* Feature - ActionMailbox SES ingress now lives in the `aws-actionmailbox-ses` gem.
|
44
|
+
|
45
|
+
* Issue - The `Aws::Rails::ActionMailbox::RSpec` module has been moved to `Aws::ActionMailbox::SES::RSpec` and will be removed in aws-sdk-rails ~> 5.
|
46
|
+
|
47
|
+
* Feature - ActiveJob SQS now lives in the `aws-activejob-sqs` gem.
|
48
|
+
|
49
|
+
* 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.
|
50
|
+
|
51
|
+
* Issue - Correctly determine if SQSD is running in a Docker container.
|
52
|
+
|
53
|
+
* Feature - Aws::Record scaffold generators now lives in the `aws-record-rails` gem.
|
54
|
+
|
55
|
+
4.1.0 (2024-09-27)
|
56
|
+
------------------
|
57
|
+
|
58
|
+
* Feature - Add SDK eager loading to optimize load times. See: https://github.com/aws/aws-sdk-ruby/pull/3105.
|
59
|
+
|
60
|
+
4.0.3 (2024-07-31)
|
61
|
+
------------------
|
62
|
+
|
63
|
+
* Issue - Revert validating `:ses` or `:sesv2` as ActionMailer configuration. (#136)
|
64
|
+
|
65
|
+
4.0.2 (2024-07-22)
|
66
|
+
------------------
|
67
|
+
|
68
|
+
* Issue - Do not require `action_mailbox/engine` in `Aws::Rails::ActionMailbox::Engine` and instead check for its existence.
|
69
|
+
|
70
|
+
* Issue - Refactor the loading of the SQS ActiveJob adapter to be in `aws/rails/sqs_active_job`.
|
71
|
+
|
72
|
+
4.0.1 (2024-07-18)
|
73
|
+
------------------
|
74
|
+
|
75
|
+
* Issue - Require `action_mailbox/engine` from `Aws::Rails::ActionMailbox::Engine`.
|
76
|
+
|
77
|
+
4.0.0 (2024-07-18)
|
78
|
+
------------------
|
79
|
+
|
80
|
+
* Feature - Add support for Action Mailbox with SES (#127).
|
81
|
+
|
82
|
+
* Issue - Ensure `:ses` or `:sesv2` as ActionMailer configuration.
|
83
|
+
|
84
|
+
* Issue - Do not allow `:amazon`, `amazon_sqs`, or `amazon_sqs_async` for SQS active job configuration. Instead use `:sqs` and `:sqs_async`.
|
85
|
+
|
86
|
+
3.13.0 (2024-06-06)
|
87
|
+
------------------
|
88
|
+
|
89
|
+
* Feature - Use `Concurrent.available_processor_count` to set default thread pool max threads (#125).
|
90
|
+
|
91
|
+
* Issue - No longer rely on `caller_runs` for backpressure in sqs active job executor (#123).
|
92
|
+
|
93
|
+
3.12.0 (2024-04-02)
|
94
|
+
------------------
|
95
|
+
* Feature - Drop support for Ruby 2.3 and Ruby 2.4 (#117).
|
96
|
+
* Issue - Fix `EbsSqsActiveJobMiddleware` to detect Docker container with cgroup2. (#116).
|
97
|
+
|
98
|
+
3.11.0 (2024-03-01)
|
99
|
+
------------------
|
100
|
+
|
101
|
+
* Feature - Add `retry_standard_errors` (default `true`) in SQS ActiveJob and improve retry logic (#114).
|
102
|
+
|
103
|
+
3.10.0 (2024-01-19)
|
104
|
+
------------------
|
105
|
+
|
106
|
+
* Feature - Support `enqueue_all` in the SQS ActiveJob adapter.
|
107
|
+
|
108
|
+
* Issue - Improve `to_h` method's performance of `Aws::Rails::SqsActiveJob::Configuration`.
|
109
|
+
|
110
|
+
3.9.1 (2023-12-19)
|
111
|
+
------------------
|
112
|
+
|
113
|
+
* Issue - Fix negative `delay_seconds` being passed to parameter in the SQS adapter.
|
114
|
+
|
115
|
+
3.9.0 (2023-09-28)
|
116
|
+
------------------
|
117
|
+
|
118
|
+
* Feature - Add support for selectively choosing deduplication keys.
|
119
|
+
|
120
|
+
* Feature - Set required Ruby version to >= 2.3 (#104)
|
121
|
+
|
122
|
+
* Issue - Run `rubocop` on all files. (#104)
|
123
|
+
|
124
|
+
3.8.0 (2023-06-02)
|
125
|
+
------------------
|
126
|
+
|
127
|
+
* Feature - Improve User-Agent tracking and bump minimum SQS and SES versions.
|
128
|
+
|
129
|
+
3.7.1 (2023-02-15)
|
130
|
+
------------------
|
131
|
+
|
132
|
+
* Issue - Fix detecting docker host in `EbsSqsActiveJobMiddleware`.
|
133
|
+
|
134
|
+
3.7.0 (2023-01-24)
|
135
|
+
------------------
|
136
|
+
|
137
|
+
* Feature - Add SES v2 Mailer.
|
138
|
+
|
139
|
+
* Feature - Support smtp_envelope_from and _to in SES Mailer.
|
140
|
+
|
141
|
+
* Issue - Fix Ruby 3.1 usage by handling Psych 4 BadAlias error.
|
142
|
+
|
143
|
+
3.6.4 (2022-10-13)
|
144
|
+
------------------
|
145
|
+
|
146
|
+
* Issue - Use `request.ip` in `sent_from_docker_host?`.
|
147
|
+
|
148
|
+
3.6.3 (2022-09-06)
|
149
|
+
------------------
|
150
|
+
|
151
|
+
* Issue - Remove defaults for `visibility_timeout`: fallback to value configured on queue.
|
152
|
+
* Issue - Fix I18n localization bug in SQS adapters.
|
153
|
+
|
154
|
+
3.6.2 (2022-06-16)
|
155
|
+
------------------
|
156
|
+
|
157
|
+
* Issue - Fix DynamoDB session store to work with Rails 7.
|
158
|
+
* Issue - Allow for dynamic message group ids in FIFO Queues.
|
159
|
+
|
160
|
+
3.6.1 (2021-06-08)
|
161
|
+
------------------
|
162
|
+
|
163
|
+
* Issue - Fix credential loading to work with Rails 7.
|
164
|
+
|
165
|
+
3.6.0 (2021-01-20)
|
166
|
+
------------------
|
167
|
+
|
168
|
+
* Feature - Support for forwarding Elastic Beanstalk SQS Daemon requests to Active Job.
|
169
|
+
|
170
|
+
3.5.0 (2021-01-06)
|
171
|
+
------------------
|
172
|
+
|
173
|
+
* Feature - Add support for FIFO Queues to AWS SQS ActiveJob.
|
174
|
+
|
175
|
+
3.4.0 (2020-12-07)
|
176
|
+
------------------
|
177
|
+
|
178
|
+
* Feature - Add a non-blocking async ActiveJob adapter: `:amazon_sqs_async`.
|
179
|
+
|
180
|
+
* Feature - Add a lambda handler for processing active jobs from an SQS trigger.
|
181
|
+
|
182
|
+
* Issue - Fix bug in default for backpressure config.
|
183
|
+
|
184
|
+
3.3.0 (2020-12-01)
|
185
|
+
------------------
|
186
|
+
|
187
|
+
* Feature - Add `aws-record` as a dependency, a rails generator for `aws-record` models, and a rake task for table migrations.
|
188
|
+
|
189
|
+
* Feature - Add AWS SQS ActiveJob - A lightweight, SQS backend for ActiveJob.
|
190
|
+
|
191
|
+
3.2.1 (2020-11-13)
|
192
|
+
------------------
|
193
|
+
|
194
|
+
* Issue - Include missing files into the gemspec.
|
195
|
+
|
196
|
+
3.2.0 (2020-11-13)
|
197
|
+
------------------
|
198
|
+
|
199
|
+
* Feature - Add support for `ActiveSupport::Notifications` for instrumenting AWS SDK service calls.
|
200
|
+
|
201
|
+
* Feature - Add support for DynamoDB as an `ActiveDispatch::Session`.
|
202
|
+
|
203
|
+
3.1.0 (2020-04-06)
|
204
|
+
------------------
|
205
|
+
* Issue - Merge only credential related keys from Rails encrypted credentials into `Aws.config`.
|
206
|
+
|
207
|
+
3.0.5 (2019-10-17)
|
208
|
+
------------------
|
209
|
+
|
210
|
+
* Upgrading - Adds support for Rails Encrypted Credentials, requiring Rails 5.2+
|
211
|
+
and thus needed a new major version. Consequently drops support for Ruby < 2.3
|
212
|
+
and for Rails < 5.2. Delivery method configuration changed from `:aws_sdk` to
|
213
|
+
`:ses`, to allow for future delivery methods. Adds rubocop to the package and
|
214
|
+
fixed many violations. This test framework now includes a dummy application for
|
215
|
+
testing future features.
|
216
|
+
|
217
|
+
2.1.0 (2019-02-14)
|
218
|
+
------------------
|
219
|
+
|
220
|
+
* Feature - Aws::Rails::Mailer - Adds the Amazon SES message ID as a header to
|
221
|
+
raw emails after sending, for tracking purposes. See
|
222
|
+
[related GitHub pull request #25](https://github.com/aws/aws-sdk-rails/pull/25).
|
223
|
+
|
224
|
+
2.0.1 (2017-10-03)
|
225
|
+
------------------
|
226
|
+
|
227
|
+
* Issue - Ensure `aws-sdk-rails.initialize` executes before
|
228
|
+
`load_config_initializers`
|
229
|
+
|
230
|
+
2.0.0 (2017-08-29)
|
231
|
+
------------------
|
232
|
+
|
233
|
+
* Upgrading - Support version 3 of the AWS SDK for Ruby. This is being released
|
234
|
+
as major version 2 of `aws-sdk-rails`, though the APIs remain the same. Do note,
|
235
|
+
however, that we've changed our SDK dependency to only depend on `aws-sdk-ses`.
|
236
|
+
This means that if you were depending on other service clients transitively via
|
237
|
+
`aws-sdk-rails`, you will need to add dependencies on the appropriate service
|
238
|
+
gems when upgrading. Logger integration will work for other service gems you
|
239
|
+
depend on, since it is wired up against `aws-sdk-core` which is included in
|
240
|
+
the `aws-sdk-ses` dependency.
|
241
|
+
|
242
|
+
1.0.1 (2016-02-01)
|
243
|
+
------------------
|
244
|
+
|
245
|
+
* Feature - Gemfile - Replaced `rails` gem dependency with `railties`
|
246
|
+
dependency. With this change, applications that bring their own dependencies
|
247
|
+
in place of, for example, ActiveRecord, can do so with reduced bloat.
|
248
|
+
|
249
|
+
See [related GitHub pull request
|
250
|
+
#4](https://github.com/aws/aws-sdk-rails/pull/4).
|
251
|
+
|
252
|
+
1.0.0 (2015-03-17)
|
253
|
+
------------------
|
254
|
+
|
255
|
+
* Initial Release: Support for Amazon Simple Email Service and Rails Logger
|
256
|
+
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
|
-
|
1
|
+
5.0.0
|
@@ -0,0 +1,141 @@
|
|
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 SQS adapter contain the JSON message in the request body.
|
35
|
+
job = ::ActiveSupport::JSON.decode(request.body.string)
|
36
|
+
job_name = job['job_class']
|
37
|
+
@logger.debug("Executing job: #{job_name}")
|
38
|
+
_execute_job(job, job_name)
|
39
|
+
[200, { 'Content-Type' => 'text/plain' }, ["Successfully ran job #{job_name}."]]
|
40
|
+
rescue NameError
|
41
|
+
internal_error_response
|
42
|
+
end
|
43
|
+
|
44
|
+
def _execute_job(job, job_name)
|
45
|
+
::ActiveJob::Base.execute(job)
|
46
|
+
rescue NameError => e
|
47
|
+
@logger.error("Job #{job_name} could not resolve to a class that inherits from Active Job.")
|
48
|
+
@logger.error("Error: #{e}")
|
49
|
+
raise e
|
50
|
+
end
|
51
|
+
|
52
|
+
def execute_periodic_task(request)
|
53
|
+
# The beanstalk worker SQS Daemon will add the 'X-Aws-Sqsd-Taskname' for periodic tasks set in cron.yaml.
|
54
|
+
job_name = request.headers['X-Aws-Sqsd-Taskname']
|
55
|
+
@logger.debug("Creating and executing periodic task: #{job_name}")
|
56
|
+
_execute_periodic_task(job_name)
|
57
|
+
[200, { 'Content-Type' => 'text/plain' }, ["Successfully ran periodic task #{job_name}."]]
|
58
|
+
rescue NameError
|
59
|
+
internal_error_response
|
60
|
+
end
|
61
|
+
|
62
|
+
def _execute_periodic_task(job_name)
|
63
|
+
job = job_name.constantize.new
|
64
|
+
job.perform_now
|
65
|
+
rescue NameError => e
|
66
|
+
@logger.error("Periodic task #{job_name} could not resolve to an Active Job class " \
|
67
|
+
'- check the cron name spelling and set the path as / in cron.yaml.')
|
68
|
+
@logger.error("Error: #{e}.")
|
69
|
+
raise e
|
70
|
+
end
|
71
|
+
|
72
|
+
def internal_error_response
|
73
|
+
message = 'Failed to execute job - see Rails log for more details.'
|
74
|
+
[500, { 'Content-Type' => 'text/plain' }, [message]]
|
75
|
+
end
|
76
|
+
|
77
|
+
def forbidden_response
|
78
|
+
message = 'Request with aws-sqsd user agent was made from untrusted address.'
|
79
|
+
[403, { 'Content-Type' => 'text/plain' }, [message]]
|
80
|
+
end
|
81
|
+
|
82
|
+
# The beanstalk worker SQS Daemon sets a specific User-Agent headers that begins with 'aws-sqsd'.
|
83
|
+
def from_sqs_daemon?(request)
|
84
|
+
current_user_agent = request.headers['User-Agent']
|
85
|
+
|
86
|
+
!current_user_agent.nil? && current_user_agent.start_with?('aws-sqsd')
|
87
|
+
end
|
88
|
+
|
89
|
+
# The beanstalk worker SQS Daemon will add the custom 'X-Aws-Sqsd-Taskname' header
|
90
|
+
# for periodic tasks set in cron.yaml.
|
91
|
+
def periodic_task?(request)
|
92
|
+
request.headers['X-Aws-Sqsd-Taskname'].present? && request.fullpath == '/'
|
93
|
+
end
|
94
|
+
|
95
|
+
def sent_from_docker_host?(request)
|
96
|
+
app_runs_in_docker_container? && ip_originates_from_docker_host?(request)
|
97
|
+
end
|
98
|
+
|
99
|
+
def app_runs_in_docker_container?
|
100
|
+
@app_runs_in_docker_container ||= in_docker_container_with_cgroup1? || in_docker_container_with_cgroup2?
|
101
|
+
end
|
102
|
+
|
103
|
+
def in_docker_container_with_cgroup1?
|
104
|
+
File.exist?('/proc/1/cgroup') && File.read('/proc/1/cgroup') =~ %r{/docker/}
|
105
|
+
end
|
106
|
+
|
107
|
+
def in_docker_container_with_cgroup2?
|
108
|
+
File.exist?('/proc/self/mountinfo') && File.read('/proc/self/mountinfo') =~ %r{/docker/containers/}
|
109
|
+
end
|
110
|
+
|
111
|
+
def ip_originates_from_docker_host?(request)
|
112
|
+
default_docker_ips.include?(request.remote_ip) ||
|
113
|
+
default_docker_ips.include?(request.remote_addr)
|
114
|
+
end
|
115
|
+
|
116
|
+
def default_docker_ips
|
117
|
+
@default_docker_ips ||= build_default_docker_ips
|
118
|
+
end
|
119
|
+
|
120
|
+
# rubocop:disable Metrics/AbcSize
|
121
|
+
def build_default_docker_ips
|
122
|
+
default_gw_ips = ['172.17.0.1']
|
123
|
+
|
124
|
+
if File.exist?('/proc/net/route')
|
125
|
+
File.open('/proc/net/route').each_line do |line|
|
126
|
+
fields = line.strip.split
|
127
|
+
next if fields.size != 11
|
128
|
+
# Destination == 0.0.0.0 and Flags & RTF_GATEWAY != 0
|
129
|
+
next unless fields[1] == '00000000' && fields[3].hex.anybits?(0x2)
|
130
|
+
|
131
|
+
default_gw_ips << IPAddr.new_ntoh([fields[2].hex].pack('L')).to_s
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
default_gw_ips
|
136
|
+
end
|
137
|
+
# rubocop:enable Metrics/AbcSize
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -1,22 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'aws-sdk-core'
|
4
3
|
require 'active_support/notifications'
|
5
4
|
|
5
|
+
require 'aws-sdk-core'
|
6
|
+
|
6
7
|
module Aws
|
7
8
|
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
9
|
# @api private
|
12
10
|
class Notifications < Seahorse::Client::Plugin
|
11
|
+
# This plugin needs to be first, which means it is called first in the stack,
|
12
|
+
# to start recording time, and returns last
|
13
13
|
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
14
|
handlers.add(Handler, step: :initialize, priority: 99)
|
18
15
|
end
|
19
16
|
|
17
|
+
# @api private
|
20
18
|
class Handler < Seahorse::Client::Handler
|
21
19
|
def call(context)
|
22
20
|
event_name = "#{context.operation_name}.#{context.config.api.metadata['serviceId']}.aws"
|
data/lib/aws/rails/railtie.rb
CHANGED
@@ -3,26 +3,24 @@
|
|
3
3
|
module Aws
|
4
4
|
# Use the Rails namespace.
|
5
5
|
module Rails
|
6
|
+
# See https://guides.rubyonrails.org/configuring.html#initializers
|
6
7
|
# @api private
|
7
8
|
class Railtie < ::Rails::Railtie
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
Aws::Rails.use_rails_encrypted_credentials
|
12
|
-
Aws::Rails.add_action_mailer_delivery_method
|
13
|
-
Aws::Rails.add_action_mailer_delivery_method(:sesv2)
|
14
|
-
Aws::Rails.log_to_rails_logger
|
9
|
+
# Set the logger for the AWS SDK to Rails.logger.
|
10
|
+
initializer 'aws-sdk-rails.log-to-rails-logger', after: :initialize_logger do
|
11
|
+
Aws.config[:logger] = ::Rails.logger
|
15
12
|
end
|
16
13
|
|
17
|
-
|
18
|
-
|
14
|
+
# Configures the AWS SDK with credentials from Rails encrypted credentials.
|
15
|
+
initializer 'aws-sdk-rails.use-rails-encrypted-credentials', after: :load_environment_config do
|
16
|
+
# limit the config keys we merge to credentials only
|
17
|
+
aws_credential_keys = %i[access_key_id secret_access_key session_token account_id]
|
18
|
+
creds = ::Rails.application.credentials[:aws].to_h.slice(*aws_credential_keys)
|
19
|
+
Aws.config.merge!(creds)
|
19
20
|
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
config.eager_load_namespaces << Aws
|
24
|
-
end
|
25
|
-
|
22
|
+
# Eager load the AWS SDK Clients.
|
23
|
+
initializer 'aws-sdk-rails.eager-load-sdk', before: :eager_load! do
|
26
24
|
Aws.define_singleton_method(:eager_load!) do
|
27
25
|
Aws.constants.each do |c|
|
28
26
|
m = Aws.const_get(c)
|
@@ -33,79 +31,42 @@ module Aws
|
|
33
31
|
end
|
34
32
|
end
|
35
33
|
end
|
36
|
-
end
|
37
34
|
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
config.before_eager_load do
|
36
|
+
config.eager_load_namespaces << Aws
|
37
|
+
end
|
41
38
|
end
|
42
|
-
end
|
43
39
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
# and use it to determine which mailer to use, keeping name free-form.
|
55
|
-
ActiveSupport.on_load(:action_mailer) do
|
56
|
-
if name == :sesv2
|
57
|
-
add_delivery_method(name, Aws::Rails::Sesv2Mailer, client_options)
|
58
|
-
else
|
59
|
-
add_delivery_method(name, Aws::Rails::SesMailer, client_options)
|
40
|
+
# Add ActiveSupport Notifications instrumentation to AWS SDK client operations.
|
41
|
+
# Each operation will produce an event with a name `<operation>.<service>.aws`.
|
42
|
+
# For example, S3's put_object has an event name of: put_object.S3.aws
|
43
|
+
initializer 'aws-sdk-rails.instrument-sdk-operations', after: :load_active_support do
|
44
|
+
Aws.constants.each do |c|
|
45
|
+
m = Aws.const_get(c)
|
46
|
+
if m.is_a?(Module) && m.const_defined?(:Client) &&
|
47
|
+
(client = m.const_get(:Client)) && client.superclass == Seahorse::Client::Base
|
48
|
+
m.const_get(:Client).add_plugin(Aws::Rails::Notifications)
|
49
|
+
end
|
60
50
|
end
|
61
51
|
end
|
62
|
-
end
|
63
|
-
|
64
|
-
# Configures the AWS SDK for Ruby's logger to use the Rails logger.
|
65
|
-
def self.log_to_rails_logger
|
66
|
-
Aws.config[:logger] = ::Rails.logger
|
67
|
-
nil
|
68
|
-
end
|
69
|
-
|
70
|
-
# Configures the AWS SDK with credentials from Rails encrypted credentials.
|
71
|
-
def self.use_rails_encrypted_credentials
|
72
|
-
# limit the config keys we merge to credentials only
|
73
|
-
aws_credential_keys = %i[access_key_id secret_access_key session_token]
|
74
|
-
|
75
|
-
Aws.config.merge!(
|
76
|
-
::Rails.application.credentials[:aws].to_h.slice(*aws_credential_keys)
|
77
|
-
)
|
78
|
-
end
|
79
52
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
# name of: put_object.S3.aws
|
84
|
-
def self.instrument_sdk_operations
|
85
|
-
Aws.constants.each do |c|
|
86
|
-
next if Aws.autoload?(c)
|
87
|
-
|
88
|
-
m = Aws.const_get(c)
|
89
|
-
if m.is_a?(Module) && m.const_defined?(:Client) &&
|
90
|
-
m.const_get(:Client).superclass == Seahorse::Client::Base
|
91
|
-
m.const_get(:Client).add_plugin(Aws::Rails::Notifications)
|
92
|
-
end
|
53
|
+
# Register a middleware that will handle requests from the Elastic Beanstalk worker SQS Daemon.
|
54
|
+
initializer 'aws-sdk-rails.add-sqsd-middleware', before: :build_middleware_stack do |app|
|
55
|
+
Aws::Rails.add_sqsd_middleware(app)
|
93
56
|
end
|
94
57
|
end
|
95
58
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
is_eb_worker_hosted = Aws::Util.str_2_bool(ENV['AWS_PROCESS_BEANSTALK_WORKER_REQUESTS'].to_s.downcase)
|
59
|
+
class << self
|
60
|
+
# @api private
|
61
|
+
def add_sqsd_middleware(app)
|
62
|
+
return unless ENV['AWS_PROCESS_BEANSTALK_WORKER_REQUESTS']
|
101
63
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
app.config.middleware.use(Aws::Rails::EbsSqsActiveJobMiddleware)
|
64
|
+
if app.config.force_ssl
|
65
|
+
# SQS Daemon sends requests over HTTP - allow and process them before enforcing SSL.
|
66
|
+
app.config.middleware.insert_before(::ActionDispatch::SSL, Aws::Rails::Middleware::ElasticBeanstalkSQSD)
|
67
|
+
else
|
68
|
+
app.config.middleware.use(Aws::Rails::Middleware::ElasticBeanstalkSQSD)
|
69
|
+
end
|
109
70
|
end
|
110
71
|
end
|
111
72
|
end
|
data/lib/aws-sdk-rails.rb
CHANGED
@@ -1,16 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'aws/rails/
|
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
|
-
|
11
|
-
require_relative 'action_dispatch/session/dynamodb_store'
|
12
|
-
|
13
|
-
require_relative 'generators/aws_record/base'
|
14
6
|
|
15
7
|
module Aws
|
16
8
|
module Rails
|