<commit_before>require 'dsi_deploy'
require 'net/http'
require 'digest'

# rails_config source - compatible with Settings.add_source!()
class DSI::Deploy::ConfigSource
  def initialize(settings)
    config = settings.dsi_deploy.to_h
    name = config.delete(:name)
    config[:environment] ||= Rails.env
    config[:domain] ||= (Settings[:hostname] || Settings[:host])
    @deploy = DSI::Deploy.new(name, config)
  end
  # This is the only interface rails_config expects -s hould return a Hash-like
  def load
    # TODO: turn into some sort of lazy lookup
    {
      'db' => {
        'password' => <PASSWORD>,
        'host' => self.service(:db).target,
      },
      'redis' => {
        'url' => "redis://#{self.service(:redis).target}:#{self.service(:redis).port}"
      }
    }
  end
  EC2_METADATA_URI = URI('http://169.254.169.254/latest/user-data')
  def user_data
    @user_data ||= begin
      key, value = Net::HTTP.get(EC2_METADATA_URI).split('=', 2)
      # Single value only for now:
      {key.to_sym => value}
    end
  end

  def db_password
    Digest::MD5.hexdigest("#{user_data[:secret]}:db")
  end<commit_msg>ensure deploy config settings are always the lowest priority (though not in the cleanest way exactly)<commit_after>require 'dsi_deploy'
require 'net/http'
require 'digest'

# rails_config source - compatible with Settings.add_source!()
class DSI::Deploy::ConfigSource
  def initialize(settings)
    config = settings.dsi_deploy.to_h
    name = config.delete(:name)
    config[:environment] ||= Rails.env
    config[:domain] ||= (Settings[:hostname] || Settings[:host])
    @deploy = DSI::Deploy.new(name, config)
    # TODO: find a better way to be LOWEST priority source
    @settings = settings
  end
  # This is the only interface rails_config expects -s hould return a Hash-like
  def load
    # TODO: turn into some sort of lazy lookup
    {
      'db' => {
        'password' => @settings.db.password || <PASSWORD>_password,
        'host' => @settings.db.host || self.service(:db).target,
      },
      'redis' => {
        'url' => @settings.redis.url || "redis://#{self.service(:redis).target}:#{self.service(:redis).port}"
      }
    }
  end
  EC2_METADATA_URI = URI('http://169.254.169.254/latest/user-data')
  def user_data
    @user_data ||= begin
      key, value = Net::HTTP.get(EC2_METADATA_URI).split('=', 2)
      # Single value only for now:
      {key.to_sym => value}
    end
  end

  def db_password
    Digest::MD5.<PASSWORD>("#{user_data[:secret]}:db")
  end
{'fraction_non_alphanumeric': 0.14978148589590784, 'fraction_numerical': 0.012713547874453715, 'mean_word_length': 3.2823129251700682, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1859057', 'n_tokens_mistral': 865, 'n_tokens_neox': 833, 'n_words': 193}