Sha256: 3afc0da176f096eb3a23b70bd24359f38b9ba734fa60563cce6f0531988e1b65

Contents?: true

Size: 1.12 KB

Versions: 11

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module Karafka
  module Web
    module Management
      # Extends the boot file with Web components
      class ExtendBootFile < Base
        # Code that is needed in the `karafka.rb` to connect Web UI to Karafka
        ENABLER_CODE = 'Karafka::Web.enable!'

        # Template with initial Web UI configuration
        # Session secret needs to be set per user and per env
        SETUP_TEMPLATE = <<~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

        # Adds needed code
        def call
          if File.read(Karafka.boot_file).include?(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
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
karafka-web-0.7.10 lib/karafka/web/management/extend_boot_file.rb
karafka-web-0.7.9 lib/karafka/web/management/extend_boot_file.rb
karafka-web-0.7.8 lib/karafka/web/management/extend_boot_file.rb
karafka-web-0.7.7 lib/karafka/web/management/extend_boot_file.rb
karafka-web-0.7.6 lib/karafka/web/management/extend_boot_file.rb
karafka-web-0.7.5 lib/karafka/web/management/extend_boot_file.rb
karafka-web-0.7.4 lib/karafka/web/management/extend_boot_file.rb
karafka-web-0.7.3 lib/karafka/web/management/extend_boot_file.rb
karafka-web-0.7.2 lib/karafka/web/management/extend_boot_file.rb
karafka-web-0.7.1 lib/karafka/web/management/extend_boot_file.rb
karafka-web-0.7.0 lib/karafka/web/management/extend_boot_file.rb