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(config: {}, knife_config: nil, ui: nil) ⇒ ChefVaultHandler

Returns a new instance of ChefVaultHandler.

Parameters:

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

    knife merged config, typically @config

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

    ui object for output



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

def initialize(config: {}, knife_config: nil, ui: nil)
  @config = config
  unless knife_config.nil?
    @config = knife_config
    Chef.deprecated(:knife_bootstrap_apis, "The knife_config option to the Bootstrap::ClientBuilder object is deprecated and has been renamed to just 'config'")
  end
  @ui = ui
end

Instance Attribute Details

#clientChef::ApiClient (readonly)

Returns vault client.

Returns:

  • (Chef::ApiClient)

    vault client



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

def client
  @client
end

#configHash

Returns knife merged config, typically @config.

Returns:

  • (Hash)

    knife merged config, typically @config



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

def config
  @config
end

#uiChef::Knife::UI

Returns ui object for output.

Returns:



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.

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) ⇒ ChefVault::Item

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

Returns:

  • (ChefVault::Item)

    ChefVault::Item object



135
136
137
# File 'lib/chef/knife/bootstrap/chef_vault_handler.rb', line 135

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.

Parameters:

  • client (Chef::ApiClient)

    vault client



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

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" ]



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