<commit_before>#
# Author:: <NAME> (<<EMAIL>>)
# Author:: <NAME> (<<EMAIL>>)
#
# Copyright:: Copyright (c) Chef Software Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require_relative "../config"
require_relative "../log"
require_relative "../resource/file"
require_relative "../mixin/checksum"
require_relative "../provider"
require "etc" unless defined?(Etc)
require "fileutils" unless defined?(FileUtils)
require_relative "../scan_access_control"
require_relative "../win32/registry"

class Chef

  class Provider
    class RegistryKey < Chef::Provider
      provides :registry_key

      include Chef::Mixin::Checksum

      WORD_TYPES = %i{dword dword_big_endian qword}.freeze

      def running_on_windows!
        unless ChefUtils.windows?
          raise Chef::Exceptions::Win32NotWindows, "Attempt to manipulate the windows registry on a non-windows node"
        end
      end

      def load_current_resource
        running_on_windows!
        @current_resource ||= Chef::Resource::RegistryKey.new(new_resource.key, run_context)
        current_resource.key(new_resource.key)
        current_resource.architecture(new_resource.architecture)
        current_resource.recursive(new_resource.recursive)
        if registry.key_exists?(new_resource.key)
          current_resource.values(registry.get_values(new_resource.key))
        end
        values_to_hash(current_resource.unscrubbed_values)
        current_resource
      end

      def registry
        @registry ||= Chef::Win32::Registry.new(@run_context, new_resource.architecture)
      end

      def values_to_hash(values)
        if values
          @name_hash = Hash[values.map { |val| [val[:name].downcase, val] }]
        else
          @name_hash = {}
        end
      end

      def key_missing?(values, name)
        values.each do |v|
          return true unless v.key?(name)
        end
        false
      end
<commit_msg>don't pass nil to values in registrykey provider<commit_after>#
# Author:: <NAME> (<<EMAIL>>)
# Author:: <NAME> (<<EMAIL>>)
#
# Copyright:: Copyright (c) Chef Software Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require_relative "../config"
require_relative "../log"
require_relative "../resource/registry_key"
require_relative "../mixin/checksum"
require_relative "../provider"
require "etc" unless defined?(Etc)
require "fileutils" unless defined?(FileUtils)
require_relative "../scan_access_control"
require_relative "../win32/registry"

class Chef

  class Provider
    class RegistryKey < Chef::Provider
      provides :registry_key

      include Chef::Mixin::Checksum

      WORD_TYPES = %i{dword dword_big_endian qword}.freeze

      def running_on_windows!
        unless ChefUtils.windows?
          raise Chef::Exceptions::Win32NotWindows, "Attempt to manipulate the windows registry on a non-windows node"
        end
      end

      def load_current_resource
        running_on_windows!
        @current_resource ||= Chef::Resource::RegistryKey.new(new_resource.key, run_context)
        current_resource.key(new_resource.key)
        current_resource.architecture(new_resource.architecture)
        current_resource.recursive(new_resource.recursive)
        if registry.key_exists?(new_resource.key)
          current_registry_values = registry.get_values(new_resource.key) || []
          current_resource.values(current_registry_values)
        end
        values_to_hash(current_resource.unscrubbed_values)
        current_resource
      end

      def registry
        @registry ||= Chef::Win32::Registry.new(@run_context, new_resource.architecture)
      end

      def values_to_hash(values)
        if values
          @name_hash = Hash[values.map { |val| [val[:name].downcase, val] }]
        else
          @name_hash = {}
        end
      end

      def key_missing?(values, name)
        values.each do |v|
          return true unless v.key?(name)
        end
        false
      end

{'fraction_non_alphanumeric': 0.09442755825734549, 'fraction_numerical': 0.004052684903748734, 'mean_word_length': 3.229648671808055, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6064779', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1371, 'n_words': 397}