Class: Legion::CLI::Doctor::ApiBindCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/cli/doctor/api_bind_check.rb

Constant Summary collapse

LOOPBACK_BINDS =
%w[127.0.0.1 ::1 localhost].freeze

Instance Method Summary collapse

Instance Method Details

#nameObject



9
10
11
# File 'lib/legion/cli/doctor/api_bind_check.rb', line 9

def name
  'API bind address'
end

#runObject



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
# File 'lib/legion/cli/doctor/api_bind_check.rb', line 13

def run
  return skip_result unless defined?(Legion::Settings)

  api_settings = Legion::Settings[:api]
  return skip_result unless api_settings.is_a?(Hash)

  bind = api_settings[:bind]
  return skip_result if bind.nil?

  if LOOPBACK_BINDS.include?(bind)
    Result.new(
      name:    name,
      status:  :pass,
      message: "API bound to loopback (#{bind})"
    )
  elsif api_settings.dig(:auth, :enabled) == true
    Result.new(
      name:    name,
      status:  :pass,
      message: "API bound to #{bind} with auth enabled"
    )
  else
    Result.new(
      name:         name,
      status:       :warn,
      message:      "API bound to non-loopback address (#{bind}) without explicit auth configuration",
      prescription: "Set api.auth.enabled: true or change api.bind to '127.0.0.1'"
    )
  end
end