<commit_before>module Foreplay
  class Engine
    class Secrets
      class Location
        include Foreplay
        attr_reader :secret_location, :environment

        def initialize(s, e)
          @secret_location = s
          @environment = e
        end

        def secrets
          return @secrets if @secrets

          @secrets = all_secrets[environment]

          case @secrets
          when Hash
            log "Loaded #{secrets.keys.length} secrets"
            @secrets
          when String
            log "Unexpected secrets found: #{@secrets}"
            @secrets = {}
          else
            log 'No secrets found'
            url ? log("Looked in #{url}") : log('No url found')
            log("Secrets #{all_secrets.key?(environment) ? 'has a' : 'has no'} key #{environment}") if all_secrets
            @secrets = {}
          end
        end

        def all_secrets
          return @all_secrets if @all_secrets

          @all_secrets = url ? YAML.load(`#{command}`) : {}
        rescue Psych::SyntaxError => e
          log "Exception caught when loading secrets using this command: #{command}"
          log "#{e.class}: #{e.message}".red
          @all_secrets = {}
        end

        def command
          @command ||= "curl -k -L#{header_string} #{url}".fake_erb
        end

        def header_string<commit_msg>Even more diagnostics for secrets<commit_after>module Foreplay
  class Engine
    class Secrets
      class Location
        include Foreplay
        attr_reader :secret_location, :environment

        def initialize(s, e)
          @secret_location = s
          @environment = e
        end

        def secrets
          return @secrets if @secrets

          @secrets = all_secrets[environment]

          case @secrets
          when Hash
            log "Loaded #{secrets.keys.length} secrets"
            @secrets
          when String
            log "Unexpected secrets found: #{@secrets}"
            @secrets = {}
          else
            log 'No secrets found'
            url ? log("Looked in #{url}") : log('No url found')
            log("Secrets #{all_secrets.key?(environment) ? 'has a' : 'has no'} key #{environment}") if all_secrets
            log all_secrets.inspect if all_secrets
            @secrets = {}
          end
        end

        def all_secrets
          return @all_secrets if @all_secrets

          @all_secrets = url ? YAML.load(`#{command}`) : {}
        rescue Psych::SyntaxError => e
          log "Exception caught when loading secrets from this location: #{url}"
          log "#{e.class}: #{e.message}".red
          @all_secrets = {}
        end

        def command
          @command ||= "curl -k -L#{header_string} #{url}".fake_erb
        end

        def header_string
{'fraction_non_alphanumeric': 0.09765765765765766, 'fraction_numerical': 0.0, 'mean_word_length': 1.7269155206286837, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4318536', 'n_tokens_mistral': 795, 'n_tokens_neox': 749, 'n_words': 223}