Created
July 15, 2020 09:41
-
-
Save thomsh/5df208029c5707928d210d3e01907883 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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