Skip to content

Commit

Permalink
Adding path validation
Browse files Browse the repository at this point in the history
Doing 2 checks:
- Check if we have an absolute path
- Check if the file exists

Requires 'pathname' gem
  • Loading branch information
Richard Pijnenburg committed Mar 6, 2013
1 parent 3b1f0a0 commit be87aaf
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/logstash/config/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require "logstash/util/password"
require "logstash/version"
require "i18n"
require "pathname"

# This module is meant as a mixin to classes wishing to be configurable from
# config files
Expand Down Expand Up @@ -391,6 +392,20 @@ def validate_value(value, validator)
end

result = ::LogStash::Util::Password.new(value.first)
when :path
if value.size > 1 # Only 1 value wanted
return false, "Expected path (one value), got #{value.size} values?"
end

unless (Pathname.new value.first).absolute? == false # We want an absolute path
return false, "Require absolute path, got relative path #{value.first}?"
end

unless File.exists?(value.first) # Check if the file exists
return false, "File does not exist or cannot be opened"
end

result = value.first
end # case validator
else
return false, "Unknown validator #{validator.class}"
Expand Down

0 comments on commit be87aaf

Please sign in to comment.