Class: Chef::Knife::VaultCreate
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::VaultCreate
- Includes:
- VaultBase
- Defined in:
- lib/chef/knife/vault_create.rb
Instance Method Summary collapse
Methods included from VaultBase
#configure_chef, included, #show_usage
Instance Method Details
#run ⇒ Object
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/chef/knife/vault_create.rb', line 61 def run vault = @name_args[0] item = @name_args[1] values = @name_args[2] search = config[:search] json_file = config[:json] file = config[:file] keys_mode = config[:keys_mode] set_mode(config[:vault_mode]) if vault && item && (search || clients || admins) begin vault_item = ChefVault::Item.load(vault, item) raise ChefVault::Exceptions::ItemAlreadyExists, "#{vault_item.data_bag}/#{vault_item.id} already exists, "\ "use 'knife vault remove' 'knife vault update' "\ "or 'knife vault edit' to make changes." rescue ChefVault::Exceptions::KeysNotFound, ChefVault::Exceptions::ItemNotFound, Chef::Exceptions::InvalidDataBagItemID vault_item = ChefVault::Item.new(vault, item) if values || json_file || file merge_values(values, json_file).each do |key, value| vault_item[key] = value end if file vault_item["file-name"] = File.basename(file) vault_item["file-content"] = File.open(file, &:read) end else vault_json = edit_hash({}) vault_json.each do |key, value| vault_item[key] = value end end vault_item.search(search) if search vault_item.clients if search vault_item.clients(clients) if clients vault_item.admins(admins) if admins vault_item.keys.mode(keys_mode) if keys_mode vault_item.save end else show_usage end end |