Class: Chef::Knife::VaultShow
Instance Method Summary
collapse
Methods included from VaultBase
#configure_chef, included, #show_usage
Instance Method Details
#print_keys(vault) ⇒ Object
90
91
92
93
94
95
96
97
|
# File 'lib/chef/knife/vault_show.rb', line 90
def print_keys(vault)
if bag_is_vault?(vault)
bag = Chef::DataBag.load(vault)
output split_vault_keys(bag)[1]
else
output "data bag #{vault} is not a chef-vault"
end
end
|
#print_values(vault, item, values) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/chef/knife/vault_show.rb', line 51
def print_values(vault, item, values)
vault_item = ChefVault::Item.load(vault, item)
= {}
if config[:print]
case config[:print]
when "search"
["search_query"] = vault_item.search
when "admins"
["admins"] = vault_item.get_admins
when "clients"
["clients"] = vault_item.get_clients
when "all"
["search_query"] = vault_item.search
["admins"] = vault_item.get_admins
["clients"] = vault_item.get_clients
end
end
if values
included_values = %w{id}
values.split(",").each do |value|
value.strip! included_values << value
end
filtered_data = Hash[vault_item.raw_data.find_all { |k, _| included_values.include?(k) }]
output_data = filtered_data.merge()
else
all_data = vault_item.raw_data
output_data = all_data.merge()
end
output(output_data)
end
|
#run ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/chef/knife/vault_show.rb', line 35
def run
vault = @name_args[0]
item = @name_args[1]
values = @name_args[2]
if vault && item
set_mode(config[:vault_mode])
print_values(vault, item, values)
elsif vault
set_mode(config[:vault_mode])
print_keys(vault)
else
show_usage
end
end
|