-
-
Save zzondlo/2297843 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
require "chef/config" | |
require "chef/knife" | |
require "chef/log" | |
require "chef/mixin/convert_to_class_name" | |
module DataBagCommon | |
def self.included(base) | |
base.module_eval do | |
def read_secret | |
if locate_config_value(:secret) | |
locate_config_value(:secret) | |
else | |
Chef::EncryptedDataBagItem.load_secret(locate_config_value(:secret_file)) | |
end | |
end | |
def use_encryption | |
if locate_config_value(:secret) && locate_config_value(:secret_file) | |
stdout.puts "please specify only one of --secret, --secret-file" | |
exit(1) | |
end | |
locate_config_value(:secret) || locate_config_value(:secret_file) | |
end | |
end | |
end | |
def locate_config_value(key) | |
key = key.to_sym | |
Chef::Config[:knife][key] || config[key] | |
end | |
end | |
%w[data_bag_create data_bag_show data_bag_edit data_bag_from_file].each do |k| | |
class_name = Chef::Mixin::ConvertToClassName.convert_to_class_name(k) | |
super_class = Chef::Knife.const_get(class_name) | |
eval <<-EOH | |
class #{super_class} | |
include DataBagCommon | |
end | |
EOH | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment