Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
|=======================================================================
|Setting |Input type|Required
| <<plugins-{type}s-{plugin}-access_key_id>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-additional_settings>> |<<hash,hash>>|No
| <<plugins-{type}s-{plugin}-aws_credentials_file>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-bucket>> |<<string,string>>|Yes
| <<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
Expand Down Expand Up @@ -120,6 +121,29 @@ This plugin uses the AWS SDK and supports several ways to get credentials, which
4. Environment variables `AMAZON_ACCESS_KEY_ID` and `AMAZON_SECRET_ACCESS_KEY`
5. IAM Instance Profile (available when running inside EC2)

[id="plugins-{type}s-{plugin}-additional_settings"]
===== `additional_settings`

* Value type is <<hash,hash>>
* 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]
output {
s3 {
access_key_id => "1234",
secret_access_key => "secret",
region => "eu-west-1",
bucket => "logstash-test",
additional_settings => {
"force_path_style => true,
"follow_redirects" => false
}
}
}

[id="plugins-{type}s-{plugin}-aws_credentials_file"]
===== `aws_credentials_file`

Expand Down
6 changes: 4 additions & 2 deletions lib/logstash/outputs/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class LogStash::Outputs::S3 < LogStash::Outputs::Base
# S3 bucket
config :bucket, :validate => :string, :required => true

config :additional_settings, :validate => :hash, :default => {}

# 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.
# If you have tags then it will generate a specific size file for every tags
##NOTE: define size of file is the better thing, because generate a local temporary file on disk and then put it in bucket.
Expand Down Expand Up @@ -267,9 +269,9 @@ def close
end

def full_options
options = Hash.new
options = aws_options_hash || {}
options[:signature_version] = @signature_version if @signature_version
options.merge(aws_options_hash)
@additional_settings.merge(options)
end

def normalize_key(prefix_key)
Expand Down
27 changes: 25 additions & 2 deletions spec/outputs/s3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
subject { described_class.new(options) }

before do
allow(subject).to receive(:bucket_resource).and_return(mock_bucket)
allow_any_instance_of(LogStash::Outputs::S3::WriteBucketPermissionValidator).to receive(:valid?).with(mock_bucket, subject.upload_options).and_return(true)
allow_any_instance_of(LogStash::Outputs::S3::WriteBucketPermissionValidator).to receive(:valid?).and_return(true)
end

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

describe "additional_settings" do
context "when enabling force_path_style" do
let(:additional_settings) do
{ "additional_settings" => { "force_path_style" => true } }
end

it "validates the prefix" do
expect(Aws::S3::Bucket).to receive(:new).twice.with(anything, hash_including("force_path_style" => true)).and_call_original
described_class.new(options.merge(additional_settings)).register
end
end
context "when using a non existing setting" do
let(:additional_settings) do
{ "additional_settings" => { "doesnt_exist" => true } }
end

it "raises an error" do
plugin = described_class.new(options.merge(additional_settings))
expect { plugin.register }.to raise_error(ArgumentError)
end
end
end

it "allow to not validate credentials" do
s3 = described_class.new(options.merge({"validate_credentials_on_root_bucket" => false}))
expect_any_instance_of(LogStash::Outputs::S3::WriteBucketPermissionValidator).not_to receive(:valid?).with(any_args)
Expand All @@ -152,6 +174,7 @@

context "receiving events" do
before do
allow(subject).to receive(:bucket_resource).and_return(mock_bucket)
subject.register
end

Expand Down