用红宝石内的刀加密数据袋 [英] encrypt data bag with knife from inside ruby
本文介绍了用红宝石内的刀加密数据袋的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在加密数据包的时刻,我必须做:
系统刀数据包从文件TemporaryEncrypting \#{enc_file_path} \ - 安全文件#{Secret_Key_Path}
这不行,因为刀找不到配置文件,我似乎无法得到它读取 C:\chef
中的一个。
如何在ruby内部执行此操作? p>
解决方案
我制定了如何在ruby内进行加密,只需使用以下代码:
pre>
需要厨师/刀
#require'chef / encrypted_data_bag_item'#你需要在厨师版本12中做到这一点,他们把它从刀中移出来它是自己的部分
require'json'
secret = Chef :: EncryptedDataBagItem.load_secret Secret_Key_Path
to_encrypt = JSON.parse(json_to_encrypt)
encrypted_data = Chef :: EncryptedDataBagItem.encrypt_data_bag_item to_encrypt,secret
从这个问题
At the moment to encrypt a data bag, I have to do :
system "knife data bag from file TemporaryEncrypting \"#{enc_file_path}\" --secret-file #{Secret_Key_Path}"
and that doesn't work because knife can't find a config file and I can't seem to get it read the one in C:\chef
.
How do I do this from within ruby?
解决方案
I worked out how to encrypt inside of ruby, just use this code:
require 'chef/knife'
#require 'chef/encrypted_data_bag_item' #you need to do this in chef version 12, they've moved it out of knife and into it's own section
require 'json'
secret = Chef::EncryptedDataBagItem.load_secret Secret_Key_Path
to_encrypt = JSON.parse(json_to_encrypt)
encrypted_data = Chef::EncryptedDataBagItem.encrypt_data_bag_item to_encrypt, secret
Answer achieved with information from the answer to this question
这篇关于用红宝石内的刀加密数据袋的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文