summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chef/lib/chef/knife/configure.rb18
-rw-r--r--chef/spec/unit/knife/configure_spec.rb51
2 files changed, 47 insertions, 22 deletions
diff --git a/chef/lib/chef/knife/configure.rb b/chef/lib/chef/knife/configure.rb
index d94e760c04..c5e14930c1 100644
--- a/chef/lib/chef/knife/configure.rb
+++ b/chef/lib/chef/knife/configure.rb
@@ -113,13 +113,17 @@ EOH
end
def ask_user_for_config
- @chef_server = config[:chef_server_url] || ask_question("Your chef server URL? ", :default => 'http://localhost:4000')
- @new_client_name = config[:node_name] || ask_question("Select a user name for your new client: ", :default => Etc.getlogin)
- @admin_client_name = config[:admin_client_name] || ask_question("Your existing admin client user name? ", :default => 'chef-webui')
- @admin_client_key = config[:admin_client_key] || ask_question("The location of your existing admin key? ", :default => '/etc/chef/webui.pem')
- @validation_client_name = config[:validation_client_name] || ask_question("Your validation client user name? ", :default => 'chef-validator')
- @validation_key = config[:validation_key] || ask_question("The location of your validation key? ", :default => '/etc/chef/validation.pem')
- @chef_repo = config[:repository] || ask_question("Path to a chef repository (or leave blank)? ")
+ @chef_server = config[:chef_server_url] || ask_question("Please enter the chef server URL: ", :default => 'http://localhost: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')
+ else
+ @new_client_name = config[:node_name] || ask_question("Please enter an existing username or clientname for the API: ", :default => Etc.getlogin)
+ end
+ @validation_client_name = config[:validation_client_name] || ask_question("Please enter the validation clientname: ", :default => 'chef-validator')
+ @validation_key = config[:validation_key] || ask_question("Please enter the location of the validation key: ", :default => '/etc/chef/validation.pem')
+ @chef_repo = config[:repository] || ask_question("Please enter the path to a chef repository (or leave blank): ")
@new_client_key = config[:client_key] || File.join(chef_config_path, "#{@new_client_name}.pem")
end
diff --git a/chef/spec/unit/knife/configure_spec.rb b/chef/spec/unit/knife/configure_spec.rb
index 1010907e82..3d6fa3bd3e 100644
--- a/chef/spec/unit/knife/configure_spec.rb
+++ b/chef/spec/unit/knife/configure_spec.rb
@@ -16,43 +16,64 @@ describe Chef::Knife::Configure do
it "asks the user for the URL of the chef server" do
@knife.ask_user_for_config
- @out.string.should match(Regexp.escape('Your chef server URL? [http://localhost:4000]'))
+ @out.string.should match(Regexp.escape('Please enter the chef server URL: [http://localhost:4000]'))
@knife.chef_server.should == 'http://localhost:4000'
end
- it "asks the user for the user name they want for the new client" do
+ it "asks the user for the clientname they want for the new client if -i is specified" do
+ @knife.config[:initial] = true
@knife.ask_user_for_config
- @out.string.should match(Regexp.escape("Select a user name for your new client: [#{Etc.getlogin}]"))
+ @out.string.should match(Regexp.escape("Please enter a clientname for the new client: [#{Etc.getlogin}]"))
@knife.new_client_name.should == Etc.getlogin
end
- it "asks the user for the existing admin client's name" do
+ it "asks the user for the existing API username or clientname if -i is not specified" do
@knife.ask_user_for_config
- @out.string.should match(Regexp.escape("Your existing admin client user name? [chef-webui]"))
- @knife.admin_client_name.should == 'chef-webui'
- end
+ @out.string.should match(Regexp.escape("Please enter an existing username or clientname for the API: [#{Etc.getlogin}]"))
+ @knife.new_client_name.should == Etc.getlogin
+ end
- it "asks the user for the location of the existing admin key" do
- @knife.ask_user_for_config
- @out.string.should match(Regexp.escape("The location of your existing admin key? [/etc/chef/webui.pem]"))
- @knife.admin_client_key.should == '/etc/chef/webui.pem'
- end
+ 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'
+ 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'
+ 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]"))
+ @knife.admin_client_key.should == '/etc/chef/webui.pem'
+ end
+
+ it "should not ask the user for the location of the existing admin key if -i is not specified" do
+ @knife.ask_user_for_config
+ @out.string.should_not match(Regexp.escape("Please enter the location of the existing admin client's private key: [/etc/chef/webui.pem]"))
+ @knife.admin_client_key.should_not == '/etc/chef/webui.pem'
+ end
it "asks the user for the location of a chef repo" do
@knife.ask_user_for_config
- @out.string.should match(Regexp.escape("Path to a chef repository (or leave blank)?"))
+ @out.string.should match(Regexp.escape("Please enter the path to a chef repository (or leave blank):"))
@knife.chef_repo.should == ''
end
it "asks the users for the name of the validation client" do
@knife.ask_user_for_config
- @out.string.should match(Regexp.escape("Your validation client user name? [chef-validator]"))
+ @out.string.should match(Regexp.escape("Please enter the validation clientname: [chef-validator]"))
@knife.validation_client_name.should == 'chef-validator'
end
it "asks the users for the location of the validation key" do
@knife.ask_user_for_config
- @out.string.should match(Regexp.escape("The location of your validation key? [/etc/chef/validation.pem]"))
+ @out.string.should match(Regexp.escape("Please enter the location of the validation key: [/etc/chef/validation.pem]"))
@knife.validation_key.should == '/etc/chef/validation.pem'
end