Class: Karafka::Web::Management::Actions::ExtendBootFile

Inherits:
Base
  • Object
show all
Defined in:
lib/karafka/web/management/actions/extend_boot_file.rb

Overview

Extends the boot file with Web components

Constant Summary collapse

ENABLER_CODE =

Code that is needed in the karafka.rb to connect Web UI to Karafka

'Karafka::Web.enable!'
SETUP_TEMPLATE =

Template with initial Web UI configuration Session secret needs to be set per user and per env

<<~CONFIG.freeze
  Karafka::Web.setup do |config|
    # You may want to set it per ENV. This value was randomly generated.
    config.ui.sessions.secret = '#{SecureRandom.hex(32)}'
  end

  #{ENABLER_CODE}
CONFIG

Instance Method Summary collapse

Instance Method Details

#callObject

Adds needed code



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/karafka/web/management/actions/extend_boot_file.rb', line 24

def call
  # We detect this that way so in case our template or user has enabled as a comment
  # it still adds the template and runs install
  if File.readlines(Karafka.boot_file).any? { |line| line.start_with?(ENABLER_CODE) }
    puts "Web UI #{already} installed."
  else
    puts 'Updating the Karafka boot file...'
    File.open(Karafka.boot_file, 'a') do |f|
      f << "\n#{SETUP_TEMPLATE}\n"
    end
    puts "Karafka boot file #{successfully} updated."
  end
end