Class: Api::ConfigDefinitionsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/api/config_definitions_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/api/config_definitions_controller.rb', line 4

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 = build_options(target, target.common_options)
  advanced_options = build_options(target, target.advanced_options)

  options = {
    type: type,
    name: name,
    commonOptions: common_options,
    advancedOptions: advanced_options
  }

  if type == "input" && ["forward", "syslog"].include?(name)
    transport = target.class._sections[:transport]
    transport_common_options = build_options(transport, target.transport_common_options)
    transport_advanced_options = build_options(transport, target.transport_advanced_options)
    options[:transport] = {
      commonOptions: transport_common_options,
      advancedOptions: transport_advanced_options
    }
  end

  if type == "output" && name == "forward"
    tls_options = build_options(target, target.tls_options)
    options[:tlsOptions] = tls_options
  end

  if target.respond_to?(:aws_credential_options)
    aws_credential_options = build_options(target, target.aws_credential_options)
    options[:awsCredentialOptions] = {
      simple: aws_credential_options
    }
    target.aws_credential_sections.each do |key|
      section = target._sections[key]
      new_key = key.to_s.camelize(:lower).to_sym
      options[:awsCredentialOptions][new_key] = build_options(section, section._types.keys)
    end
  end

  render json: options
end