From b2a73274b81af5b755bcaa40dae1b9e597b69ada Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Wed, 20 Jun 2018 12:03:59 +0900 Subject: [PATCH] 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"}