Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

UGH #6

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions lib/kitchen-shopify-provisioner/databag_mash_monkeypatch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# because https://github.com/chef/chef-zero/pull/147/files will never get merged
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you think that PR will never get merged?


module ChefZero
module ChefData
class DataNormalizer
def self.normalize_data_bag_item(data_bag_item, data_bag_name, id, method)
if method == 'DELETE'
# TODO SERIOUSLY, WHO DOES THIS MANY EXCEPTIONS IN THEIR INTERFACE
unless data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data']
data_bag_item['id'] ||= id
data_bag_item = { 'raw_data' => data_bag_item }
data_bag_item['chef_type'] ||= 'data_bag_item'
data_bag_item['json_class'] ||= 'Chef::DataBagItem'
data_bag_item['data_bag'] ||= data_bag_name
data_bag_item['name'] ||= "data_bag_item_#{data_bag_name}_#{id}"
end
else
# If it's not already wrapped with raw_data, wrap it.
if data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data']
# data_bag_item = data_bag_item['raw_data']
end
# Argh. We don't do this on GET, but we do on PUT and POST????
if %w(PUT POST).include?(method)
data_bag_item['chef_type'] ||= 'data_bag_item'
data_bag_item['data_bag'] ||= data_bag_name
end
data_bag_item['id'] ||= id
end
data_bag_item
end
end
end
end
8 changes: 7 additions & 1 deletion lib/kitchen/provisioner/chef_zero_shopify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
require 'chef/encrypted_data_bag_item'
require 'chef/encrypted_data_bag_item/check_encrypted'

# UGH
require 'kitchen-shopify-provisioner/databag_mash_monkeypatch'

module Kitchen
module Provisioner
# We'll sneak some code in before the default chef zero provisioner runs
Expand Down Expand Up @@ -62,7 +65,10 @@ def decrypt_data_bags(config, tmpdir)
files.each do |item_file|
raw_data = ::Chef::JSONCompat.from_json(IO.read(item_file))
raw_data = ::Chef::EncryptedDataBagItem.new(raw_data, secret).to_hash if encrypted_data_bag?(raw_data)
json_dump = ::Chef::JSONCompat.to_json_pretty(raw_data)
item = ::Chef::DataBagItem.new
item.data_bag(bag_name)
item.raw_data = raw_data
json_dump = ::Chef::JSONCompat.to_json_pretty(item)
plain_file = File.join(plain_data_bags, bag_name, File.basename(item_file))
FileUtils.mkdir_p(File.dirname(plain_file))
File.write(plain_file, json_dump)
Expand Down