<commit_before>require 'inifile'
require 'csv'

class Chef
module Provisioning
module FogDriver
  module Providers
    class AWS
      # Reads in a credentials file in Amazon's download format and presents the credentials to you
      class Credentials
        def initialize
          @credentials = {}
        end

        include Enumerable

        def default
          if @credentials.size == 0
            raise "No credentials loaded!  Do you have one of ~/.aws/credentials or ~/.aws/config?"
          end
          @credentials[ENV['AWS_DEFAULT_PROFILE'] || 'default'] || @credentials.first[1]
        end

        def keys
          @credentials.keys
        end

        def [](name)
          @credentials[name]
        end

        def each(&block)
          @credentials.each(&block)
        end

        def load_ini(credentials_ini_file)
          inifile = IniFile.load(File.expand_path(credentials_ini_file))
          if inifile
            inifile.each_section do |section|
              if section =~ /^\s*profile\s+(.+)$/ || section =~ /^\s*(default)\s*/
                profile_name = $1.strip
                profile = inifile[section].inject({}) do |result, pair|
                  result[pair[0].to_sym] = pair[1]
                  result
                end
                profile[:name] = profile_name
                @credentials[profile_name] = (@credentials[profile_name].nil? && profile) ||
                    @credentials[profile_name].merge(profile)
              end
            end
          else
            # Get it to throw an error
            File.open(File.expand_path(credentials_ini_file)) do
            end
          end
        end

        def load_csv(credentials_csv_file)
          CSV.new(File.open(credentials_csv_file), :headers => :first_row).each do |row|
            @credentials[row['User Name']] = {
              :name => row['<NAME>'],
              :user_name => row['<NAME>'],
              :aws_access_key_id => row['Access Key Id'],
              :aws_secret_access_key => row['Secret Access Key']
            }
          end
        end

        def load_default
          unless ENV['AWS_CONFIG_FILE']
            path = ['~/.aws/credentials', '~/.aws/config']
          else
            path = [ENV['AWS_CONFIG_FILE']]
          end

          path.each do |file|
            if File.file?(File.expand_path(file))
              load_ini(file)
            end
          end
        end

        def self.method_missing(name, *args, &block)
          singleton.send(name, *args, &block)
        end

        def self.singleton
          @aws_credentials ||= Credentials.new
        end
      end
    end
  end
end
end
end
<commit_msg>Fix the merge order of the credentials files.<commit_after>require 'inifile'
require 'csv'

class Chef
module Provisioning
module FogDriver
  module Providers
    class AWS
      # Reads in a credentials file in Amazon's download format and presents the credentials to you
      class Credentials
        def initialize
          @credentials = {}
        end

        include Enumerable

        def default
          if @credentials.size == 0
            raise "No credentials loaded!  Do you have one of ~/.aws/credentials or ~/.aws/config?"
          end
          @credentials[ENV['AWS_DEFAULT_PROFILE'] || 'default'] || @credentials.first[1]
        end

        def keys
          @credentials.keys
        end

        def [](name)
          @credentials[name]
        end

        def each(&block)
          @credentials.each(&block)
        end

        def load_ini(credentials_ini_file)
          inifile = IniFile.load(File.expand_path(credentials_ini_file))
          if inifile
            inifile.each_section do |section|
              if section =~ /^\s*profile\s+(.+)$/ || section =~ /^\s*(default)\s*/
                profile_name = $1.strip
                profile = inifile[section].inject({}) do |result, pair|
                  result[pair[0].to_sym] = pair[1]
                  result
                end
                profile[:name] = profile_name
                @credentials[profile_name] = (@credentials[profile_name].nil? && profile) ||
                    @credentials[profile_name].merge(profile)
              end
            end
          else
            # Get it to throw an error
            File.open(File.expand_path(credentials_ini_file)) do
            end
          end
        end

        def load_csv(credentials_csv_file)
          CSV.new(File.open(credentials_csv_file), :headers => :first_row).each do |row|
            @credentials[row['User Name']] = {
              :name => row['<NAME>'],
              :user_name => row['<NAME>'],
              :aws_access_key_id => row['Access Key Id'],
              :aws_secret_access_key => row['Secret Access Key']
            }
          end
        end

        def load_default
          unless ENV['AWS_CONFIG_FILE']
            path = ['~/.aws/config', '~/.aws/credentials']
          else
            path = [ENV['AWS_CONFIG_FILE']]
          end

          path.each do |file|
            if File.file?(File.expand_path(file))
              load_ini(file)
            end
          end
        end

        def self.method_missing(name, *args, &block)
          singleton.send(name, *args, &block)
        end

        def self.singleton
          @aws_credentials ||= Credentials.new
        end
      end
    end
  end
end
end
end

{'fraction_non_alphanumeric': 0.10169179845531445, 'fraction_numerical': 0.0018389113644722325, 'mean_word_length': 1.6011477761836441, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1370892', 'n_tokens_mistral': 1558, 'n_tokens_neox': 1507, 'n_words': 363}