From 59c6476c4f6a12723924f308c95c9eb832527ceb Mon Sep 17 00:00:00 2001 From: Joao Duarte Date: Thu, 29 Mar 2018 23:40:51 +0100 Subject: [PATCH] add option for additional settings --- docs/index.asciidoc | 24 ++++++++++++++++++++++++ lib/logstash/outputs/s3.rb | 6 ++++-- spec/outputs/s3_spec.rb | 27 +++++++++++++++++++++++++-- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/docs/index.asciidoc b/docs/index.asciidoc index 4d64cc18..27ad9f85 100644 --- a/docs/index.asciidoc +++ b/docs/index.asciidoc @@ -77,6 +77,7 @@ This plugin supports the following configuration options plus the <> |<>|No +| <> |<>|No | <> |<>|No | <> |<>|Yes | <> |<>, 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 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 <> + * 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` diff --git a/lib/logstash/outputs/s3.rb b/lib/logstash/outputs/s3.rb index 6170e5c5..28c28234 100644 --- a/lib/logstash/outputs/s3.rb +++ b/lib/logstash/outputs/s3.rb @@ -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. @@ -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) diff --git a/spec/outputs/s3_spec.rb b/spec/outputs/s3_spec.rb index 7e0a2fad..a6fef307 100644 --- a/spec/outputs/s3_spec.rb +++ b/spec/outputs/s3_spec.rb @@ -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 @@ -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) @@ -152,6 +174,7 @@ context "receiving events" do before do + allow(subject).to receive(:bucket_resource).and_return(mock_bucket) subject.register end