From 3a2835429a3ab643fc9cb73abb5a53477f36dd1d Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Thu, 21 Jun 2018 15:26:01 +0900 Subject: [PATCH] Add initial_params Signed-off-by: Kenji Okimoto --- .../fluentd/setting/plugin_parameter.rb | 19 ++++++ app/models/fluentd/setting/in_forward.rb | 3 +- .../models/fluentd/setting/in_forward_spec.rb | 59 +++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/fluentd/setting/plugin_parameter.rb b/app/models/concerns/fluentd/setting/plugin_parameter.rb index 70143fa..924a405 100644 --- a/app/models/concerns/fluentd/setting/plugin_parameter.rb +++ b/app/models/concerns/fluentd/setting/plugin_parameter.rb @@ -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 diff --git a/app/models/fluentd/setting/in_forward.rb b/app/models/fluentd/setting/in_forward.rb index d4b7ba0..375531c 100644 --- a/app/models/fluentd/setting/in_forward.rb +++ b/app/models/fluentd/setting/in_forward.rb @@ -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 diff --git a/spec/models/fluentd/setting/in_forward_spec.rb b/spec/models/fluentd/setting/in_forward_spec.rb index 6468244..7baebf7 100644 --- a/spec/models/fluentd/setting/in_forward_spec.rb +++ b/spec/models/fluentd/setting/in_forward_spec.rb @@ -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