diff --git a/app/controllers/fluentd/settings/out_forward_controller.rb b/app/controllers/fluentd/settings/out_forward_controller.rb
index f449a31..f9f6cb4 100644
--- a/app/controllers/fluentd/settings/out_forward_controller.rb
+++ b/app/controllers/fluentd/settings/out_forward_controller.rb
@@ -4,6 +4,11 @@ class Fluentd::Settings::OutForwardController < ApplicationController
def show
@setting = Fluentd::Setting::OutForward.new({
+ secondary: {
+ "0" => {
+ type: "file",
+ }
+ }
})
end
@@ -27,7 +32,10 @@ class Fluentd::Settings::OutForwardController < ApplicationController
def setting_params
params.require(:fluentd_setting_out_forward).permit(*Fluentd::Setting::OutForward::KEYS).merge(
- params.require(:fluentd_setting_out_forward).permit(:server => Fluentd::Setting::OutForward::Server::KEYS)
+ params.require(:fluentd_setting_out_forward).permit(
+ :server => Fluentd::Setting::OutForward::Server::KEYS,
+ :secondary => Fluentd::Setting::OutForward::Secondary::KEYS,
+ ),
)
end
diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb
index b13dd67..773f558 100644
--- a/app/helpers/settings_helper.rb
+++ b/app/helpers/settings_helper.rb
@@ -3,6 +3,8 @@ module SettingsHelper
html = '
'
case form.object.column_type(key)
+ when :hidden
+ return form.hidden_field(key)
when :boolean, :flag
html << form.check_box(key, {}, "true", "false")
html << " " # NOTE: Adding space for padding
diff --git a/app/models/fluentd/setting/common.rb b/app/models/fluentd/setting/common.rb
index d89e3a4..d1f883f 100644
--- a/app/models/fluentd/setting/common.rb
+++ b/app/models/fluentd/setting/common.rb
@@ -5,7 +5,7 @@ class Fluentd
include ActiveModel::Model
module ClassMethods
- attr_accessor :values, :types, :children
+ attr_accessor :values, :types, :children, :hidden_values
def choice(key, values)
@values ||= {}
@@ -13,6 +13,10 @@ class Fluentd
set_type(:choice, [key])
end
+ def hidden(key)
+ set_type(:hidden, [key])
+ end
+
def nested(key, klass, options = {})
# e.g.:
#
@@ -92,7 +96,7 @@ class Fluentd
"\n" + child_instance.to_config(key).gsub(/^/m, " ")
end
end.join
- else
+ else # including :hidden
print_if_present(key)
end
end
diff --git a/app/models/fluentd/setting/out_forward.rb b/app/models/fluentd/setting/out_forward.rb
index 711f40e..75605df 100644
--- a/app/models/fluentd/setting/out_forward.rb
+++ b/app/models/fluentd/setting/out_forward.rb
@@ -14,18 +14,31 @@ class Fluentd
validates :host, presence: true
end
+ class Secondary
+ include Common
+ KEYS = [
+ :path, :type
+ ].freeze
+
+ attr_accessor(*KEYS)
+
+ hidden :type
+ validates :path, presence: true
+ end
+
include Common
KEYS = [
:match,
:send_timeout, :recover_wait, :heartbeat_type, :heartbeat_interval,
:phi_threshold, :hard_timeout,
- :server
+ :server, :secondary
].freeze
attr_accessor(*KEYS)
choice :heartbeat_type, %w(udp tcp)
nested :server, Server
+ nested :secondary, Secondary
validates :match, presence: true
validate :validate_at_least_one_server
diff --git a/app/views/fluentd/settings/out_forward/_form.html.haml b/app/views/fluentd/settings/out_forward/_form.html.haml
index ce23683..abe8feb 100644
--- a/app/views/fluentd/settings/out_forward/_form.html.haml
+++ b/app/views/fluentd/settings/out_forward/_form.html.haml
@@ -3,6 +3,7 @@
= form_for(@setting, url: finish_fluentd_setting_out_forward_path(@fluentd), html: {class: "ignore-rails-error-div"}) do |f|
= field(f, :match)
= field(f, :server)
+ = field(f, :secondary)
.well.well-sm
%h4{"data-toggle" => "collapse", "href" => "#advanced-setting"}
diff --git a/spec/models/fluentd/setting/common_spec.rb b/spec/models/fluentd/setting/common_spec.rb
index 0c90f9c..de3c1c4 100644
--- a/spec/models/fluentd/setting/common_spec.rb
+++ b/spec/models/fluentd/setting/common_spec.rb
@@ -32,6 +32,18 @@ describe Fluentd::Setting::Common do
it { subject.column_type(:foo).should_not == :flag }
end
+ describe "#hidden" do
+ subject do
+ Class.new do
+ include Fluentd::Setting::Common
+ attr_accessor :hide
+ hidden :hide
+ end.new
+ end
+
+ it { subject.column_type(:hide).should == :hidden }
+ end
+
describe "#choice" do
subject do
Class.new do
@@ -109,10 +121,11 @@ describe Fluentd::Setting::Common do
end
@klass = Class.new do
include Fluentd::Setting::Common
- KEYS = [:key1, :key2, :flag1, :ch, :child, :string] # FIXME: display "warning: already initialized constant KEYS", but works :(
+ KEYS = [:key1, :key2, :flag1, :hide, :ch, :child, :string] # FIXME: display "warning: already initialized constant KEYS", but works :(
attr_accessor(*KEYS)
booleans :key1, :key2
flags :flag1
+ hidden :hide
choice :ch, %w(foo bar)
nested :child, Child
end
@@ -140,6 +153,11 @@ describe Fluentd::Setting::Common do
end
end
+ describe "hidden" do
+ let(:params) { {hide: "foo"} }
+ it { should include("hide foo\n") }
+ end
+
describe "choice" do
let(:params) { {ch: "foo"} }
it { should include("ch foo\n") }