Class: RailsInformant::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/rails_informant/engine.rb

Constant Summary collapse

MINIMUM_TOKEN_LENGTH =
32

Class Method Summary collapse

Class Method Details

.validate_api_token!Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rails_informant/engine.rb', line 61

def self.validate_api_token!
  return unless RailsInformant.capture_errors

  token = RailsInformant.api_token

  message = if token.nil?
    <<~MSG.squish
      RailsInformant: api_token must be configured when capture_errors is enabled.
      Set it in your initializer: config.api_token = "your-secret-token"
    MSG
  elsif token.length < MINIMUM_TOKEN_LENGTH
    <<~MSG.squish
      RailsInformant: api_token must be at least #{MINIMUM_TOKEN_LENGTH} characters.
      Use SecureRandom.hex(32) or Rails credentials to generate a secure token.
    MSG
  end

  return unless message

  if RailsInformant.server_mode?
    raise message
  else
    Rails.logger&.warn message
  end
end