aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage
diff options
context:
space:
mode:
authorBrian Knight <brianknight10@gmail.com>2018-03-19 11:25:40 -0400
committerAndrew White <pixeltrix@users.noreply.github.com>2018-03-19 15:25:40 +0000
commitc1600009b2bbb3b67db20ddb14fef34d4cfa82bc (patch)
treede8feeed47f1130158deba421175f266feb08c1c /activestorage
parentdb8cce202b8e81154773e5195a3ae35e873427e6 (diff)
downloadrails-c1600009b2bbb3b67db20ddb14fef34d4cfa82bc.tar.gz
rails-c1600009b2bbb3b67db20ddb14fef34d4cfa82bc.tar.bz2
rails-c1600009b2bbb3b67db20ddb14fef34d4cfa82bc.zip
Allow full use of the AWS S3 SDK authentication options (#32270)
If an explicit AWS key pair and/or region is not provided in config/storage.yml, attempt to use environment variables, shared credentials, or IAM role credentials. Order of precedence is determined by the AWS SDK[1]. [1]: https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html
Diffstat (limited to 'activestorage')
-rw-r--r--activestorage/CHANGELOG.md8
-rw-r--r--activestorage/lib/active_storage/service/s3_service.rb4
-rw-r--r--activestorage/test/service/s3_service_test.rb2
3 files changed, 11 insertions, 3 deletions
diff --git a/activestorage/CHANGELOG.md b/activestorage/CHANGELOG.md
index d794afb0e6..5541f7f331 100644
--- a/activestorage/CHANGELOG.md
+++ b/activestorage/CHANGELOG.md
@@ -1,3 +1,11 @@
+* Allow full use of the AWS S3 SDK options for authentication. If an
+ explicit AWS key pair and/or region is not provided in `storage.yml`,
+ attempt to use environment variables, shared credentials, or IAM
+ (instance or task) role credentials. Order of precedence is determined
+ by the [AWS SDK](https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html).
+
+ *Brian Knight*
+
* Rails 6 requires Ruby 2.4.1 or newer.
*Jeremy Daer*
diff --git a/activestorage/lib/active_storage/service/s3_service.rb b/activestorage/lib/active_storage/service/s3_service.rb
index 8ab7a44131..5e489f4be1 100644
--- a/activestorage/lib/active_storage/service/s3_service.rb
+++ b/activestorage/lib/active_storage/service/s3_service.rb
@@ -9,8 +9,8 @@ module ActiveStorage
class Service::S3Service < Service
attr_reader :client, :bucket, :upload_options
- def initialize(access_key_id:, secret_access_key:, region:, bucket:, upload: {}, **options)
- @client = Aws::S3::Resource.new(access_key_id: access_key_id, secret_access_key: secret_access_key, region: region, **options)
+ def initialize(bucket:, upload: {}, **options)
+ @client = Aws::S3::Resource.new(**options)
@bucket = @client.bucket(bucket)
@upload_options = upload
diff --git a/activestorage/test/service/s3_service_test.rb b/activestorage/test/service/s3_service_test.rb
index d6996209d2..7833e51122 100644
--- a/activestorage/test/service/s3_service_test.rb
+++ b/activestorage/test/service/s3_service_test.rb
@@ -3,7 +3,7 @@
require "service/shared_service_tests"
require "net/http"
-if SERVICE_CONFIGURATIONS[:s3] && SERVICE_CONFIGURATIONS[:s3][:access_key_id].present?
+if SERVICE_CONFIGURATIONS[:s3]
class ActiveStorage::Service::S3ServiceTest < ActiveSupport::TestCase
SERVICE = ActiveStorage::Service.configure(:s3, SERVICE_CONFIGURATIONS)