Skip to content

Commit e18bb48

Browse files
authored
add support for additional_settings option (#141)
1 parent b9ed6e8 commit e18bb48

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

docs/index.asciidoc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
3434
|=======================================================================
3535
|Setting |Input type|Required
3636
| <<plugins-{type}s-{plugin}-access_key_id>> |<<string,string>>|No
37+
| <<plugins-{type}s-{plugin}-additional_settings>> |<<hash,hash>>|No
3738
| <<plugins-{type}s-{plugin}-aws_credentials_file>> |<<string,string>>|No
3839
| <<plugins-{type}s-{plugin}-backup_add_prefix>> |<<string,string>>|No
3940
| <<plugins-{type}s-{plugin}-backup_to_bucket>> |<<string,string>>|No
@@ -139,6 +140,28 @@ Whether to delete processed files from the original bucket.
139140

140141
Ruby style regexp of keys to exclude from the bucket
141142

143+
[id="plugins-{type}s-{plugin}-additional_settings"]
144+
===== `additional_settings`
145+
146+
* Value type is <<hash,hash>>
147+
* Default value is `{}`
148+
149+
Key-value pairs of settings and corresponding values used to parametrize
150+
the connection to s3. See full list in https://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Client.html[the AWS SDK documentation]. Example:
151+
152+
[source,ruby]
153+
input {
154+
s3 {
155+
"access_key_id" => "1234",
156+
"secret_access_key" => "secret",
157+
"bucket" => "logstash-test",
158+
"additional_settings" => {
159+
"force_path_style => true,
160+
"follow_redirects" => false
161+
}
162+
}
163+
}
164+
142165
[id="plugins-{type}s-{plugin}-interval"]
143166
===== `interval`
144167

lib/logstash/inputs/s3.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class LogStash::Inputs::S3 < LogStash::Inputs::Base
3535
# If specified, the prefix of filenames in the bucket must match (not a regexp)
3636
config :prefix, :validate => :string, :default => nil
3737

38+
config :additional_settings, :validate => :hash, :default => {}
39+
3840
# The path to use for writing state. The state stored by this plugin is
3941
# a memory of files already processed by this plugin.
4042
#
@@ -386,7 +388,8 @@ def delete_file_from_bucket(object)
386388

387389
private
388390
def get_s3object
389-
s3 = Aws::S3::Resource.new(aws_options_hash)
391+
options = @additional_settings.merge(aws_options_hash || {})
392+
s3 = Aws::S3::Resource.new(options)
390393
end
391394

392395
private

spec/inputs/s3_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,39 @@
7676
subject.send(:get_s3object)
7777
end
7878
end
79+
80+
describe "additional_settings" do
81+
context 'when force_path_style is set' do
82+
let(:settings) {
83+
{
84+
"additional_settings" => { "force_path_style" => true },
85+
"bucket" => "logstash-test",
86+
}
87+
}
88+
89+
it 'should instantiate AWS::S3 clients with force_path_style set' do
90+
expect(Aws::S3::Resource).to receive(:new).with({
91+
:region => subject.region,
92+
"force_path_style" => true
93+
}).and_call_original
94+
95+
subject.send(:get_s3object)
96+
end
97+
end
98+
99+
context 'when an unknown setting is given' do
100+
let(:settings) {
101+
{
102+
"additional_settings" => { "this_setting_doesnt_exist" => true },
103+
"bucket" => "logstash-test",
104+
}
105+
}
106+
107+
it 'should raise an error' do
108+
expect { subject.send(:get_s3object) }.to raise_error(ArgumentError)
109+
end
110+
end
111+
end
79112
end
80113

81114
describe "#list_new_files" do

0 commit comments

Comments
 (0)