Sha256: 31ad032c2d71dc547d3810e940e886c84c71938635e17440d6abe6e530331df6

Contents?: true

Size: 1.85 KB

Versions: 45

Compression:

Stored size: 1.85 KB

Contents

require 'chef/chef_fs/data_handler/data_handler_base'
require 'chef/data_bag_item'

class Chef
  module ChefFS
    module DataHandler
      class DataBagItemDataHandler < DataHandlerBase
        def normalize(data_bag_item, entry)
          # If it's wrapped with raw_data, unwrap it.
          if data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data']
            data_bag_item = data_bag_item['raw_data']
          end
          # chef_type and data_bag come back in PUT and POST results, but we don't
          # use those in knife-essentials.
          normalize_hash(data_bag_item, {
            'id' => remove_dot_json(entry.name)
          })
        end

        def normalize_for_post(data_bag_item, entry)
          if data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data']
            data_bag_item = data_bag_item['raw_data']
          end
          {
            "name" => "data_bag_item_#{entry.parent.name}_#{remove_dot_json(entry.name)}",
            "json_class" => "Chef::DataBagItem",
            "chef_type" => "data_bag_item",
            "data_bag" => entry.parent.name,
            "raw_data" => normalize(data_bag_item, entry)
          }
        end

        def normalize_for_put(data_bag_item, entry)
          normalize_for_post(data_bag_item, entry)
        end

        def preserve_key?(key)
          return key == 'id'
        end

        def chef_class
          Chef::DataBagItem
        end

        def verify_integrity(object, entry, &on_error)
          base_name = remove_dot_json(entry.name)
          if object['raw_data']['id'] != base_name
            on_error.call("ID in #{entry.path_for_printing} must be '#{base_name}' (is '#{object['raw_data']['id']}')")
          end
        end

        # Data bags do not support .rb files (or if they do, it's undocumented)
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
chef-12.6.0 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.6.0-universal-mingw32 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.5.1-universal-mingw32 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.5.1 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.4.3-universal-mingw32 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.4.3 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.4.2-universal-mingw32 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.4.2 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.5.0.alpha.1 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.4.1-universal-mingw32 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.4.1 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.4.0 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.4.0-universal-mingw32 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.4.0.rc.2 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.4.0.rc.2-universal-mingw32 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.4.0.rc.0 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.4.0.rc.0-universal-mingw32 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.3.0-x86-mingw32 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.3.0 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb
chef-12.3.0.rc.0-x86-mingw32 lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb