Skip to content

Commit

Permalink
add validator for usage of storage plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
tagomoris committed Jan 30, 2017
1 parent b76473b commit 57f957a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/fluent/plugin_helper/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def storage_create(usage: '', type: nil, conf: nil, default_type: nil)
if conf && !conf.arg.empty?
usage = conf.arg
end
if !usage.empty? && usage !~ /^[a-zA-Z][-_.a-zA-Z0-9]*$/
raise Fluent::ConfigError, "Argument in <storage ARG> uses invalid characters: '#{usage}'"
end

s = @_storages[usage]
if s && s.running
Expand Down Expand Up @@ -98,6 +101,9 @@ def configure(conf)
super

@storage_configs.each do |section|
if !section.usage.empty? && section.usage !~ /^[a-zA-Z][-_.a-zA-Z0-9]*$/
raise Fluent::ConfigError, "Argument in <storage ARG> uses invalid characters: '#{section.usage}'"
end
if @_storages[section.usage]
raise Fluent::ConfigError, "duplicated storages configured: #{section.usage}"
end
Expand Down
11 changes: 11 additions & 0 deletions test/plugin_helper/test_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ class Dummy2 < Fluent::Plugin::TestBase
end
end

test 'raises config error if config argument has invalid characters' do
d = Dummy.new
assert_raise Fluent::ConfigError.new("Argument in <storage ARG> uses invalid characters: 'yaa y'") do
d.configure(config_element('root', '', {}, [config_element('storage', 'yaa y', {'@type' => 'local'})]))
end
d.configure(config_element())
assert_raise Fluent::ConfigError.new("Argument in <storage ARG> uses invalid characters: 'a,b'") do
d.storage_create(usage: 'a,b', type: 'local')
end
end

test 'can be configured without storage sections' do
d = Dummy.new
assert_nothing_raised do
Expand Down

0 comments on commit 57f957a

Please sign in to comment.