<commit_before>require "sinatra/base"
require "travis/config"

module TravisDeployLogs
  def self.config
    @config ||= Travis::Config.load
  end

  class App < Sinatra::Base
    VALID_ENVIRONMENTS = %w[
      production
      com-production
      org-production
      staging
      com-staging
      org-staging
    ]

    configure :production do
      use Rack::Auth::Basic do |username, password|
        username == TravisDeployLogs.config.basic_username && password == TravisDeployLogs.config.basic_password
      end
    end

    get "/heroku/:env/:app/:id" do
      unless VALID_ENVIRONMENTS.include?(params[:env])
        halt 400, "Unknown environment"
      end

      env = params[:env].gsub("-", "_")
      app = params[:app]

      heroku_org = if app =~ /\Apro-/ || env =~ /\Acom/
                     TravisDeployLogs.config.heroku_orgs["com"]
                   else
                     TravisDeployLogs.config.heroku_orgs["org"]
                   end

      heroku_app = TravisDeployLogs.config.heroku_apps[env][app]<commit_msg>Use Rack::Utils.secure_compare for basic auth check<commit_after>require "sinatra/base"
require 'rack/utils'
require "travis/config"

module TravisDeployLogs
  def self.config
    @config ||= Travis::Config.load
  end

  class App < Sinatra::Base
    VALID_ENVIRONMENTS = %w[
      production
      com-production
      org-production
      staging
      com-staging
      org-staging
    ]

    configure :production do
      use Rack::Auth::Basic do |username, password|
        basic_username = TravisDeployLogs.config.basic_username
        basic_password = TravisDeployLogs.config.basic_password
        Rack::Utils.secure_compare(username, basic_username) && Rack::Utils.secure_compare(password, basic_password)
      end
    end

    get "/heroku/:env/:app/:id" do
      unless VALID_ENVIRONMENTS.include?(params[:env])
        halt 400, "Unknown environment"
      end

      env = params[:env].gsub("-", "_")
      app = params[:app]

      heroku_org = if app =~ /\Apro-/ || env =~ /\Acom/
                     TravisDeployLogs.config.heroku_orgs["com"]
                   else
                     TravisDeployLogs.config.heroku_orgs["org"]
                   end

      heroku_app = TravisDeployLogs.config.heroku_apps[env][app]
{'fraction_non_alphanumeric': 0.10747051114023591, 'fraction_numerical': 0.002621231979030144, 'mean_word_length': 2.3577712609970676, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2335983', 'n_tokens_mistral': 738, 'n_tokens_neox': 706, 'n_words': 134}