Add initial_params

Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
This commit is contained in:
Kenji Okimoto 2018-06-21 15:26:01 +09:00
parent f87367a656
commit 3a2835429a
No known key found for this signature in database
GPG Key ID: F9E3E329A5C5E4A1
3 changed files with 80 additions and 1 deletions

View File

@ -110,6 +110,25 @@ class Fluentd
self._sections.key?(:format)
end
def initial_params
new # ensure to load attributes
params = {}
self._defaults.each do |key, value|
if key.to_s.start_with?("@")
params[key.to_s[1..-1].to_sym] = value
else
params[key] = value
end
end
self._sections.each do |key, section|
next if section.initial_params.blank?
params[key] = {
"0" => section.initial_params.stringify_keys
}
end
params
end
def permit_params
self.new # init
keys = self._types.keys

View File

@ -6,13 +6,14 @@ class Fluentd
register_plugin("input", "forward")
def self.initial_params
{
params = {
bind: "0.0.0.0",
port: 24224,
linger_timeout: 0,
chunk_size_limit: nil,
chunk_size_warn_limit: nil,
}
super.compact.deep_merge(params)
end
def common_options

View File

@ -7,6 +7,65 @@ describe Fluentd::Setting::InForward do
{}
}
describe ".initial_params" do
subject { klass.initial_params }
let(:expected) do
{
log_level: nil,
port: 24224,
bind: "0.0.0.0",
backlog: nil,
linger_timeout: 0,
blocking_timeout: 0.5,
chunk_size_limit: nil,
chunk_size_warn_limit: nil,
deny_keepalive: false,
resolve_hostname: nil,
skip_invalid_event: false,
source_address_key: nil,
source_hostname_key: nil,
security: {
"0" => {
"user_auth" => false,
"allow_anonymous_source" => true,
"client" => {
"0" => {
"host" => nil,
"network" => nil,
"shared_key" => nil,
"users" => [],
}
}
}
},
transport: {
"0" => {
"protocol" => :tcp,
"version" => :TLSv1_2,
"ciphers" => "ALL:!aNULL:!eNULL:!SSLv2",
"insecure" => false,
"ca_path" => nil,
"cert_path" => nil,
"private_key_path" => nil,
"private_key_passphrase" => nil,
"client_cert_auth" => false,
"ca_cert_path" => nil,
"ca_private_key_path" => nil,
"ca_private_key_passphrase" => nil,
"generate_private_key_length" => 2048,
"generate_cert_country" => "US",
"generate_cert_state" => "CA",
"generate_cert_locality" => "Mountain View",
"generate_cert_common_name" => nil,
"generate_cert_expiration" => 315360000,
"generate_cert_digest" => :sha256,
}
},
}
end
it { should == expected }
end
describe "#valid?" do
it "should be valid" do
params = valid_attributes.dup