diff --git a/docs/index.asciidoc b/docs/index.asciidoc index 506ef7a..d62c58b 100644 --- a/docs/index.asciidoc +++ b/docs/index.asciidoc @@ -34,6 +34,7 @@ This plugin supports the following configuration options plus the <> |<>|No +| <> |<>|No | <> |<>|No | <> |<>|No | <> |<>|No @@ -139,6 +140,28 @@ Whether to delete processed files from the original bucket. Ruby style regexp of keys to exclude from the bucket +[id="plugins-{type}s-{plugin}-additional_settings"] +===== `additional_settings` + + * Value type is <> + * Default value is `{}` + +Key-value pairs of settings and corresponding values used to parametrize +the connection to s3. See full list in https://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Client.html[the AWS SDK documentation]. Example: + +[source,ruby] + input { + s3 { + "access_key_id" => "1234", + "secret_access_key" => "secret", + "bucket" => "logstash-test", + "additional_settings" => { + "force_path_style => true, + "follow_redirects" => false + } + } + } + [id="plugins-{type}s-{plugin}-interval"] ===== `interval` diff --git a/lib/logstash/inputs/s3.rb b/lib/logstash/inputs/s3.rb index c3f46e4..3b7ceba 100644 --- a/lib/logstash/inputs/s3.rb +++ b/lib/logstash/inputs/s3.rb @@ -35,6 +35,8 @@ class LogStash::Inputs::S3 < LogStash::Inputs::Base # If specified, the prefix of filenames in the bucket must match (not a regexp) config :prefix, :validate => :string, :default => nil + config :additional_settings, :validate => :hash, :default => {} + # The path to use for writing state. The state stored by this plugin is # a memory of files already processed by this plugin. # @@ -386,7 +388,8 @@ def delete_file_from_bucket(object) private def get_s3object - s3 = Aws::S3::Resource.new(aws_options_hash) + options = @additional_settings.merge(aws_options_hash || {}) + s3 = Aws::S3::Resource.new(options) end private diff --git a/spec/inputs/s3_spec.rb b/spec/inputs/s3_spec.rb index f92760f..4b00ec1 100644 --- a/spec/inputs/s3_spec.rb +++ b/spec/inputs/s3_spec.rb @@ -76,6 +76,39 @@ subject.send(:get_s3object) end end + + describe "additional_settings" do + context 'when force_path_style is set' do + let(:settings) { + { + "additional_settings" => { "force_path_style" => true }, + "bucket" => "logstash-test", + } + } + + it 'should instantiate AWS::S3 clients with force_path_style set' do + expect(Aws::S3::Resource).to receive(:new).with({ + :region => subject.region, + "force_path_style" => true + }).and_call_original + + subject.send(:get_s3object) + end + end + + context 'when an unknown setting is given' do + let(:settings) { + { + "additional_settings" => { "this_setting_doesnt_exist" => true }, + "bucket" => "logstash-test", + } + } + + it 'should raise an error' do + expect { subject.send(:get_s3object) }.to raise_error(ArgumentError) + end + end + end end describe "#list_new_files" do