Add Api::ConfigDefinitionsController to fetch plugin definitions

Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
This commit is contained in:
Kenji Okimoto 2018-06-12 12:32:51 +09:00
parent a6d27c0b14
commit 322bfefab3
No known key found for this signature in database
GPG Key ID: F9E3E329A5C5E4A1
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,53 @@
class Api::ConfigDefinitionsController < ApplicationController
before_action :login_required
def index
name = params[:name]
type = params[:type]
prefix = case type
when "input"
"in"
when "output"
"out"
when "filter"
"filter"
when "parse"
"parser"
when "format"
"formatter"
when "parser", "formatter", "buffer", "storage"
type
end
target_class = Fluentd::Setting.const_get("#{prefix}_#{name}".classify)
target = target_class.new
common_options = target.common_options.map do |key|
h = {
name: key,
type: target.column_type(key),
desc: target.desc(key)
}
h[:list] = target.list_of(key) if target.column_type(key) == :enum
h
end
advanced_options = target.advanced_options.map do |key|
h = {
name: key,
type: target.column_type(key),
desc: target.desc(key)
}
h[:list] = target.list_of(key) if target.column_type(key) == :enum
h
end
options = {
type: type,
name: name,
commonOptions: common_options,
advancedOptions: advanced_options
}
render json: options
end
end

View File

@ -129,5 +129,6 @@ Rails.application.routes.draw do
post "grok_to_regexp"
resources :settings, only: [:index, :show, :update, :destroy], defaults: { format: "json" }
resources :config_definitions, only: [:index], defaults: { format: "json" }
end
end