Sha256: 51eea061e21b929878239d073fef4e997a77b07bfcd222a768a12643886f7fb5

Contents?: true

Size: 1.61 KB

Versions: 14

Compression:

Stored size: 1.61 KB

Contents

require "chef/chef_fs/data_handler/data_handler_base"

class Chef
  module ChefFS
    module DataHandler
      class PolicyDataHandler < DataHandlerBase
        def name_and_revision(name)
          # foo-1.0.0 = foo, 1.0.0
          name = remove_dot_json(name)
          if name =~ /^(.*)-([^-]*)$/
            name, revision_id = $1, $2
          end
          revision_id ||= "0.0.0"
          [ name, revision_id ]
        end

        def normalize(policy, entry)
          # foo-1.0.0 = foo, 1.0.0
          name, revision_id = name_and_revision(entry.name)
          defaults = {
            "name" => name,
            "revision_id" => revision_id,
            "run_list" => [],
            "cookbook_locks" => {},
          }
          normalize_hash(policy, defaults)
        end

        # Verify that the JSON hash for this type has a key that matches its name.
        #
        # @param object [Object] JSON hash of the object
        # @param entry [Chef::ChefFS::FileSystem::BaseFSObject] filesystem object we are verifying
        # @yield  [s] callback to handle errors
        # @yieldparam [s<string>] error message
        def verify_integrity(object_data, entry)
          name, revision = name_and_revision(entry.name)
          if object_data["name"] != name
            yield("Object name '#{object_data['name']}' doesn't match entry '#{name}'.")
          end

          if object_data["revision_id"] != revision
            yield("Object revision ID '#{object_data['revision_id']}' doesn't match entry '#{revision}'.")
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
chef-13.12.14-universal-mingw32 lib/chef/chef_fs/data_handler/policy_data_handler.rb
chef-13.12.3-universal-mingw32 lib/chef/chef_fs/data_handler/policy_data_handler.rb
chef-13.11.3-universal-mingw32 lib/chef/chef_fs/data_handler/policy_data_handler.rb
chef-13.10.4-universal-mingw32 lib/chef/chef_fs/data_handler/policy_data_handler.rb
chef-13.10.0-universal-mingw32 lib/chef/chef_fs/data_handler/policy_data_handler.rb
chef-13.9.4-universal-mingw32 lib/chef/chef_fs/data_handler/policy_data_handler.rb
chef-13.9.1-universal-mingw32 lib/chef/chef_fs/data_handler/policy_data_handler.rb
chef-13.8.5-universal-mingw32 lib/chef/chef_fs/data_handler/policy_data_handler.rb
chef-13.8.3-universal-mingw32 lib/chef/chef_fs/data_handler/policy_data_handler.rb
chef-12.22.1 lib/chef/chef_fs/data_handler/policy_data_handler.rb
chef-12.22.1-universal-mingw32 lib/chef/chef_fs/data_handler/policy_data_handler.rb
chef-13.8.0-universal-mingw32 lib/chef/chef_fs/data_handler/policy_data_handler.rb
chef-12.8.1 lib/chef/chef_fs/data_handler/policy_data_handler.rb
chef-12.8.1-universal-mingw32 lib/chef/chef_fs/data_handler/policy_data_handler.rb