Class: Chef::Knife::Bootstrap::ChefVaultHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/knife/bootstrap/chef_vault_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(knife_config: {}, ui: nil) ⇒ ChefVaultHandler

Returns a new instance of ChefVaultHandler.

Parameters:

  • knife_config (Hash) (defaults to: {})

    knife merged config, typically @config

  • ui (Chef::Knife::UI) (defaults to: nil)

    ui object for output



35
36
37
38
# File 'lib/chef/knife/bootstrap/chef_vault_handler.rb', line 35

def initialize(knife_config: {}, ui: nil)
  @knife_config = knife_config
  @ui           = ui
end

Instance Attribute Details

#knife_configHash

Returns knife merged config, typically @config.

Returns:

  • (Hash)

    knife merged config, typically @config



25
26
27
# File 'lib/chef/knife/bootstrap/chef_vault_handler.rb', line 25

def knife_config
  @knife_config
end

#node_nameString (readonly)

Returns name of the node (technically name of the client).

Returns:

  • (String)

    name of the node (technically name of the client)



31
32
33
# File 'lib/chef/knife/bootstrap/chef_vault_handler.rb', line 31

def node_name
  @node_name
end

#uiChef::Knife::UI

Returns ui object for output.

Returns:



28
29
30
# File 'lib/chef/knife/bootstrap/chef_vault_handler.rb', line 28

def ui
  @ui
end

Instance Method Details

#doing_chef_vault?Boolean

Returns if we’ve got chef vault options to act on or not.

Returns:

  • (Boolean)

    if we’ve got chef vault options to act on or not



73
74
75
# File 'lib/chef/knife/bootstrap/chef_vault_handler.rb', line 73

def doing_chef_vault?
  !!(bootstrap_vault_json || bootstrap_vault_file || bootstrap_vault_item)
end

#load_chef_bootstrap_vault_item(vault, item) ⇒ Object

Hook to stub out ChefVault

Parameters:

  • vault (String)

    name of the chef-vault encrypted data bag

  • item (String)

    name of the chef-vault encrypted item



137
138
139
# File 'lib/chef/knife/bootstrap/chef_vault_handler.rb', line 137

def load_chef_bootstrap_vault_item(vault, item)
  ChefVault::Item.load(vault, item)
end

#run(node_name: nil) ⇒ Object

Updates the chef vault items for the newly created node.

@todo: node_name should be mandatory (ruby 2.0 compat)

Parameters:

  • node_name (String) (defaults to: nil)

    name of the node (technically name of the client)



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/chef/knife/bootstrap/chef_vault_handler.rb', line 44

def run(node_name: nil)
  return unless doing_chef_vault?

  sanity_check

  @node_name = node_name

  ui.info("Updating Chef Vault, waiting for client to be searchable..") while wait_for_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" ]



64
65
66
67
68
69
70
# File 'lib/chef/knife/bootstrap/chef_vault_handler.rb', line 64

def update_bootstrap_vault_json!
  vault_json.each do |vault, items|
    [ items ].flatten.each do |item|
      update_vault(vault, item)
    end
  end
end