Skip to content

Commit f5fff78

Browse files
committed
add option for additional settings
1 parent ba0251d commit f5fff78

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

docs/index.asciidoc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
7777
|=======================================================================
7878
|Setting |Input type|Required
7979
| <<plugins-{type}s-{plugin}-access_key_id>> |<<string,string>>|No
80+
| <<plugins-{type}s-{plugin}-additional_settings>> |<<hash,hash>>|No
8081
| <<plugins-{type}s-{plugin}-aws_credentials_file>> |<<string,string>>|No
8182
| <<plugins-{type}s-{plugin}-bucket>> |<<string,string>>|Yes
8283
| <<plugins-{type}s-{plugin}-canned_acl>> |<<string,string>>, one of `["private", "public-read", "public-read-write", "authenticated-read", "aws-exec-read", "bucket-owner-read", "bucket-owner-full-control", "log-delivery-write"]`|No
@@ -120,6 +121,29 @@ This plugin uses the AWS SDK and supports several ways to get credentials, which
120121
4. Environment variables `AMAZON_ACCESS_KEY_ID` and `AMAZON_SECRET_ACCESS_KEY`
121122
5. IAM Instance Profile (available when running inside EC2)
122123

124+
[id="plugins-{type}s-{plugin}-additional_settings"]
125+
===== `additional_settings`
126+
127+
* Value type is <<hash,hash>>
128+
* Default value is `{}`
129+
130+
Key-value pairs of settings and corresponding values used to parametrize
131+
the connection to S3. See full list in https://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Client.html[the AWS SDK documentation]. Example:
132+
133+
[source,ruby]
134+
output {
135+
s3 {
136+
access_key_id => "1234",
137+
secret_access_key => "secret",
138+
region => "eu-west-1",
139+
bucket => "logstash-test",
140+
additional_settings => {
141+
"force_path_style => true,
142+
"follow_redirects" => false
143+
}
144+
}
145+
}
146+
123147
[id="plugins-{type}s-{plugin}-aws_credentials_file"]
124148
===== `aws_credentials_file`
125149

lib/logstash/outputs/s3.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class LogStash::Outputs::S3 < LogStash::Outputs::Base
106106
# S3 bucket
107107
config :bucket, :validate => :string, :required => true
108108

109+
config :additional_settings, :validate => :hash, :default => {}
110+
109111
# Set the size of file in bytes, this means that files on bucket when have dimension > file_size, they are stored in two or more file.
110112
# If you have tags then it will generate a specific size file for every tags
111113
##NOTE: define size of file is the better thing, because generate a local temporary file on disk and then put it in bucket.
@@ -267,9 +269,9 @@ def close
267269
end
268270

269271
def full_options
270-
options = Hash.new
272+
options = aws_options_hash || {}
271273
options[:signature_version] = @signature_version if @signature_version
272-
options.merge(aws_options_hash)
274+
@additional_settings.merge(options)
273275
end
274276

275277
def normalize_key(prefix_key)

spec/outputs/s3_spec.rb

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
subject { described_class.new(options) }
2525

2626
before do
27-
allow(subject).to receive(:bucket_resource).and_return(mock_bucket)
28-
allow_any_instance_of(LogStash::Outputs::S3::WriteBucketPermissionValidator).to receive(:valid?).with(mock_bucket, subject.upload_options).and_return(true)
27+
allow_any_instance_of(LogStash::Outputs::S3::WriteBucketPermissionValidator).to receive(:valid?).and_return(true)
2928
end
3029

3130
context "#register configuration validation" do
@@ -143,6 +142,29 @@
143142
expect { s3.register }.to raise_error(LogStash::ConfigurationError)
144143
end
145144

145+
describe "additional_settings" do
146+
context "when enabling force_path_style" do
147+
let(:additional_settings) do
148+
{ "additional_settings" => { "force_path_style" => true } }
149+
end
150+
151+
it "validates the prefix" do
152+
expect(Aws::S3::Bucket).to receive(:new).twice.with(anything, hash_including("force_path_style" => true)).and_call_original
153+
described_class.new(options.merge(additional_settings)).register
154+
end
155+
end
156+
context "when using a non existing setting" do
157+
let(:additional_settings) do
158+
{ "additional_settings" => { "doesnt_exist" => true } }
159+
end
160+
161+
it "raises an error" do
162+
plugin = described_class.new(options.merge(additional_settings))
163+
expect { plugin.register }.to raise_error(ArgumentError)
164+
end
165+
end
166+
end
167+
146168
it "allow to not validate credentials" do
147169
s3 = described_class.new(options.merge({"validate_credentials_on_root_bucket" => false}))
148170
expect_any_instance_of(LogStash::Outputs::S3::WriteBucketPermissionValidator).not_to receive(:valid?).with(any_args)
@@ -152,6 +174,7 @@
152174

153175
context "receiving events" do
154176
before do
177+
allow(subject).to receive(:bucket_resource).and_return(mock_bucket)
155178
subject.register
156179
end
157180

0 commit comments

Comments
 (0)