aws-sdk-rails 2.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0cb7c2fb3548b24522a39f7198022577a23b0c81
4
- data.tar.gz: 113bf55ef5e63b1a62d49cb311d0d1f30d13786e
2
+ SHA256:
3
+ metadata.gz: de037ab8aa7c27156e7074ab7aaf7999d32ebb468c26c938c35031618912af2c
4
+ data.tar.gz: 61bc484c0d053a05fb1ad108c636a67be5fb76a2c0d9152d126657b9b3099baf
5
5
  SHA512:
6
- metadata.gz: fc2f3865e396476b4b39115fb7b8439e410713afeb265e3f6b71b2cf2e5aa87fc41bbb532e03dc9c6e18c952ad3bfb82ae2d966e4f29b70b523309f0c76bab7c
7
- data.tar.gz: d553e23b153945f701b8c827abd04715d4c359f5b71d5b98a0b0a0608248233af5bbc8c7632c9938907fb126303d561b74e66801af2c9a1a60507adb023aa8be
6
+ metadata.gz: 89e5f84d363bb63b0d3c7520405acb03f46a283a6ea03d711547e5ecfc686e9435d232312d228c9cf61809f58fb6dc247a29793b56274cb94c5f9adee5910e72
7
+ data.tar.gz: aedc388ff0285d30d741b6ec6d2114af167b119f5f02b5da2be1a9858028e81bbbbfd152b3802c1482c9b50b9d5fdb57c96449c80a31d4c9d304e2aad306eb52
data/CHANGELOG.md ADDED
@@ -0,0 +1,261 @@
1
+ 5.1.0 (2024-12-05)
2
+ ------------------
3
+
4
+ * Feature - Support async job processing in Elastic Beanstalk middleware. (#167)
5
+
6
+ 5.0.0 (2024-11-21)
7
+ ------------------
8
+
9
+ * 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`.
10
+
11
+ * 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`.
12
+
13
+ * Issue - Remove require of `aws/rails/action_mailbox/rspec` in favor of `aws/action_mailbox/ses/rspec`.
14
+
15
+ * Issue - Remove symlinked namespaces from previous major versions.
16
+
17
+ * Feature - `ActiveSupport::Notifications` are enabled by default and removes `Aws::Rails.instrument_sdk_operations`.
18
+
19
+ * Feature - Moved railtie initializations to their appropriate spots.
20
+
21
+ * Issue - Do not execute `ActiveJob` from EB cron without the root path.
22
+
23
+ 4.2.0 (2024-11-20)
24
+ ------------------
25
+
26
+ * 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`.
27
+
28
+ * 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.
29
+
30
+ * Issue - `ActionDispatch::Session::DynamoDbStore` now inherits `ActionDispatch::Session::AbstractStore` by wrapping `Aws::SessionStore::DynamoDB::RackMiddleware`.
31
+
32
+ * Issue - `DynamoDbStore` is now configured with the `:dynamo_db_store` configuration instead of `:dynamodb_store`.
33
+
34
+ * 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.
35
+
36
+ * Feature - `AWS_DYNAMO_DB_SESSION_CONFIG_FILE` is now searched and with precedence over the default Rails configuration YAML file locations.
37
+
38
+ * Feature - Prepare modularization of `aws-record`.
39
+
40
+ * Issue - Do not skip autoload modules for `Aws::Rails.instrument_sdk_operations`.
41
+
42
+ * Feature - ActionMailer SES and SESV2 mailers now live in the `aws-actionmailer-ses` gem.
43
+
44
+ * 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.
45
+
46
+ * 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.
47
+
48
+ * Feature - ActionMailbox SES ingress now lives in the `aws-actionmailbox-ses` gem.
49
+
50
+ * Issue - The `Aws::Rails::ActionMailbox::RSpec` module has been moved to `Aws::ActionMailbox::SES::RSpec` and will be removed in aws-sdk-rails ~> 5.
51
+
52
+ * Feature - ActiveJob SQS now lives in the `aws-activejob-sqs` gem.
53
+
54
+ * 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.
55
+
56
+ * Issue - Correctly determine if SQSD is running in a Docker container.
57
+
58
+ * Feature - Aws::Record scaffold generators now lives in the `aws-record-rails` gem.
59
+
60
+ 4.1.0 (2024-09-27)
61
+ ------------------
62
+
63
+ * Feature - Add SDK eager loading to optimize load times. See: https://github.com/aws/aws-sdk-ruby/pull/3105.
64
+
65
+ 4.0.3 (2024-07-31)
66
+ ------------------
67
+
68
+ * Issue - Revert validating `:ses` or `:sesv2` as ActionMailer configuration. (#136)
69
+
70
+ 4.0.2 (2024-07-22)
71
+ ------------------
72
+
73
+ * Issue - Do not require `action_mailbox/engine` in `Aws::Rails::ActionMailbox::Engine` and instead check for its existence.
74
+
75
+ * Issue - Refactor the loading of the SQS ActiveJob adapter to be in `aws/rails/sqs_active_job`.
76
+
77
+ 4.0.1 (2024-07-18)
78
+ ------------------
79
+
80
+ * Issue - Require `action_mailbox/engine` from `Aws::Rails::ActionMailbox::Engine`.
81
+
82
+ 4.0.0 (2024-07-18)
83
+ ------------------
84
+
85
+ * Feature - Add support for Action Mailbox with SES (#127).
86
+
87
+ * Issue - Ensure `:ses` or `:sesv2` as ActionMailer configuration.
88
+
89
+ * Issue - Do not allow `:amazon`, `amazon_sqs`, or `amazon_sqs_async` for SQS active job configuration. Instead use `:sqs` and `:sqs_async`.
90
+
91
+ 3.13.0 (2024-06-06)
92
+ ------------------
93
+
94
+ * Feature - Use `Concurrent.available_processor_count` to set default thread pool max threads (#125).
95
+
96
+ * Issue - No longer rely on `caller_runs` for backpressure in sqs active job executor (#123).
97
+
98
+ 3.12.0 (2024-04-02)
99
+ ------------------
100
+ * Feature - Drop support for Ruby 2.3 and Ruby 2.4 (#117).
101
+ * Issue - Fix `EbsSqsActiveJobMiddleware` to detect Docker container with cgroup2. (#116).
102
+
103
+ 3.11.0 (2024-03-01)
104
+ ------------------
105
+
106
+ * Feature - Add `retry_standard_errors` (default `true`) in SQS ActiveJob and improve retry logic (#114).
107
+
108
+ 3.10.0 (2024-01-19)
109
+ ------------------
110
+
111
+ * Feature - Support `enqueue_all` in the SQS ActiveJob adapter.
112
+
113
+ * Issue - Improve `to_h` method's performance of `Aws::Rails::SqsActiveJob::Configuration`.
114
+
115
+ 3.9.1 (2023-12-19)
116
+ ------------------
117
+
118
+ * Issue - Fix negative `delay_seconds` being passed to parameter in the SQS adapter.
119
+
120
+ 3.9.0 (2023-09-28)
121
+ ------------------
122
+
123
+ * Feature - Add support for selectively choosing deduplication keys.
124
+
125
+ * Feature - Set required Ruby version to >= 2.3 (#104)
126
+
127
+ * Issue - Run `rubocop` on all files. (#104)
128
+
129
+ 3.8.0 (2023-06-02)
130
+ ------------------
131
+
132
+ * Feature - Improve User-Agent tracking and bump minimum SQS and SES versions.
133
+
134
+ 3.7.1 (2023-02-15)
135
+ ------------------
136
+
137
+ * Issue - Fix detecting docker host in `EbsSqsActiveJobMiddleware`.
138
+
139
+ 3.7.0 (2023-01-24)
140
+ ------------------
141
+
142
+ * Feature - Add SES v2 Mailer.
143
+
144
+ * Feature - Support smtp_envelope_from and _to in SES Mailer.
145
+
146
+ * Issue - Fix Ruby 3.1 usage by handling Psych 4 BadAlias error.
147
+
148
+ 3.6.4 (2022-10-13)
149
+ ------------------
150
+
151
+ * Issue - Use `request.ip` in `sent_from_docker_host?`.
152
+
153
+ 3.6.3 (2022-09-06)
154
+ ------------------
155
+
156
+ * Issue - Remove defaults for `visibility_timeout`: fallback to value configured on queue.
157
+ * Issue - Fix I18n localization bug in SQS adapters.
158
+
159
+ 3.6.2 (2022-06-16)
160
+ ------------------
161
+
162
+ * Issue - Fix DynamoDB session store to work with Rails 7.
163
+ * Issue - Allow for dynamic message group ids in FIFO Queues.
164
+
165
+ 3.6.1 (2021-06-08)
166
+ ------------------
167
+
168
+ * Issue - Fix credential loading to work with Rails 7.
169
+
170
+ 3.6.0 (2021-01-20)
171
+ ------------------
172
+
173
+ * Feature - Support for forwarding Elastic Beanstalk SQS Daemon requests to Active Job.
174
+
175
+ 3.5.0 (2021-01-06)
176
+ ------------------
177
+
178
+ * Feature - Add support for FIFO Queues to AWS SQS ActiveJob.
179
+
180
+ 3.4.0 (2020-12-07)
181
+ ------------------
182
+
183
+ * Feature - Add a non-blocking async ActiveJob adapter: `:amazon_sqs_async`.
184
+
185
+ * Feature - Add a lambda handler for processing active jobs from an SQS trigger.
186
+
187
+ * Issue - Fix bug in default for backpressure config.
188
+
189
+ 3.3.0 (2020-12-01)
190
+ ------------------
191
+
192
+ * Feature - Add `aws-record` as a dependency, a rails generator for `aws-record` models, and a rake task for table migrations.
193
+
194
+ * Feature - Add AWS SQS ActiveJob - A lightweight, SQS backend for ActiveJob.
195
+
196
+ 3.2.1 (2020-11-13)
197
+ ------------------
198
+
199
+ * Issue - Include missing files into the gemspec.
200
+
201
+ 3.2.0 (2020-11-13)
202
+ ------------------
203
+
204
+ * Feature - Add support for `ActiveSupport::Notifications` for instrumenting AWS SDK service calls.
205
+
206
+ * Feature - Add support for DynamoDB as an `ActiveDispatch::Session`.
207
+
208
+ 3.1.0 (2020-04-06)
209
+ ------------------
210
+ * Issue - Merge only credential related keys from Rails encrypted credentials into `Aws.config`.
211
+
212
+ 3.0.5 (2019-10-17)
213
+ ------------------
214
+
215
+ * Upgrading - Adds support for Rails Encrypted Credentials, requiring Rails 5.2+
216
+ and thus needed a new major version. Consequently drops support for Ruby < 2.3
217
+ and for Rails < 5.2. Delivery method configuration changed from `:aws_sdk` to
218
+ `:ses`, to allow for future delivery methods. Adds rubocop to the package and
219
+ fixed many violations. This test framework now includes a dummy application for
220
+ testing future features.
221
+
222
+ 2.1.0 (2019-02-14)
223
+ ------------------
224
+
225
+ * Feature - Aws::Rails::Mailer - Adds the Amazon SES message ID as a header to
226
+ raw emails after sending, for tracking purposes. See
227
+ [related GitHub pull request #25](https://github.com/aws/aws-sdk-rails/pull/25).
228
+
229
+ 2.0.1 (2017-10-03)
230
+ ------------------
231
+
232
+ * Issue - Ensure `aws-sdk-rails.initialize` executes before
233
+ `load_config_initializers`
234
+
235
+ 2.0.0 (2017-08-29)
236
+ ------------------
237
+
238
+ * Upgrading - Support version 3 of the AWS SDK for Ruby. This is being released
239
+ as major version 2 of `aws-sdk-rails`, though the APIs remain the same. Do note,
240
+ however, that we've changed our SDK dependency to only depend on `aws-sdk-ses`.
241
+ This means that if you were depending on other service clients transitively via
242
+ `aws-sdk-rails`, you will need to add dependencies on the appropriate service
243
+ gems when upgrading. Logger integration will work for other service gems you
244
+ depend on, since it is wired up against `aws-sdk-core` which is included in
245
+ the `aws-sdk-ses` dependency.
246
+
247
+ 1.0.1 (2016-02-01)
248
+ ------------------
249
+
250
+ * Feature - Gemfile - Replaced `rails` gem dependency with `railties`
251
+ dependency. With this change, applications that bring their own dependencies
252
+ in place of, for example, ActiveRecord, can do so with reduced bloat.
253
+
254
+ See [related GitHub pull request
255
+ #4](https://github.com/aws/aws-sdk-rails/pull/4).
256
+
257
+ 1.0.0 (2015-03-17)
258
+ ------------------
259
+
260
+ * Initial Release: Support for Amazon Simple Email Service and Rails Logger
261
+ 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 ADDED
@@ -0,0 +1 @@
1
+ 5.1.0
@@ -0,0 +1,205 @@
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
+
12
+ return unless ENV['AWS_PROCESS_BEANSTALK_WORKER_JOBS_ASYNC']
13
+
14
+ @executor = init_executor
15
+ end
16
+
17
+ def call(env)
18
+ request = ::ActionDispatch::Request.new(env)
19
+
20
+ # Pass through unless user agent is the SQS Daemon
21
+ return @app.call(env) unless from_sqs_daemon?(request)
22
+
23
+ @logger.debug('aws-sdk-rails middleware detected call from Elastic Beanstalk SQS Daemon.')
24
+
25
+ # Only accept requests from this user agent if it is from localhost or a docker host in case of forgery.
26
+ unless request.local? || sent_from_docker_host?(request)
27
+ @logger.warn('SQSD request detected from untrusted address; returning 403 forbidden.')
28
+ return forbidden_response
29
+ end
30
+
31
+ # Execute job or periodic task based on HTTP request context
32
+ execute(request)
33
+ end
34
+
35
+ def shutdown(timeout = nil)
36
+ return unless @executor
37
+
38
+ @logger.info("Shutting down SQS EBS background job executor. Timeout: #{timeout}")
39
+ @executor.shutdown
40
+ clean_shutdown = @executor.wait_for_termination(timeout)
41
+ @logger.info("SQS EBS background executor shutdown complete. Clean: #{clean_shutdown}")
42
+ end
43
+
44
+ private
45
+
46
+ def init_executor
47
+ threads = Integer(ENV.fetch('AWS_PROCESS_BEANSTALK_WORKER_THREADS',
48
+ Concurrent.available_processor_count || Concurrent.processor_count))
49
+ options = {
50
+ max_threads: threads,
51
+ max_queue: 1,
52
+ auto_terminate: false, # register our own at_exit to gracefully shutdown
53
+ fallback_policy: :abort # Concurrent::RejectedExecutionError must be handled
54
+ }
55
+ at_exit { shutdown }
56
+
57
+ Concurrent::ThreadPoolExecutor.new(options)
58
+ end
59
+
60
+ def execute(request)
61
+ if periodic_task?(request)
62
+ execute_periodic_task(request)
63
+ else
64
+ execute_job(request)
65
+ end
66
+ end
67
+
68
+ def execute_job(request)
69
+ if @executor
70
+ _execute_job_background(request)
71
+ else
72
+ _execute_job_now(request)
73
+ end
74
+ end
75
+
76
+ # Execute a job in the current thread
77
+ def _execute_job_now(request)
78
+ # Jobs queued from the SQS adapter contain the JSON message in the request body.
79
+ job = ::ActiveSupport::JSON.decode(request.body.string)
80
+ job_name = job['job_class']
81
+ @logger.debug("Executing job: #{job_name}")
82
+ ::ActiveJob::Base.execute(job)
83
+ [200, { 'Content-Type' => 'text/plain' }, ["Successfully ran job #{job_name}."]]
84
+ rescue NameError => e
85
+ @logger.error("Job #{job_name} could not resolve to a class that inherits from Active Job.")
86
+ @logger.error("Error: #{e}")
87
+ internal_error_response
88
+ end
89
+
90
+ # Execute a job using the thread pool executor
91
+ def _execute_job_background(request)
92
+ job_data = ::ActiveSupport::JSON.decode(request.body.string)
93
+ @logger.debug("Queuing background job: #{job_data['job_class']}")
94
+ @executor.post(job_data) do |job|
95
+ ::ActiveJob::Base.execute(job)
96
+ end
97
+ [200, { 'Content-Type' => 'text/plain' }, ["Successfully queued job #{job_data['job_class']}"]]
98
+ rescue Concurrent::RejectedExecutionError
99
+ msg = 'No capacity to execute job.'
100
+ @logger.info(msg)
101
+ [429, { 'Content-Type' => 'text/plain' }, [msg]]
102
+ end
103
+
104
+ def execute_periodic_task(request)
105
+ # The beanstalk worker SQS Daemon will add the 'X-Aws-Sqsd-Taskname' for periodic tasks set in cron.yaml.
106
+ job_name = request.headers['X-Aws-Sqsd-Taskname']
107
+ job = job_name.constantize.new
108
+ if @executor
109
+ _execute_periodic_task_background(job)
110
+ else
111
+ _execute_periodic_task_now(job)
112
+ end
113
+ rescue NameError => e
114
+ @logger.error("Periodic task #{job_name} could not resolve to an Active Job class " \
115
+ '- check the cron name spelling and set the path as / in cron.yaml.')
116
+ @logger.error("Error: #{e}.")
117
+ internal_error_response
118
+ end
119
+
120
+ def _execute_periodic_task_now(job)
121
+ @logger.debug("Executing periodic task: #{job.class}")
122
+ job.perform_now
123
+ [200, { 'Content-Type' => 'text/plain' }, ["Successfully ran periodic task #{job.class}."]]
124
+ end
125
+
126
+ def _execute_periodic_task_background(job)
127
+ @logger.debug("Queuing bakground periodic task: #{job.class}")
128
+ @executor.post(job, &:perform_now)
129
+ [200, { 'Content-Type' => 'text/plain' }, ["Successfully queued periodic task #{job.class}"]]
130
+ rescue Concurrent::RejectedExecutionError
131
+ msg = 'No capacity to execute periodic task.'
132
+ @logger.info(msg)
133
+ [429, { 'Content-Type' => 'text/plain' }, [msg]]
134
+ end
135
+
136
+ def internal_error_response
137
+ message = 'Failed to execute job - see Rails log for more details.'
138
+ [500, { 'Content-Type' => 'text/plain' }, [message]]
139
+ end
140
+
141
+ def forbidden_response
142
+ message = 'Request with aws-sqsd user agent was made from untrusted address.'
143
+ [403, { 'Content-Type' => 'text/plain' }, [message]]
144
+ end
145
+
146
+ # The beanstalk worker SQS Daemon sets a specific User-Agent headers that begins with 'aws-sqsd'.
147
+ def from_sqs_daemon?(request)
148
+ current_user_agent = request.headers['User-Agent']
149
+
150
+ !current_user_agent.nil? && current_user_agent.start_with?('aws-sqsd')
151
+ end
152
+
153
+ # The beanstalk worker SQS Daemon will add the custom 'X-Aws-Sqsd-Taskname' header
154
+ # for periodic tasks set in cron.yaml.
155
+ def periodic_task?(request)
156
+ request.headers['X-Aws-Sqsd-Taskname'].present? && request.fullpath == '/'
157
+ end
158
+
159
+ def sent_from_docker_host?(request)
160
+ app_runs_in_docker_container? && ip_originates_from_docker_host?(request)
161
+ end
162
+
163
+ def app_runs_in_docker_container?
164
+ @app_runs_in_docker_container ||= in_docker_container_with_cgroup1? || in_docker_container_with_cgroup2?
165
+ end
166
+
167
+ def in_docker_container_with_cgroup1?
168
+ File.exist?('/proc/1/cgroup') && File.read('/proc/1/cgroup') =~ %r{/docker/}
169
+ end
170
+
171
+ def in_docker_container_with_cgroup2?
172
+ File.exist?('/proc/self/mountinfo') && File.read('/proc/self/mountinfo') =~ %r{/docker/containers/}
173
+ end
174
+
175
+ def ip_originates_from_docker_host?(request)
176
+ default_docker_ips.include?(request.remote_ip) ||
177
+ default_docker_ips.include?(request.remote_addr)
178
+ end
179
+
180
+ def default_docker_ips
181
+ @default_docker_ips ||= build_default_docker_ips
182
+ end
183
+
184
+ # rubocop:disable Metrics/AbcSize
185
+ def build_default_docker_ips
186
+ default_gw_ips = ['172.17.0.1']
187
+
188
+ if File.exist?('/proc/net/route')
189
+ File.open('/proc/net/route').each_line do |line|
190
+ fields = line.strip.split
191
+ next if fields.size != 11
192
+ # Destination == 0.0.0.0 and Flags & RTF_GATEWAY != 0
193
+ next unless fields[1] == '00000000' && fields[3].hex.anybits?(0x2)
194
+
195
+ default_gw_ips << IPAddr.new_ntoh([fields[2].hex].pack('L')).to_s
196
+ end
197
+ end
198
+
199
+ default_gw_ips
200
+ end
201
+ # rubocop:enable Metrics/AbcSize
202
+ end
203
+ end
204
+ end
205
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/notifications'
4
+
5
+ require 'aws-sdk-core'
6
+
7
+ module Aws
8
+ module Rails
9
+ # @api private
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
+ def add_handlers(handlers, _config)
14
+ handlers.add(Handler, step: :initialize, priority: 99)
15
+ end
16
+
17
+ # @api private
18
+ class Handler < Seahorse::Client::Handler
19
+ def call(context)
20
+ event_name = "#{context.operation_name}.#{context.config.api.metadata['serviceId']}.aws"
21
+ ActiveSupport::Notifications.instrument(event_name, context: context) do
22
+ @handler.call(context)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ # Use the Rails namespace.
5
+ module Rails
6
+ # See https://guides.rubyonrails.org/configuring.html#initializers
7
+ # @api private
8
+ class Railtie < ::Rails::Railtie
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
12
+ end
13
+
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)
20
+ end
21
+
22
+ # Eager load the AWS SDK Clients.
23
+ initializer 'aws-sdk-rails.eager-load-sdk', before: :eager_load! do
24
+ Aws.define_singleton_method(:eager_load!) do
25
+ Aws.constants.each do |c|
26
+ m = Aws.const_get(c)
27
+ next unless m.is_a?(Module)
28
+
29
+ m.constants.each do |constant|
30
+ m.const_get(constant)
31
+ end
32
+ end
33
+ end
34
+
35
+ config.before_eager_load do
36
+ config.eager_load_namespaces << Aws
37
+ end
38
+ end
39
+
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
50
+ end
51
+ end
52
+
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)
56
+ end
57
+ end
58
+
59
+ class << self
60
+ # @api private
61
+ def add_sqsd_middleware(app)
62
+ return unless ENV['AWS_PROCESS_BEANSTALK_WORKER_REQUESTS']
63
+
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
70
+ end
71
+ end
72
+ end
73
+ end
data/lib/aws-sdk-rails.rb CHANGED
@@ -1,37 +1,11 @@
1
- require_relative 'aws/rails/mailer'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'aws/rails/middleware/elastic_beanstalk_sqsd'
4
+ require_relative 'aws/rails/railtie'
5
+ require_relative 'aws/rails/notifications'
2
6
 
3
7
  module Aws
4
8
  module Rails
5
-
6
- # @api private
7
- class Railtie < ::Rails::Railtie
8
- initializer "aws-sdk-rails.initialize" do |app|
9
- # Initialization Actions
10
- Aws::Rails.add_action_mailer_delivery_method
11
- Aws::Rails.log_to_rails_logger
12
- end
13
- end
14
-
15
- # This is called automatically from the SDK's Railtie, but if you want to
16
- # manually specify options for building the Aws::SES::Client object, you
17
- # can manually call this method.
18
- #
19
- # @param [Symbol] name The name of the ActionMailer delivery method to
20
- # register.
21
- # @param [Hash] options The options you wish to pass on to the
22
- # Aws::SES::Client initialization method.
23
- def self.add_action_mailer_delivery_method(name = :aws_sdk, options = {})
24
- ActiveSupport.on_load(:action_mailer) do
25
- self.add_delivery_method(name, Aws::Rails::Mailer, options)
26
- end
27
- end
28
-
29
- # Configures the AWS SDK for Ruby's logger to use the Rails logger.
30
- def self.log_to_rails_logger
31
- Aws.config[:logger] = ::Rails.logger
32
- nil
33
- end
34
-
9
+ VERSION = File.read(File.expand_path('../VERSION', __dir__)).strip
35
10
  end
36
11
  end
37
-
metadata CHANGED
@@ -1,57 +1,62 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-sdk-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 5.1.0
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: 2017-08-29 00:00:00.000000000 Z
11
+ date: 2024-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: aws-sdk-ses
14
+ name: aws-sdk-core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1'
19
+ version: '3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1'
26
+ version: '3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: railties
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '3'
33
+ version: 7.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '3'
41
- description: Provides helpers to integrate the AWS SDK for Ruby with Ruby on Rails.
40
+ version: 7.1.0
41
+ description: Integrates the AWS SDK for Ruby with Ruby on Rails
42
42
  email:
43
- - alexwood@amazon.com
43
+ - aws-dr-rubygems@amazon.com
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - CHANGELOG.md
49
+ - LICENSE.txt
50
+ - VERSION
48
51
  - lib/aws-sdk-rails.rb
49
- - lib/aws/rails/mailer.rb
52
+ - lib/aws/rails/middleware/elastic_beanstalk_sqsd.rb
53
+ - lib/aws/rails/notifications.rb
54
+ - lib/aws/rails/railtie.rb
50
55
  homepage: https://github.com/aws/aws-sdk-rails
51
56
  licenses:
52
- - Apache 2.0
57
+ - Apache-2.0
53
58
  metadata: {}
54
- post_install_message:
59
+ post_install_message:
55
60
  rdoc_options: []
56
61
  require_paths:
57
62
  - lib
@@ -59,16 +64,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
64
  requirements:
60
65
  - - ">="
61
66
  - !ruby/object:Gem::Version
62
- version: '0'
67
+ version: '2.7'
63
68
  required_rubygems_version: !ruby/object:Gem::Requirement
64
69
  requirements:
65
70
  - - ">="
66
71
  - !ruby/object:Gem::Version
67
72
  version: '0'
68
73
  requirements: []
69
- rubyforge_project:
70
- rubygems_version: 2.5.1
71
- signing_key:
74
+ rubygems_version: 3.5.9
75
+ signing_key:
72
76
  specification_version: 4
73
- summary: AWS SDK for Ruby Rails Plugin
77
+ summary: AWS SDK for Ruby on Rails Railtie
74
78
  test_files: []
@@ -1,47 +0,0 @@
1
- require 'aws-sdk-ses'
2
-
3
- module Aws
4
- module Rails
5
-
6
- # Provides a delivery method for ActionMailer that uses Amazon Simple Email
7
- # Service.
8
- #
9
- # Once you have an SES delivery method you can configure Rails to
10
- # use this for ActionMailer in your environment configuration
11
- # (e.g. RAILS_ROOT/config/environments/production.rb)
12
- #
13
- # config.action_mailer.delivery_method = :aws_sdk
14
- #
15
- # Uses the AWS SDK for Ruby V2's credential provider chain when creating an
16
- # SES client instance.
17
- class Mailer
18
-
19
- # @param [Hash] options Passes along initialization options to
20
- # [Aws::SES::Client.new](http://docs.aws.amazon.com/sdkforruby/api/Aws/SES/Client.html#initialize-instance_method).
21
- def initialize(options = {})
22
- @client = SES::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
- 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)
37
-
38
- end
39
-
40
- # ActionMailer expects this method to be present and to return a hash.
41
- def settings
42
- {}
43
- end
44
-
45
- end
46
- end
47
- end