diff --git a/app/controllers/api/config_definitions_controller.rb b/app/controllers/api/config_definitions_controller.rb new file mode 100644 index 0000000..fe79521 --- /dev/null +++ b/app/controllers/api/config_definitions_controller.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 14d5464..6e3ddeb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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