<commit_before>require 'sinatra/base'
require 'sinatra-activerecord'

require 'supervisor'

module MagistrateMonitor
  class Server < Sinatra::Base
    dir = File.dirname(File.expand_path(__FILE__))

    set :views,  "#{dir}/views"
    set :public, "#{dir}/public"
    set :static, true
        
    get '/', :provides => 'html' do
      @supervisors = Supervisor.order('name ASC').all
      normalize_status_data!
      
      erb :index
    end
    
    get '/supervisors/:name' do
      @supervisor = Supervisor.find_by_name params[:name]
      erb :show
    end
    
    # Responds with the latest databag instructions for the supervisor<commit_msg>Added basic http auth when config file is present<commit_after>require 'sinatra/base'
require 'sinatra-activerecord'

require 'supervisor'

module MagistrateMonitor
  class Server < Sinatra::Base
    dir = File.dirname(File.expand_path(__FILE__))

    set :views,  "#{dir}/views"
    set :public, "#{dir}/public"
    set :static, true
    
    set :basic_auth_credentials, lambda {
      config_file = File.join('config', 'magistrate.yml')
      if File.exist?( config_file )
        config = File.open(config_file) { |file| YAML.load(file) }
        if config['http_username'] && config['http_password']
          [config['http_username'], config['http_password']]
        end
      end
    }
    
    if basic_auth_credentials
      use Rack::Auth::Basic do |username, password|
        [username, password] == basic_auth_credentials
      end
    end
    
    get '/', :provides => 'html' do
      @supervisors = Supervisor.order('name ASC').all
      normalize_status_data!
      
      erb :index
    end
    
    get '/supervisors/:name' do
      @supervisor = Supervisor.find_by_name params[:name]
      erb :show
    end
    
    # Responds with the latest databag instructions for the supervisor
{'fraction_non_alphanumeric': 0.1098546042003231, 'fraction_numerical': 0.0, 'mean_word_length': 2.846790890269151, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1299231', 'n_tokens_mistral': 587, 'n_tokens_neox': 568, 'n_words': 141}