<commit_before>class Fluentd::SettingsController < ApplicationController
  before_action :login_required
  before_action :find_fluentd

  def show
    @config = File.read(@fluentd.agent.config_file) # TODO
  end

  def edit
    @config = File.read(@fluentd.agent.config_file) # TODO
  end

  def  update
    File.open(@fluentd.agent.config_file, "w") do |f| # TODO: should update by agent class
      f.write params[:config]
    end
    @fluentd.agent.restart if @fluentd.agent.running?
    redirect_to fluentd_setting_path(@fluentd)
  end

  def in_tail_after_file_choose
    @setting = Fluentd::Setting::InTail.new({
      :path => params[:path],
      :tag => nil,
    })
  end

  def in_tail_after_format
    @setting = Fluentd::Setting::InTail.new(setting_params)
  end

  def in_tail_confirm
    @setting = Fluentd::Setting::InTail.new(setting_params)
    if params[:back]
      return render :in_tail_after_file_choose
    end
  end

  def in_tail_finish
    @setting = Fluentd::Setting::InTail.new(setting_params)
    if params[:back]
      return render :in_tail_after_format
    end

    unless @setting.valid?
      return render "in_tail_after_format"
    end

    if @fluentd.agent.configuration.to_s.include?(@setting.to_conf.strip)
      @setting.errors.add(:base, :duplicated_conf)
      return render "in_tail_after_format"
    end

    File.open(@fluentd.agent.config_file, "a") do |f| # TODO: should update by agent class
      f.write "\n"
      f.write @setting.to_conf
    end
    @fluentd.agent.restart if @fluentd.agent.running?
    redirect_to fluentd_setting_path(@fluentd)
  end

  private

  def setting_params
    {
      :pos_file => "/tmp/fluentd-#{@fluentd.id}.pos",
    }.merge params.require(:setting).permit(:path, :format, *Fluentd::Setting::InTail.known_formats, :tag, :rotate_wait, :pos_file, :read_from_head, :refresh_interval)
  end
end<commit_msg>pos_file default value to be safety<commit_after>class Fluentd::SettingsController < ApplicationController
  before_action :login_required
  before_action :find_fluentd

  def show
    @config = File.read(@fluentd.agent.config_file) # TODO
  end

  def edit
    @config = File.read(@fluentd.agent.config_file) # TODO
  end

  def  update
    File.open(@fluentd.agent.config_file, "w") do |f| # TODO: should update by agent class
      f.write params[:config]
    end
    @fluentd.agent.restart if @fluentd.agent.running?
    redirect_to fluentd_setting_path(@fluentd)
  end

  def in_tail_after_file_choose
    @setting = Fluentd::Setting::InTail.new({
      :path => params[:path],
      :tag => nil,
    })
  end

  def in_tail_after_format
    @setting = Fluentd::Setting::InTail.new(setting_params)
  end

  def in_tail_confirm
    @setting = Fluentd::Setting::InTail.new(setting_params)
    if params[:back]
      return render :in_tail_after_file_choose
    end
  end

  def in_tail_finish
    @setting = Fluentd::Setting::InTail.new(setting_params)
    if params[:back]
      return render :in_tail_after_format
    end

    unless @setting.valid?
      return render "in_tail_after_format"
    end

    if @fluentd.agent.configuration.to_s.include?(@setting.to_conf.strip)
      @setting.errors.add(:base, :duplicated_conf)
      return render "in_tail_after_format"
    end

    File.open(@fluentd.agent.config_file, "a") do |f| # TODO: should update by agent class
      f.write "\n"
      f.write @setting.to_conf
    end
    @fluentd.agent.restart if @fluentd.agent.running?
    redirect_to fluentd_setting_path(@fluentd)
  end

  private

  def setting_params
    {
      :pos_file => "/tmp/fluentd-#{@fluentd.id}-#{Time.now.to_i}.pos",
    }.merge params.require(:setting).permit(:path, :format, *Fluentd::Setting::InTail.known_formats, :tag, :rotate_wait, :pos_file, :read_from_head, :refresh_interval)
  end
end
{'fraction_non_alphanumeric': 0.11218872870249016, 'fraction_numerical': 0.0, 'mean_word_length': 3.659340659340659, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2485720', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1325, 'n_words': 256}