Skip to content

Instantly share code, notes, and snippets.

@thomsh
Created July 15, 2020 09:41
Show Gist options
  • Save thomsh/5df208029c5707928d210d3e01907883 to your computer and use it in GitHub Desktop.
Save thomsh/5df208029c5707928d210d3e01907883 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: encrypt_databag.rb /path/to/plain_json_data_bag KEY"
abort
end
plaindata_path = ARGV[0]
secret = ARGV[1]
if secret.length < 12
puts "secret key too small : size=#{secret.length}"
abort
end
#secret = Chef::EncryptedDataBagItem.load_secret(ARGV[1])
plain_data = JSON.parse(File.read(plaindata_path))
encrypted_data = Chef::EncryptedDataBagItem.encrypt_data_bag_item(plain_data, secret)
puts JSON.pretty_generate(encrypted_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment