Class: Chef::Knife::DataBagFromFile
Instance Attribute Summary
Attributes inherited from Chef::Knife
#name_args, #ui
Instance Method Summary
collapse
Methods inherited from Chef::Knife
#api_key, category, common_name, #configure_chef, #create_object, #delete_object, deps, #format_rest_error, guess_category, #highlight_config_error, #humanize_exception, #humanize_http_exception, inherited, #initialize, list_commands, load_commands, load_deps, msg, #noauth_rest, #parse_options, #read_config_file, reset_subcommands!, #rest, run, #run_with_pretty_exceptions, #server_url, #show_usage, snake_case_name, subcommand_category, subcommand_class_from, subcommand_loader, subcommands, subcommands_by_category, ui, unnamed?, #username
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
Constructor Details
This class inherits a constructor from Chef::Knife
Instance Method Details
#read_secret ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/chef/knife/data_bag_from_file.rb', line 46
def read_secret
if config[:secret]
config[:secret]
else
Chef::EncryptedDataBagItem.load_secret(config[:secret_file])
end
end
|
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/chef/knife/data_bag_from_file.rb', line 66
def run
if @name_args.size != 2
stdout.puts opt_parser
exit(1)
end
@data_bag, @item_path = @name_args[0], @name_args[1]
item = loader.load_from("data_bags", @data_bag, @item_path)
item = if use_encryption
secret = read_secret
Chef::EncryptedDataBagItem.encrypt_data_bag_item(item, secret)
else
item
end
dbag = Chef::DataBagItem.new
dbag.data_bag(@name_args[0])
dbag.raw_data = item
dbag.save
ui.info("Updated data_bag_item[#{dbag.data_bag}::#{dbag.id}]")
end
|
#use_encryption ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/chef/knife/data_bag_from_file.rb', line 54
def use_encryption
if config[:secret] && config[:secret_file]
stdout.puts "please specify only one of --secret, --secret-file"
exit(1)
end
config[:secret] || config[:secret_file]
end
|