<commit_before>class Chef
  class Credentials
    def initialize(node)
      @node = node
    end

    def credentials_for(lb = "default")
      from_databag(lb) || the_hash[lb] || the_hash[:default]
    end

    private

    def the_hash
      @node[:f5][:credentials]
    end

    def from_databag(databag_name = 'default')
      begin
        search(:f5, "id:#{databag_name}").first
      rescue Net::HTTPServerException
        nil
      end
    end
  end
end<commit_msg>Switch to the databag dsl instead of search<commit_after>class Chef
  class Credentials
    include Chef::DSL::DataQuery

    def initialize(node)
      @node = node
    end

    def credentials_for(lb = "default")
      from_databag(lb) || the_hash[lb] || the_hash[:default]
    end

    private

    def the_hash
      @node[:f5][:credentials]
    end

    def from_databag(databag_name = 'default')
      begin
        bag = data_bag_item(:f5, databag_name)
        bag.default_proc = proc{|h, k| h.key?(k.to_s) ? h[k.to_s] : nil} if bag
        bag
      rescue Net::HTTPServerException
        nil
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10045248868778281, 'fraction_numerical': 0.0036199095022624436, 'mean_word_length': 2.4779874213836477, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1969816', 'n_tokens_mistral': 389, 'n_tokens_neox': 371, 'n_words': 86}