Class: Chef::Knife::Bootstrap::ChefVaultHandler
- Inherits:
-
Object
- Object
- Chef::Knife::Bootstrap::ChefVaultHandler
- Defined in:
- lib/chef/knife/bootstrap/chef_vault_handler.rb
Instance Attribute Summary collapse
-
#client ⇒ Chef::ApiClient
readonly
Vault client.
-
#knife_config ⇒ Hash
Knife merged config, typically @config.
-
#ui ⇒ Chef::Knife::UI
Ui object for output.
Instance Method Summary collapse
-
#doing_chef_vault? ⇒ Boolean
If we’ve got chef vault options to act on or not.
-
#initialize(knife_config: {}, ui: nil) ⇒ ChefVaultHandler
constructor
A new instance of ChefVaultHandler.
-
#load_chef_bootstrap_vault_item(vault, item) ⇒ ChefVault::Item
Hook to stub out ChefVault.
-
#run(client) ⇒ Object
Updates the chef vault items for the newly created client.
-
#update_bootstrap_vault_json! ⇒ Object
Iterate through all the vault items to update.
Constructor Details
#initialize(knife_config: {}, ui: nil) ⇒ ChefVaultHandler
Returns a new instance of ChefVaultHandler.
34 35 36 37 |
# File 'lib/chef/knife/bootstrap/chef_vault_handler.rb', line 34 def initialize(knife_config: {}, ui: nil) @knife_config = knife_config @ui = ui end |
Instance Attribute Details
#client ⇒ Chef::ApiClient (readonly)
Returns vault client.
30 31 32 |
# File 'lib/chef/knife/bootstrap/chef_vault_handler.rb', line 30 def client @client end |
#knife_config ⇒ Hash
Returns knife merged config, typically @config.
24 25 26 |
# File 'lib/chef/knife/bootstrap/chef_vault_handler.rb', line 24 def knife_config @knife_config end |
#ui ⇒ Chef::Knife::UI
Returns ui object for output.
27 28 29 |
# File 'lib/chef/knife/bootstrap/chef_vault_handler.rb', line 27 def ui @ui end |
Instance Method Details
#doing_chef_vault? ⇒ Boolean
Returns if we’ve got chef vault options to act on or not.
69 70 71 |
# File 'lib/chef/knife/bootstrap/chef_vault_handler.rb', line 69 def doing_chef_vault? !!(bootstrap_vault_json || bootstrap_vault_file || bootstrap_vault_item) end |
#load_chef_bootstrap_vault_item(vault, item) ⇒ ChefVault::Item
Hook to stub out ChefVault
133 134 135 |
# File 'lib/chef/knife/bootstrap/chef_vault_handler.rb', line 133 def load_chef_bootstrap_vault_item(vault, item) ChefVault::Item.load(vault, item) end |
#run(client) ⇒ Object
Updates the chef vault items for the newly created client.
42 43 44 45 46 47 48 49 50 |
# File 'lib/chef/knife/bootstrap/chef_vault_handler.rb', line 42 def run(client) return unless doing_chef_vault? sanity_check @client = client update_bootstrap_vault_json! end |
#update_bootstrap_vault_json! ⇒ Object
Iterate through all the vault items to update. Items may be either a String or an Array of Strings:
"vault1": "item",
"vault2": [ "item1", "item2", "item2" ]
60 61 62 63 64 65 66 |
# File 'lib/chef/knife/bootstrap/chef_vault_handler.rb', line 60 def update_bootstrap_vault_json! vault_json.each do |vault, items| [ items ].flatten.each do |item| update_vault(vault, item) end end end |