39
40
41
42
43
44
45
46
47
48
49
50
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
|
# File 'lib/chef/knife/vault_remove.rb', line 39
def run
vault = @name_args[0]
item = @name_args[1]
values = @name_args[2]
search = config[:search]
admins = config[:admins]
clean_unknown_clients = config[:clean_unknown_clients]
json_file = config[:json]
set_mode(config[:vault_mode])
if vault && item && ((values || json_file) || (search || admins))
begin
vault_item = ChefVault::Item.load(vault, item)
remove_items = []
if values || json_file
begin
json = JSON.parse(values)
json.each do |key, _|
remove_items << key
end
rescue JSON::ParserError
remove_items = values.split(",")
end
remove_items.each do |key|
key.strip!
vault_item.remove(key)
end
end
vault_item.clients(search, :delete) if search
vault_item.admins(admins, :delete) if admins
vault_item.rotate_keys!(clean_unknown_clients)
rescue ChefVault::Exceptions::KeysNotFound,
ChefVault::Exceptions::ItemNotFound
raise ChefVault::Exceptions::ItemNotFound,
"#{vault}/#{item} does not exist, "\
"use 'knife vault create' to create."
end
else
show_usage
end
end
|