diff options
author | Steven Danna <steve@opscode.com> | 2012-12-17 00:02:50 -0800 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-02-06 09:51:02 -0800 |
commit | 4d45c9fb1bb4ec70c342fee963c3ac9b1134fdba (patch) | |
tree | 8dd524c9ff85c717f1b3727516bad1acd8057821 | |
parent | cd7178d0ed7b7eb1df1063ee03d2946ff7d482f1 (diff) | |
download | chef-4d45c9fb1bb4ec70c342fee963c3ac9b1134fdba.tar.gz |
Update knife-configure to create user rather than client.
Chef 11 now has users as a first-class, authenticatable actors.
knife configure -i
now creates a user rather than a client.
-rw-r--r-- | lib/chef/knife/configure.rb | 29 | ||||
-rw-r--r-- | spec/unit/knife/configure_spec.rb | 49 |
2 files changed, 39 insertions, 39 deletions
diff --git a/lib/chef/knife/configure.rb b/lib/chef/knife/configure.rb index e818239a89..eaf42544c0 100644 --- a/lib/chef/knife/configure.rb +++ b/lib/chef/knife/configure.rb @@ -27,6 +27,7 @@ class Chef deps do require 'ohai' Chef::Knife::ClientCreate.load_deps + Chef::Knife::UserCreate.load_deps end banner "knife configure (options)" @@ -40,15 +41,15 @@ class Chef :short => "-i", :long => "--initial", :boolean => true, - :description => "Create an initial API Client" + :description => "Create an initial API User" option :admin_client_name, :long => "--admin-client-name NAME", - :description => "The existing admin clientname (usually chef-webui)" + :description => "The existing admin clientname (usually admin)" option :admin_client_key, :long => "--admin-client-key PATH", - :description => "The path to the admin client's private key (usually a file named webui.pem)" + :description => "The path to the admin client's private key (usually a file named admin.pem)" option :validation_client_name, :long => "--validation-client-name NAME", @@ -93,13 +94,15 @@ EOH Chef::Config[:chef_server_url] = chef_server Chef::Config[:node_name] = admin_client_name Chef::Config[:client_key] = admin_client_key - client_create = Chef::Knife::ClientCreate.new - client_create.name_args = [ new_client_name ] - client_create.config[:admin] = true - client_create.config[:file] = new_client_key - client_create.config[:yes] = true - client_create.config[:disable_editing] = true - client_create.run + user_create = Chef::Knife::UserCreate.new + user_create.name_args = [ new_client_name ] + user_create.config[:user_password] = config[:user_password] || + ui.ask("Please enter a password for the new user: ") {|q| q.echo = false} + user_create.config[:admin] = true + user_create.config[:file] = new_client_key + user_create.config[:yes] = true + user_create.config[:disable_editing] = true + user_create.run else ui.msg("*****") ui.msg("") @@ -132,9 +135,9 @@ EOH server_name = guess_servername @chef_server = config[:chef_server_url] || ask_question("Please enter the chef server URL: ", :default => "http://#{server_name}:4000") if config[:initial] - @new_client_name = config[:node_name] || ask_question("Please enter a clientname for the new client: ", :default => Etc.getlogin) - @admin_client_name = config[:admin_client_name] || ask_question("Please enter the existing admin clientname: ", :default => 'chef-webui') - @admin_client_key = config[:admin_client_key] || ask_question("Please enter the location of the existing admin client's private key: ", :default => '/etc/chef/webui.pem') + @new_client_name = config[:node_name] || ask_question("Please enter a name for the new user: ", :default => Etc.getlogin) + @admin_client_name = config[:admin_client_name] || ask_question("Please enter the existing admin name: ", :default => 'admin') + @admin_client_key = config[:admin_client_key] || ask_question("Please enter the location of the existing admin's private key: ", :default => '/etc/chef/admin.pem') @admin_client_key = File.expand_path(@admin_client_key) else @new_client_name = config[:node_name] || ask_question("Please enter an existing username or clientname for the API: ", :default => Etc.getlogin) diff --git a/spec/unit/knife/configure_spec.rb b/spec/unit/knife/configure_spec.rb index 692fc5ea15..8d5b51551d 100644 --- a/spec/unit/knife/configure_spec.rb +++ b/spec/unit/knife/configure_spec.rb @@ -41,7 +41,7 @@ describe Chef::Knife::Configure do @knife.config[:initial] = true Etc.stub!(:getlogin).and_return("a-new-user") @knife.ask_user_for_config - @out.string.should match(Regexp.escape("Please enter a clientname for the new client: [a-new-user]")) + @out.string.should match(Regexp.escape("Please enter a name for the new user: [a-new-user]")) @knife.new_client_name.should == Etc.getlogin end @@ -50,7 +50,7 @@ describe Chef::Knife::Configure do @knife.config[:node_name] = 'testnode' Etc.stub!(:getlogin).and_return("a-new-user") @knife.ask_user_for_config - @out.string.should_not match(Regexp.escape("Please enter a clientname for the new client")) + @out.string.should_not match(Regexp.escape("Please enter a name for the new user")) @knife.new_client_name.should == 'testnode' end @@ -64,32 +64,32 @@ describe Chef::Knife::Configure do it "asks the user for the existing admin client's name if -i is specified" do @knife.config[:initial] = true @knife.ask_user_for_config - @out.string.should match(Regexp.escape("Please enter the existing admin clientname: [chef-webui]")) - @knife.admin_client_name.should == 'chef-webui' + @out.string.should match(Regexp.escape("Please enter the existing admin name: [admin]")) + @knife.admin_client_name.should == 'admin' end it "should not ask the user for the existing admin client's name if -i and --admin-client_name are specified" do @knife.config[:initial] = true @knife.config[:admin_client_name] = 'my-webui' @knife.ask_user_for_config - @out.string.should_not match(Regexp.escape("Please enter the existing admin clientname:")) + @out.string.should_not match(Regexp.escape("Please enter the existing admin:")) @knife.admin_client_name.should == 'my-webui' end it "should not ask the user for the existing admin client's name if -i is not specified" do @knife.ask_user_for_config - @out.string.should_not match(Regexp.escape("Please enter the existing admin clientname: [chef-webui]")) - @knife.admin_client_name.should_not == 'chef-webui' + @out.string.should_not match(Regexp.escape("Please enter the existing admin: [admin]")) + @knife.admin_client_name.should_not == 'admin' end it "asks the user for the location of the existing admin key if -i is specified" do @knife.config[:initial] = true @knife.ask_user_for_config - @out.string.should match(Regexp.escape("Please enter the location of the existing admin client's private key: [/etc/chef/webui.pem]")) + @out.string.should match(Regexp.escape("Please enter the location of the existing admin's private key: [/etc/chef/admin.pem]")) if windows? - @knife.admin_client_key.should == 'C:/etc/chef/webui.pem' + @knife.admin_client_key.should == 'C:/etc/chef/admin.pem' else - @knife.admin_client_key.should == '/etc/chef/webui.pem' + @knife.admin_client_key.should == '/etc/chef/admin.pem' end end @@ -111,7 +111,7 @@ describe Chef::Knife::Configure do if windows? @knife.admin_client_key.should_not == 'C:/etc//chef/webui.pem' else - @knife.admin_client_key.should_not == '/etc/chef/webui.pem' + @knife.admin_client_key.should_not == '/etc/chef/webui.pem' end end @@ -140,7 +140,7 @@ describe Chef::Knife::Configure do if windows? @knife.validation_key.should == 'C:/etc/chef/validation.pem' else - @knife.validation_key.should == '/etc/chef/validation.pem' + @knife.validation_key.should == '/etc/chef/validation.pem' end end @@ -208,28 +208,25 @@ describe Chef::Knife::Configure do File.should_receive(:expand_path).with("/home/you/.chef/knife.rb").and_return("/home/you/.chef/knife.rb") File.should_receive(:expand_path).with("/home/you/.chef/a-new-user.pem").and_return("/home/you/.chef/a-new-user.pem") File.should_receive(:expand_path).with("/etc/chef/validation.pem").and_return("/etc/chef/validation.pem") - File.should_receive(:expand_path).with("/etc/chef/webui.pem").and_return("/etc/chef/webui.pem") + File.should_receive(:expand_path).with("/etc/chef/admin.pem").and_return("/etc/chef/admin.pem") Chef::Config[:node_name] = "webmonkey.example.com" - - client_command_config = {} - - client_command = mock("knife client create command", :config => client_command_config) - client_command.should_receive(:name_args=).with(["a-new-user"]) - client_command.stub!(:name_args).and_return(["a-new-user"]) - client_command.should_receive(:run) + user_command = Chef::Knife::UserCreate.new + user_command.should_receive(:run) Etc.stub!(:getlogin).and_return("a-new-user") - Chef::Knife::ClientCreate.stub!(:new).and_return(client_command) + Chef::Knife::UserCreate.stub!(:new).and_return(user_command) FileUtils.should_receive(:mkdir_p).with("/home/you/.chef") ::File.should_receive(:open).with("/home/you/.chef/knife.rb", "w") @knife.config[:initial] = true + @knife.config[:user_password] = "blah" @knife.run - client_command.name_args.should == Array("a-new-user") - client_command.config[:admin].should be_true - client_command.config[:file].should == "/home/you/.chef/a-new-user.pem" - client_command.config[:yes].should be_true - client_command.config[:disable_editing].should be_true + user_command.name_args.should == Array("a-new-user") + user_command.config[:user_password].should == "blah" + user_command.config[:admin].should be_true + user_command.config[:file].should == "/home/you/.chef/a-new-user.pem" + user_command.config[:yes].should be_true + user_command.config[:disable_editing].should be_true end end |