Class: Chef::Knife::Bootstrap::ClientBuilder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: {}, knife_config: nil, chef_config: {}, ui: nil) ⇒ ClientBuilder

Returns a new instance of ClientBuilder.

Parameters:

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

    Hash of knife config settings

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

    Hash of chef config settings

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

    UI object for output



42
43
44
45
46
47
48
49
50
# File 'lib/chef/knife/bootstrap/client_builder.rb', line 42

def initialize(config: {}, knife_config: nil, chef_config: {}, 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
  @chef_config = chef_config
  @ui = ui
end

Instance Attribute Details

#chef_configHash

Returns chef config object.

Returns:

  • (Hash)

    chef config object



33
34
35
# File 'lib/chef/knife/bootstrap/client_builder.rb', line 33

def chef_config
  @chef_config
end

#clientChef::ApiClient (readonly)

Returns client saved on run.

Returns:

  • (Chef::ApiClient)

    client saved on run



37
38
39
# File 'lib/chef/knife/bootstrap/client_builder.rb', line 37

def client
  @client
end

#configHash

Returns knife merged config, typically @config.

Returns:

  • (Hash)

    knife merged config, typically @config



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

def config
  @config
end

#uiChef::Knife::UI

Returns ui object for output.

Returns:



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

def ui
  @ui
end

Instance Method Details

#client_pathString

Tempfile to use to write newly created client credentials to.

This method is public so that the knife bootstrapper can read then and pass the value into the handler for chef vault which needs the client cert we create here.

We hang onto the tmpdir as an ivar as well so that it will not get GC’d and removed

Returns:

  • (String)

    path to the generated client.pem



74
75
76
77
78
79
80
# File 'lib/chef/knife/bootstrap/client_builder.rb', line 74

def client_path
  @client_path ||=
    begin
      @tmpdir = Dir.mktmpdir
      File.join(@tmpdir, "#{node_name}.pem")
    end
end

#runObject

Main entry. Prompt the user to clean up any old client or node objects. Then create the new client, then create the new node.



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/chef/knife/bootstrap/client_builder.rb', line 54

def run
  sanity_check

  ui.info("Creating new client for #{node_name}")

  @client = create_client!

  ui.info("Creating new node for #{node_name}")

  create_node!
end