From ee8c45db8ad33f17db3b650914743fd2a0b6e3d3 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Tue, 19 Jun 2018 18:05:24 +0900 Subject: [PATCH 01/21] Add transport_common_options,transport_advanced_options Signed-off-by: Kenji Okimoto --- app/models/fluentd/setting/in_forward.rb | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/models/fluentd/setting/in_forward.rb b/app/models/fluentd/setting/in_forward.rb index db1e5e3..d4b7ba0 100644 --- a/app/models/fluentd/setting/in_forward.rb +++ b/app/models/fluentd/setting/in_forward.rb @@ -29,6 +29,35 @@ class Fluentd :blocking_timeout, ] end + + def transport_common_options + [ + :ca_path, + :cert_path, + :private_key_path, + :private_key_passphrase + ] + end + + def transport_advanced_options + [ + :version, + :ciphers, + :insecure, + :client_cert_auth, + :ca_cert_path, + :ca_private_key_path, + :ca_private_key_passphrase, + :generate_private_key_length, + :generate_cert_country, + :generate_cert_state, + :generate_cert_locality, + :generate_cert_common_name, + :generate_cert_common_name, + :generate_cert_expiration, + :generate_cert_digest + ] + end end end end From a644442687d04e656fb694d6863bc4f2ca38b8e7 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Tue, 19 Jun 2018 18:05:56 +0900 Subject: [PATCH 02/21] Add transport section to in_forward Signed-off-by: Kenji Okimoto --- app/javascript/packs/transport_section.js | 71 +++++++++++++++++++ .../settings/in_forward/_form.html.haml | 2 + .../shared/vue/_transport_section.html.haml | 30 ++++++++ 3 files changed, 103 insertions(+) create mode 100644 app/javascript/packs/transport_section.js create mode 100644 app/views/shared/vue/_transport_section.html.haml diff --git a/app/javascript/packs/transport_section.js b/app/javascript/packs/transport_section.js new file mode 100644 index 0000000..a57b4c5 --- /dev/null +++ b/app/javascript/packs/transport_section.js @@ -0,0 +1,71 @@ +'use strict' +import 'lodash/lodash' + +import ConfigField from './config_field' + +$(document).ready(() => { + new Vue({ + el: '#transport-section', + components: { + "config-field": ConfigField + }, + props: [ + "transportType", + ], + propsData: { + "transportType": "tcp" + }, + data: function() { + return { + pluginType: null, + pluginName: null, + options: ["tcp", "tls"], + commonOptions: [], + advancedOptions: [] + + } + }, + computed: { + token: function() { + return Rails.csrfToken() + } + }, + filters: { + toUpper: function(value) { + return _.toUpper(value) + } + }, + beforeMount: function() { + this.pluginType = this.$el.attributes.pluginType.nodeValue + this.pluginName = this.$el.attributes.pluginName.nodeValue + }, + mounted: function() { + }, + methods: { + onChange: function() { + console.log(this.pluginType, this.pluginName, this.transportType) + this.updateSection() + }, + + updateSection: function() { + if (this.transportType === "tcp") { + return + } + $.ajax({ + method: "GET", + url: "/api/config_definitions", + headers: { + 'X-CSRF-Token': this.token + }, + data: { + type: this.pluginType, + name: this.pluginName + } + }).then((data) => { + this.commonOptions = data.transport.commonOptions + this.advancedOptions = data.transport.advancedOptions + }) + } + } + }) +}) diff --git a/app/views/fluentd/settings/in_forward/_form.html.haml b/app/views/fluentd/settings/in_forward/_form.html.haml index 6ea3741..e1f00a8 100644 --- a/app/views/fluentd/settings/in_forward/_form.html.haml +++ b/app/views/fluentd/settings/in_forward/_form.html.haml @@ -5,6 +5,8 @@ - @setting.common_options.each do |key| = f.field(key) + = render "shared/vue/transport_section", setting: @setting, form: f + .card.card-body.bg-light %h4{"data-toggle" => "collapse", "href" => "#advanced-setting"} = icon('fa-caret-down') diff --git a/app/views/shared/vue/_transport_section.html.haml b/app/views/shared/vue/_transport_section.html.haml new file mode 100644 index 0000000..c61877e --- /dev/null +++ b/app/views/shared/vue/_transport_section.html.haml @@ -0,0 +1,30 @@ +- add_javascript_pack_tag("transport_section") + += render "shared/vue/config_field" + +#transport-section.form-group.card.card-body.bg-light{"pluginType" => setting.plugin_type, + "pluginName" => setting.plugin_name} + %label + Transport + .form-group + %select{"class" => "form-control", + "v-model" => "transportType", + "v-on:change" => "onChange"} + %option{"v-for" => "option in options", + "v-bind:value" => "option", + "v-bind:selected" => "transportType === option"} + {{ option | toUpper }} + %p{"v-if" => 'transportType === "tcp"'} + Nothing to configure + %template(v-else) + %template{"v-for" => "option in commonOptions"} + %config-field{"v-bind:plugin-type" => "pluginType", + "v-bind:option" => "option"} + .card.card-body.bg-light + %h4{"data-toggle" => "collapse", "href" => "#transport-advanced-setting"} + = icon('fa-caret-down') + = t('terms.advanced_setting') + '(TLS)' + #transport-advanced-setting.collapse + %template{"v-for" => "option in advancedOptions"} + %config-field{"v-bind:plugin-type" => "pluginType", + "v-bind:option" => "option"} From 7ceeadc6f6e7db838bee994d60c89ac04c082241 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 10:04:30 +0900 Subject: [PATCH 03/21] Humanize label like Rails Signed-off-by: Kenji Okimoto --- app/javascript/packs/config_field.js | 7 +++++++ app/views/shared/vue/_config_field.html.haml | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/javascript/packs/config_field.js b/app/javascript/packs/config_field.js index fd72481..3580a7e 100644 --- a/app/javascript/packs/config_field.js +++ b/app/javascript/packs/config_field.js @@ -1,4 +1,5 @@ 'use strict' +import 'lodash/lodash' const ConfigField = { template: "#vue-config-field", @@ -16,6 +17,12 @@ const ConfigField = { } }, + filters: { + humanize: function(value) { + return _.capitalize(value.replace("_", " ")) + } + }, + mounted: function() { this.expression = this.initialExpression this.timeFormat = this.initialTimeFormat diff --git a/app/views/shared/vue/_config_field.html.haml b/app/views/shared/vue/_config_field.html.haml index 52e2e59..1aeaa90 100644 --- a/app/views/shared/vue/_config_field.html.haml +++ b/app/views/shared/vue/_config_field.html.haml @@ -5,7 +5,7 @@ "data-toggle" => "tooltip", "data-placement" => "right", "v-bind:title" => "option.desc"} - {{ option.name }} + {{ option.name | humanize }} %select{"v-bind:id" => "inputId(pluginType, option)", "v-bind:name" => "inputName(pluginType, option)", "class" => "form-control"} @@ -22,13 +22,13 @@ "data-toggle" => "tooltip", "data-placement" => "right", "v-bind:title" => "option.desc"} - {{ option.name }} + {{ option.name | humanize }} %template(v-else) %label{"v-bind:for" => "inputId(pluginType, option)", "data-toggle" => "tooltip", "data-placement" => "right", "v-bind:title" => "option.desc"} - {{ option.name }} + {{ option.name | humanize }} %template{"v-if" => 'option.name === "expression"'} %input{"v-bind:id" => "inputId(pluginType, option)", "v-bind:name" => "inputName(pluginType, option)", From ce9434126a2dd4ba4379c6d530b0fb1aa92f0c04 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 10:05:02 +0900 Subject: [PATCH 04/21] Set expression and time_format if needed Signed-off-by: Kenji Okimoto --- app/javascript/packs/config_field.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/javascript/packs/config_field.js b/app/javascript/packs/config_field.js index 3580a7e..9bd1e93 100644 --- a/app/javascript/packs/config_field.js +++ b/app/javascript/packs/config_field.js @@ -24,8 +24,12 @@ const ConfigField = { }, mounted: function() { - this.expression = this.initialExpression - this.timeFormat = this.initialTimeFormat + if (this.option.name === "expression") { + this.expression = this.initialExpression + } + if (this.option.name === "time_format") { + this.timeFormat = this.initialTimeFormat + } this.$on("hook:updated", () => { this.$nextTick(() => { console.log("config-field hook:updated") From 2be60eec6225cc9d9674d1cd5a6b06810bf03c86 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 10:05:25 +0900 Subject: [PATCH 05/21] Add updated hook to set expression and time_format Set expression and timeFormat properly if selected parseType is changed. Signed-off-by: Kenji Okimoto --- app/javascript/packs/config_field.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/javascript/packs/config_field.js b/app/javascript/packs/config_field.js index 9bd1e93..93ffea8 100644 --- a/app/javascript/packs/config_field.js +++ b/app/javascript/packs/config_field.js @@ -39,6 +39,20 @@ const ConfigField = { }) }, + updated: function() { + if (this.option.name === "expression") { + this.expression = this.initialExpression + } + if (this.option.name === "time_format") { + this.timeFormat = this.initialTimeFormat + } + this.$nextTick(() => { + console.log("config-field updated") + $("[data-toggle=tooltip]").tooltip("dispose") + $("[data-toggle=tooltip]").tooltip("enable") + }) + }, + watch: { "expression": function(newValue, oldValue) { this.$emit("change-parse-config", { From 033e702df5ba6f2ef5ac2e7bcb10348653172f80 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 10:07:51 +0900 Subject: [PATCH 06/21] Remove redundant code Signed-off-by: Kenji Okimoto --- app/javascript/packs/config_field.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/javascript/packs/config_field.js b/app/javascript/packs/config_field.js index 93ffea8..b93db95 100644 --- a/app/javascript/packs/config_field.js +++ b/app/javascript/packs/config_field.js @@ -30,13 +30,6 @@ const ConfigField = { if (this.option.name === "time_format") { this.timeFormat = this.initialTimeFormat } - this.$on("hook:updated", () => { - this.$nextTick(() => { - console.log("config-field hook:updated") - $("[data-toggle=tooltip]").tooltip("dispose") - $("[data-toggle=tooltip]").tooltip("enable") - }) - }) }, updated: function() { From e5e5c7206995bedcb5496c1a62c64ca241a6ed2f Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 10:45:29 +0900 Subject: [PATCH 07/21] Fix humanize filter Signed-off-by: Kenji Okimoto --- app/javascript/packs/config_field.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/javascript/packs/config_field.js b/app/javascript/packs/config_field.js index b93db95..8660512 100644 --- a/app/javascript/packs/config_field.js +++ b/app/javascript/packs/config_field.js @@ -19,7 +19,7 @@ const ConfigField = { filters: { humanize: function(value) { - return _.capitalize(value.replace("_", " ")) + return _.capitalize(value.replace(/_/g, " ")) } }, From d549818c23d986034ca3267f3cd650415cf9dd8f Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 10:45:45 +0900 Subject: [PATCH 08/21] Add style class form-control to enum field Signed-off-by: Kenji Okimoto --- app/form_builders/fluentd_form_builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/form_builders/fluentd_form_builder.rb b/app/form_builders/fluentd_form_builder.rb index 3db57d8..0bcb91a 100644 --- a/app/form_builders/fluentd_form_builder.rb +++ b/app/form_builders/fluentd_form_builder.rb @@ -34,7 +34,7 @@ class FluentdFormBuilder < ActionView::Helpers::FormBuilder def enum_field(key, options) label(key, nil, data: { toggle: "tooltip", placement: "right" }, title: object.desc(key)) + - select(key, object.list_of(key), options, { class: "enum" }) + select(key, object.list_of(key), options, { class: "enum form-control" }) end def bool_field(key, options) From 417291566ffd2a55842d54c1f038f0cbc57d8a23 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 10:52:28 +0900 Subject: [PATCH 09/21] in_syslog: Hide transport section and blocking_timeout Signed-off-by: Kenji Okimoto --- app/models/fluentd/setting/in_syslog.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/fluentd/setting/in_syslog.rb b/app/models/fluentd/setting/in_syslog.rb index 8ed0f9d..9ff270c 100644 --- a/app/models/fluentd/setting/in_syslog.rb +++ b/app/models/fluentd/setting/in_syslog.rb @@ -27,7 +27,9 @@ class Fluentd def hidden_options [ - :parse + :parse, + :transport, + :blocking_timeout ] end end From fdc012cc965219efcbe0155354fd24d5b792ca51 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 11:00:45 +0900 Subject: [PATCH 10/21] Use local variables Signed-off-by: Kenji Okimoto --- app/views/fluentd/settings/in_forward/_form.html.haml | 8 ++++---- app/views/shared/settings/show.html.haml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/fluentd/settings/in_forward/_form.html.haml b/app/views/fluentd/settings/in_forward/_form.html.haml index e1f00a8..0245f08 100644 --- a/app/views/fluentd/settings/in_forward/_form.html.haml +++ b/app/views/fluentd/settings/in_forward/_form.html.haml @@ -1,18 +1,18 @@ = render "shared/setting_errors" - # NOTE: plugin_setting_form_action_url is defined at SettingConcern -= form_with(model: @setting, scope: "setting", url: plugin_setting_form_action_url(@fluentd), local: true, class: "ignore-rails-error-div", builder: FluentdFormBuilder) do |f| - - @setting.common_options.each do |key| += form_with(model: setting, scope: "setting", url: plugin_setting_form_action_url(fluentd), local: true, class: "ignore-rails-error-div", builder: FluentdFormBuilder) do |f| + - setting.common_options.each do |key| = f.field(key) - = render "shared/vue/transport_section", setting: @setting, form: f + = render "shared/vue/transport_section", setting: setting, form: f .card.card-body.bg-light %h4{"data-toggle" => "collapse", "href" => "#advanced-setting"} = icon('fa-caret-down') = t('terms.advanced_setting') #advanced-setting.collapse - - @setting.advanced_options.each do |key| + - setting.advanced_options.each do |key| = f.field(key) = f.submit t('fluentd.common.finish'), class: "btn btn-lg btn-primary pull-right" diff --git a/app/views/shared/settings/show.html.haml b/app/views/shared/settings/show.html.haml index 89d9f01..1f342ee 100644 --- a/app/views/shared/settings/show.html.haml +++ b/app/views/shared/settings/show.html.haml @@ -6,6 +6,6 @@ = raw t("fluentd.settings.#{target_plugin_name}.option_guide") - if lookup_context.exists?("form", controller.controller_path, true) - = render "#{controller.controller_path}/form" + = render "#{controller.controller_path}/form", setting: @setting, fluentd: @fluentd - else - = render "shared/settings/form" + = render "shared/settings/form", setting: @setting, fluentd: @fluentd From b2a73274b81af5b755bcaa40dae1b9e597b69ada Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 12:03:59 +0900 Subject: [PATCH 11/21] out_forward: Display TLS options on form Signed-off-by: Kenji Okimoto --- .../api/config_definitions_controller.rb | 6 ++ app/javascript/packs/config_field.js | 13 +++- app/javascript/packs/transport_config.js | 67 +++++++++++++++++++ app/models/fluentd/setting/out_forward.rb | 15 ++++- .../settings/out_forward/_form.html.haml | 18 +++++ .../shared/vue/_transport_config.html.haml | 22 ++++++ 6 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 app/javascript/packs/transport_config.js create mode 100644 app/views/fluentd/settings/out_forward/_form.html.haml create mode 100644 app/views/shared/vue/_transport_config.html.haml diff --git a/app/controllers/api/config_definitions_controller.rb b/app/controllers/api/config_definitions_controller.rb index be88c04..e5b8e68 100644 --- a/app/controllers/api/config_definitions_controller.rb +++ b/app/controllers/api/config_definitions_controller.rb @@ -41,6 +41,12 @@ class Api::ConfigDefinitionsController < ApplicationController advancedOptions: transport_advanced_options } end + + if type == "output" && name == "forward" + tls_options = build_options(target, target.tls_options) + options[:tlsOptions] = tls_options + end + render json: options end diff --git a/app/javascript/packs/config_field.js b/app/javascript/packs/config_field.js index 8660512..5496a62 100644 --- a/app/javascript/packs/config_field.js +++ b/app/javascript/packs/config_field.js @@ -63,10 +63,19 @@ const ConfigField = { methods: { inputId: function(pluginType, option) { - return `setting_${pluginType}_0__${option.name}` + if (pluginType === "output") { + return `setting_${option.name}` + } else { + return `setting_${pluginType}_0__${option.name}` + } + }, inputName: function(pluginType, option) { - return `setting[${pluginType}[0]][${option.name}]` + if (pluginType === "output") { + return `setting[${option.name}]` + } else { + return `setting[${pluginType}[0]][${option.name}]` + } }, checked: function(checked) { if (checked === true || checked === "true") { diff --git a/app/javascript/packs/transport_config.js b/app/javascript/packs/transport_config.js new file mode 100644 index 0000000..cb30351 --- /dev/null +++ b/app/javascript/packs/transport_config.js @@ -0,0 +1,67 @@ +'use strict' + +import ConfigField from './config_field' + +$(document).ready(() => { + new Vue({ + el: '#transport-config', + components: { + "config-field": ConfigField + }, + props: [ + "transportType", + ], + propsData: { + "transportType": "tcp" + }, + data: function() { + return { + pluginType: null, + pluginName: null, + options: ["tcp", "tls"], + tlsOptions: [] + } + }, + computed: { + token: function() { + return Rails.csrfToken() + } + }, + filters: { + toUpper: function(value) { + return _.toUpper(value) + } + }, + beforeMount: function() { + this.pluginType = this.$el.attributes.pluginType.nodeValue + this.pluginName = this.$el.attributes.pluginName.nodeValue + }, + mounted: function() { + }, + methods: { + onChange: function() { + console.log(this.pluginType, this.pluginName, this.transportType) + this.updateSection() + }, + + updateSection: function() { + if (this.transportType === "tcp") { + return + } + $.ajax({ + method: "GET", + url: "/api/config_definitions", + headers: { + 'X-CSRF-Token': this.token + }, + data: { + type: this.pluginType, + name: this.pluginName + } + }).then((data) => { + this.tlsOptions = data.tlsOptions + }) + } + } + }) +}) diff --git a/app/models/fluentd/setting/out_forward.rb b/app/models/fluentd/setting/out_forward.rb index d6bdcc3..2eeab4a 100644 --- a/app/models/fluentd/setting/out_forward.rb +++ b/app/models/fluentd/setting/out_forward.rb @@ -39,9 +39,20 @@ class Fluentd def hidden_options [ :inject, :buffer, + # Deprecated options :host, :port, - # We don't support TLS configuration via fluentd-ui for now. - :transport, :tls_version, :tls_ciphers, :tls_insecure_mode, :tls_verify_hostname, :tls_cert_path + :transport + ].concat(tls_options) # Hide TLS related options to customize view + end + + def tls_options + [ + :tls_version, + :tls_ciphers, + :tls_insecure_mode, + :tls_allow_self_signed_cert, + :tls_verify_hostname, + :tls_cert_path ] end end diff --git a/app/views/fluentd/settings/out_forward/_form.html.haml b/app/views/fluentd/settings/out_forward/_form.html.haml new file mode 100644 index 0000000..5dfe67e --- /dev/null +++ b/app/views/fluentd/settings/out_forward/_form.html.haml @@ -0,0 +1,18 @@ += render "shared/setting_errors" + +- # NOTE: plugin_setting_form_action_url is defined at SettingConcern += form_with(model: setting, scope: "setting", url: plugin_setting_form_action_url(fluentd), local: true, class: "ignore-rails-error-div", builder: FluentdFormBuilder) do |f| + - setting.common_options.each do |key| + = f.field(key) + + = render "shared/vue/transport_config", setting: setting + + .card.card-body.bg-light + %h4{"data-toggle" => "collapse", "href" => "#advanced-setting"} + = icon('fa-caret-down') + = t('terms.advanced_setting') + #advanced-setting.collapse + - setting.advanced_options.each do |key| + = f.field(key) + + = f.submit t('fluentd.common.finish'), class: "btn btn-lg btn-primary pull-right" diff --git a/app/views/shared/vue/_transport_config.html.haml b/app/views/shared/vue/_transport_config.html.haml new file mode 100644 index 0000000..eff7d6a --- /dev/null +++ b/app/views/shared/vue/_transport_config.html.haml @@ -0,0 +1,22 @@ +- add_javascript_pack_tag("transport_config") + += render "shared/vue/config_field" + +#transport-config.form-group.card.card-body.bg-light{"pluginType" => setting.plugin_type, + "pluginName" => setting.plugin_name} + %h4 + Transport + .form-group + %select{"class" => "form-control", + "v-model" => "transportType", + "v-on:change" => "onChange"} + %option{"v-for" => "option in options", + "v-bind:value" => "option", + "v-bind:selected" => "transportType === option"} + {{ option | toUpper }} + %p{"v-if" => 'transportType === "tcp"'} + Nothing to configure + %template(v-else) + %template{"v-for" => "option in tlsOptions"} + %config-field{"v-bind:plugin-type" => "pluginType", + "v-bind:option" => "option"} From f29ff276b658625f3b21bc92d114315549ee7b15 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 12:57:09 +0900 Subject: [PATCH 12/21] Use class method reformat_value Signed-off-by: Kenji Okimoto --- app/models/concerns/fluentd/setting/plugin_config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/fluentd/setting/plugin_config.rb b/app/models/concerns/fluentd/setting/plugin_config.rb index e52cfa0..78e07df 100644 --- a/app/models/concerns/fluentd/setting/plugin_config.rb +++ b/app/models/concerns/fluentd/setting/plugin_config.rb @@ -70,7 +70,7 @@ class Fluentd def skip?(key, value) return true if value.blank? if self._defaults.key?(key) - reformat_value(key, self._defaults[key]) == reformat_value(key, value) + self.class.reformat_value(key, self._defaults[key]) == self.class.reformat_value(key, value) else false end From 00fcad0e1e6e75941f6bcff6440577c1bb1bc58b Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 12:57:23 +0900 Subject: [PATCH 13/21] Stop writing empty section Signed-off-by: Kenji Okimoto --- app/models/concerns/fluentd/setting/plugin_config.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/fluentd/setting/plugin_config.rb b/app/models/concerns/fluentd/setting/plugin_config.rb index 78e07df..6207045 100644 --- a/app/models/concerns/fluentd/setting/plugin_config.rb +++ b/app/models/concerns/fluentd/setting/plugin_config.rb @@ -56,7 +56,9 @@ class Fluentd next if section_params.blank? section_params.each do |index, _section_params| sub_attrs, sub_elements = parse_attributes(_section_params) - elements << config_element(key, "", sub_attrs, sub_elements) + if sub_attrs.present? || sub_elements.present? # skip empty section + elements << config_element(key, "", sub_attrs, sub_elements) + end end end return params.to_h.reject{|key, value| skip?(key.to_sym, value) }, elements From 0ca86c8f337de15dfa97b594ff68bca1aaa6a3dd Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 12:58:00 +0900 Subject: [PATCH 14/21] Empty section is valid in most case Signed-off-by: Kenji Okimoto --- app/models/concerns/fluentd/setting/section_validator.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/concerns/fluentd/setting/section_validator.rb b/app/models/concerns/fluentd/setting/section_validator.rb index 8238441..5f4df18 100644 --- a/app/models/concerns/fluentd/setting/section_validator.rb +++ b/app/models/concerns/fluentd/setting/section_validator.rb @@ -10,6 +10,7 @@ class Fluentd def validate_sections self._section_params.each do |name, sections| sections.each do |section| + next if section.attributes.values.all?(&:blank?) if section.invalid? errors.add(name, :invalid, message: section.errors.full_messages) end From a1c084b988b5647d8a2622b236ce68068ea491f8 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 13:06:50 +0900 Subject: [PATCH 15/21] Skip enum value properly Signed-off-by: Kenji Okimoto --- app/models/concerns/fluentd/setting/plugin_parameter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/fluentd/setting/plugin_parameter.rb b/app/models/concerns/fluentd/setting/plugin_parameter.rb index 267fc88..70143fa 100644 --- a/app/models/concerns/fluentd/setting/plugin_parameter.rb +++ b/app/models/concerns/fluentd/setting/plugin_parameter.rb @@ -136,7 +136,7 @@ class Fluentd def reformat_value(name, value) type = column_type(name) return value if type.nil? # name == :time_key - return value if type == :enum + return value.to_sym if type == :enum return value if type == :regexp type_name = if type.is_a?(Fluentd::Setting::Type::Time) :time From 7d805155288a8f84e0c59eee79fe4f4f56a6e6bb Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 15:17:40 +0900 Subject: [PATCH 16/21] Remove redundant code Signed-off-by: Kenji Okimoto --- app/models/concerns/fluentd/setting/configurable.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/concerns/fluentd/setting/configurable.rb b/app/models/concerns/fluentd/setting/configurable.rb index 9967a7e..669067e 100644 --- a/app/models/concerns/fluentd/setting/configurable.rb +++ b/app/models/concerns/fluentd/setting/configurable.rb @@ -89,7 +89,6 @@ class Fluentd else attribute(name, :section) section_class = Class.new(::Fluentd::Setting::Section) - section_class.include(Fluentd::Setting::PluginParameter) section_class.section_name = name section_class.required = options[:required] section_class.multi = options[:multi] From 30ba197abd2f8af5cfd58960aa0db527423197a3 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 15:17:59 +0900 Subject: [PATCH 17/21] Remove unused code Signed-off-by: Kenji Okimoto --- app/javascript/packs/owned_plugin_form.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/app/javascript/packs/owned_plugin_form.js b/app/javascript/packs/owned_plugin_form.js index fd595e5..45f10aa 100644 --- a/app/javascript/packs/owned_plugin_form.js +++ b/app/javascript/packs/owned_plugin_form.js @@ -132,19 +132,6 @@ const OwnedPluginForm = { }, selectName: function(pluginType) { return `setting[${pluginType}_type]` - }, - inputId: function(pluginType, option) { - return `setting_${pluginType}_0__${option.name}` - }, - inputName: function(pluginType, option) { - return `setting[${pluginType}[0]][${option.name}]` - }, - checked: function(checked) { - if (checked === true || checked === "true") { - return "checked" - } else { - return "" - } } } } From d6516ea172a4f02cca71ca9f15b19199097192c6 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 15:18:32 +0900 Subject: [PATCH 18/21] Convert to vue component Signed-off-by: Kenji Okimoto --- app/javascript/packs/transport_config.js | 117 ++++++++---------- .../shared/vue/_transport_config.html.haml | 38 +++--- 2 files changed, 73 insertions(+), 82 deletions(-) diff --git a/app/javascript/packs/transport_config.js b/app/javascript/packs/transport_config.js index cb30351..40e2967 100644 --- a/app/javascript/packs/transport_config.js +++ b/app/javascript/packs/transport_config.js @@ -2,66 +2,59 @@ import ConfigField from './config_field' -$(document).ready(() => { - new Vue({ - el: '#transport-config', - components: { - "config-field": ConfigField - }, - props: [ - "transportType", - ], - propsData: { - "transportType": "tcp" - }, - data: function() { - return { - pluginType: null, - pluginName: null, - options: ["tcp", "tls"], - tlsOptions: [] - } - }, - computed: { - token: function() { - return Rails.csrfToken() - } - }, - filters: { - toUpper: function(value) { - return _.toUpper(value) - } - }, - beforeMount: function() { - this.pluginType = this.$el.attributes.pluginType.nodeValue - this.pluginName = this.$el.attributes.pluginName.nodeValue - }, - mounted: function() { - }, - methods: { - onChange: function() { - console.log(this.pluginType, this.pluginName, this.transportType) - this.updateSection() - }, - - updateSection: function() { - if (this.transportType === "tcp") { - return - } - $.ajax({ - method: "GET", - url: "/api/config_definitions", - headers: { - 'X-CSRF-Token': this.token - }, - data: { - type: this.pluginType, - name: this.pluginName - } - }).then((data) => { - this.tlsOptions = data.tlsOptions - }) - } +const TransportConfig = { + template: "#vue-transport-config", + components: { + "config-field": ConfigField + }, + props: [ + "pluginType", + "pluginName" + ], + data: function() { + return { + transportType: "tcp", + options: ["tcp", "tls"], + tlsOptions: [] } - }) -}) + }, + computed: { + token: function() { + return Rails.csrfToken() + } + }, + filters: { + toUpper: function(value) { + return _.toUpper(value) + } + }, + mounted: function() { + }, + methods: { + onChange: function() { + console.log(this.pluginType, this.pluginName, this.transportType) + this.updateSection() + }, + + updateSection: function() { + if (this.transportType === "tcp") { + return + } + $.ajax({ + method: "GET", + url: "/api/config_definitions", + headers: { + 'X-CSRF-Token': this.token + }, + data: { + type: this.pluginType, + name: this.pluginName + } + }).then((data) => { + this.tlsOptions = data.tlsOptions + }) + } + } +} + +export { TransportConfig as default } diff --git a/app/views/shared/vue/_transport_config.html.haml b/app/views/shared/vue/_transport_config.html.haml index eff7d6a..53e7166 100644 --- a/app/views/shared/vue/_transport_config.html.haml +++ b/app/views/shared/vue/_transport_config.html.haml @@ -1,22 +1,20 @@ -- add_javascript_pack_tag("transport_config") - = render "shared/vue/config_field" -#transport-config.form-group.card.card-body.bg-light{"pluginType" => setting.plugin_type, - "pluginName" => setting.plugin_name} - %h4 - Transport - .form-group - %select{"class" => "form-control", - "v-model" => "transportType", - "v-on:change" => "onChange"} - %option{"v-for" => "option in options", - "v-bind:value" => "option", - "v-bind:selected" => "transportType === option"} - {{ option | toUpper }} - %p{"v-if" => 'transportType === "tcp"'} - Nothing to configure - %template(v-else) - %template{"v-for" => "option in tlsOptions"} - %config-field{"v-bind:plugin-type" => "pluginType", - "v-bind:option" => "option"} +%script{type: "text/x-template", id: "vue-transport-config"} + .form-group.card.card-body.bg-light + %h4 + Transport + .form-group + %select{"class" => "form-control", + "v-model" => "transportType", + "v-on:change" => "onChange"} + %option{"v-for" => "option in options", + "v-bind:value" => "option", + "v-bind:selected" => "transportType === option"} + {{ option | toUpper }} + %p{"v-if" => 'transportType === "tcp"'} + Nothing to configure + %template(v-else) + %template{"v-for" => "option in tlsOptions"} + %config-field{"v-bind:plugin-type" => "pluginType", + "v-bind:option" => "option"} From a5300c022b61ccbeb9ab67241d628d506632be35 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 15:19:33 +0900 Subject: [PATCH 19/21] Add buffer section to out_forward form Signed-off-by: Kenji Okimoto --- app/javascript/packs/out_forward_setting.js | 14 ++++++++++++++ .../fluentd/settings/out_forward/_form.html.haml | 2 +- .../shared/vue/_out_forward_setting.html.haml | 13 +++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 app/javascript/packs/out_forward_setting.js create mode 100644 app/views/shared/vue/_out_forward_setting.html.haml diff --git a/app/javascript/packs/out_forward_setting.js b/app/javascript/packs/out_forward_setting.js new file mode 100644 index 0000000..98b3546 --- /dev/null +++ b/app/javascript/packs/out_forward_setting.js @@ -0,0 +1,14 @@ +'use strict' + +import TransportConfig from "./transport_config" +import OwnedPluginForm from "./owned_plugin_form" + +$(document).ready(() => { + new Vue({ + el: "#out-forward-setting", + components: { + "transport-config": TransportConfig, + "owned-plugin-form": OwnedPluginForm, + } + }) +}) diff --git a/app/views/fluentd/settings/out_forward/_form.html.haml b/app/views/fluentd/settings/out_forward/_form.html.haml index 5dfe67e..35b5220 100644 --- a/app/views/fluentd/settings/out_forward/_form.html.haml +++ b/app/views/fluentd/settings/out_forward/_form.html.haml @@ -5,7 +5,7 @@ - setting.common_options.each do |key| = f.field(key) - = render "shared/vue/transport_config", setting: setting + = render "shared/vue/out_forward_setting", setting: setting .card.card-body.bg-light %h4{"data-toggle" => "collapse", "href" => "#advanced-setting"} diff --git a/app/views/shared/vue/_out_forward_setting.html.haml b/app/views/shared/vue/_out_forward_setting.html.haml new file mode 100644 index 0000000..bb43462 --- /dev/null +++ b/app/views/shared/vue/_out_forward_setting.html.haml @@ -0,0 +1,13 @@ +- add_javascript_pack_tag("out_forward_setting") + += render "shared/vue/owned_plugin_form" += render "shared/vue/transport_config" + +#out-forward-setting + %owned-plugin-form{"v-bind:id" => "'buffer-section'", + "v-bind:options-json" => "'#{Fluent::Plugin::BUFFER_REGISTRY.map.keys.to_json}'", + "v-bind:initial-plugin-name" => "'#{setting.buffer_type}'", + "v-bind:plugin-type" => "'buffer'", + "v-bind:plugin-label" => "'Buffer'"} + %transport-config{"v-bind:plugin-type" => "'#{setting.plugin_type}'", + "v-bind:plugin-name" => "'#{setting.plugin_name}'"} From 771b594f9837cd666a67fe61c0b3a1c92da43adf Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 15:24:50 +0900 Subject: [PATCH 20/21] Extract html class Signed-off-by: Kenji Okimoto --- app/form_builders/fluentd_form_builder.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/form_builders/fluentd_form_builder.rb b/app/form_builders/fluentd_form_builder.rb index 0bcb91a..ace04f6 100644 --- a/app/form_builders/fluentd_form_builder.rb +++ b/app/form_builders/fluentd_form_builder.rb @@ -58,9 +58,10 @@ class FluentdFormBuilder < ActionView::Helpers::FormBuilder section_class = object.class._sections[key] children = object.__send__(key) || { "0" => {} } html = "" + html_class = "js-nested-column #{section_class.multi ? "js-multiple" : ""}" children.each do |index, child| - html << content_tag("div", class: "js-nested-column #{section_class.multi ? "js-multiple" : ""}") do + html << content_tag("div", class: html_class) do _html = "" _html << append_and_remove_links if section_class.multi _html << label(key, nil, data: { toggle: "tooltip", placement: "right" }, title: object.desc(key)) From 7877e6565dca747f8472e500cda7e05fd1e5f2b7 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 15:32:03 +0900 Subject: [PATCH 21/21] Remove undefined CSS class Signed-off-by: Kenji Okimoto --- app/form_builders/fluentd_form_builder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/form_builders/fluentd_form_builder.rb b/app/form_builders/fluentd_form_builder.rb index ace04f6..a135be2 100644 --- a/app/form_builders/fluentd_form_builder.rb +++ b/app/form_builders/fluentd_form_builder.rb @@ -84,8 +84,8 @@ class FluentdFormBuilder < ActionView::Helpers::FormBuilder end def append_and_remove_links - %Q!#{icon('fa-plus')} ! + - %Q! ! + %Q!#{icon('fa-plus')} ! + + %Q! ! end def icon(classes, inner=nil)