Skip to content

Instantly share code, notes, and snippets.

@thomsh
Created July 15, 2020 09:41
Show Gist options
  • Save thomsh/4f33a90bacb155fbba78d1be8b0d954c to your computer and use it in GitHub Desktop.
Save thomsh/4f33a90bacb155fbba78d1be8b0d954c to your computer and use it in GitHub Desktop.
#!/opt/chef-workstation/embedded/bin/ruby
require "chef/encrypted_data_bag_item"
require "json"
if ARGV.length != 2
puts "usage: decrypt_databag.rb /path/to/cipher_json_data_bag KEY"
abort
end
cipherdata_path = ARGV[0]
secret = ARGV[1]
#secret = Chef::EncryptedDataBagItem.load_secret(ARGV[1])
encrypted_data = JSON.parse(File.read(cipherdata_path))
plain_data = Chef::EncryptedDataBagItem.new(encrypted_data, secret).to_hash
puts JSON.pretty_generate(plain_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment