Skip to content

Commit

Permalink
#6696 validate evaluation result
Browse files Browse the repository at this point in the history
Fixes #7411
  • Loading branch information
original-brownbear authored and suyograo committed Jun 13, 2017
1 parent d0ca122 commit 33f2f2f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions logstash-core/lib/logstash/config/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ def config_init(params)
end # def config_init

module DSL

include LogStash::Util::EnvironmentVariables

attr_accessor :flags

# If name is given, set the name and return it.
Expand Down Expand Up @@ -388,6 +391,8 @@ def validate_value(value, validator)
# (see LogStash::Inputs::File for example)
result = nil

value = deep_replace(value)

if validator.nil?
return true, value
elsif validator.is_a?(Array)
Expand Down
12 changes: 12 additions & 0 deletions logstash-core/spec/logstash/config/mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,13 @@ def initialize(params)
before do
ENV["FunString"] = "fancy"
ENV["FunBool"] = "true"
ENV["SERVER_LS_TEST_ADDRESS"] = "some.host.address.tld"
end

after do
ENV.delete("FunString")
ENV.delete("FunBool")
ENV.delete("SERVER_LS_TEST_ADDRESS")
end

subject do
Expand All @@ -397,6 +399,16 @@ def initialize(params)
expect(subject.nestedArray).to(be == { "level1" => [{ "key1" => "http://fancy:8080/blah.txt" }, { "key2" => "http://fancy:8080/foo.txt" }] })
expect(subject.deepHash).to(be == { "level1" => { "level2" => { "level3" => { "key1" => "http://fancy:8080/blah.txt" } } } })
end

it "should validate settings after interpolating ENV variables" do
expect {
Class.new(LogStash::Filters::Base) do
include LogStash::Config::Mixin
config_name "test"
config :server_address, :validate => :uri
end.new({"server_address" => "${SERVER_LS_TEST_ADDRESS}"})
}.not_to raise_error
end
end

context "should support $ in values" do
Expand Down

0 comments on commit 33f2f2f

Please sign in to comment.