summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel DeLeo <dan@opscode.com>2011-04-11 13:20:50 -0700
committerDaniel DeLeo <dan@opscode.com>2011-04-11 13:22:27 -0700
commit5e98c9ee4c2c4b0715a6a3d15b3b94e95c65cff5 (patch)
tree52cae9b3e5991c3efda61fa1fa9eb9b506ac2718
parent14cc140b1b6d02f3b07e58d8d7f169d77dd2e1ed (diff)
downloadchef-5e98c9ee4c2c4b0715a6a3d15b3b94e95c65cff5.tar.gz
[CHEF-2215] don't barf when there is no config file.
Also, make the cookbook site (read only) commands work without username/key
-rw-r--r--chef/lib/chef/knife.rb12
-rw-r--r--chef/lib/chef/knife/cookbook_site_download.rb10
-rw-r--r--chef/lib/chef/knife/cookbook_site_list.rb2
-rw-r--r--chef/lib/chef/knife/cookbook_site_search.rb2
-rw-r--r--chef/lib/chef/knife/cookbook_site_show.rb6
5 files changed, 20 insertions, 12 deletions
diff --git a/chef/lib/chef/knife.rb b/chef/lib/chef/knife.rb
index 83c0a74ab9..6b62516adc 100644
--- a/chef/lib/chef/knife.rb
+++ b/chef/lib/chef/knife.rb
@@ -288,7 +288,8 @@ class Chef
read_config_file(config[:config_file])
else
# ...but do log a message if no config was found.
- self.msg("No knife configuration file found")
+ Chef::Config[:color] = config[:color] && !config[:no_color]
+ ui.warn("No knife configuration file found")
end
Chef::Config[:color] = config[:color] && !config[:no_color]
@@ -320,7 +321,7 @@ class Chef
Chef::Log.debug("Using configuration from #{config[:config_file]}")
if Chef::Config[:node_name].nil?
- raise ArgumentError, "No user specified, pass via -u or specifiy 'node_name' in #{config[:config_file] ? config[:config_file] : "~/.chef/knife.rb"}"
+ #raise ArgumentError, "No user specified, pass via -u or specifiy 'node_name' in #{config[:config_file] ? config[:config_file] : "~/.chef/knife.rb"}"
end
end
@@ -514,6 +515,13 @@ class Chef
end
end
+ def noauth_rest
+ @rest ||= begin
+ require 'chef/rest'
+ Chef::REST.new(Chef::Config[:chef_server_url], false, false)
+ end
+ end
+
def server_url
Chef::Config[:chef_server_url]
end
diff --git a/chef/lib/chef/knife/cookbook_site_download.rb b/chef/lib/chef/knife/cookbook_site_download.rb
index e146e1da24..0cf547ccac 100644
--- a/chef/lib/chef/knife/cookbook_site_download.rb
+++ b/chef/lib/chef/knife/cookbook_site_download.rb
@@ -33,17 +33,17 @@ class Chef
def run
if @name_args.length == 1
- current = rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{name_args[0]}")
- cookbook_data = rest.get_rest(current["latest_version"])
+ current = noauth_rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{name_args[0]}")
+ cookbook_data = noauth_rest.get_rest(current["latest_version"])
else
- cookbook_data = rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{name_args[0]}/versions/#{name_args[1].gsub('.', '_')}")
+ cookbook_data = noauth_rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{name_args[0]}/versions/#{name_args[1].gsub('.', '_')}")
end
@version = cookbook_data['version']
ui.info("Downloading #{@name_args[0]} from the cookbooks site at version #{cookbook_data['version']} to #{config[:file]}")
- rest.sign_on_redirect = false
- tf = rest.get_rest(cookbook_data["file"], true)
+ noauth_rest.sign_on_redirect = false
+ tf = noauth_rest.get_rest(cookbook_data["file"], true)
unless config[:file]
config[:file] = File.join(Dir.pwd, "#{@name_args[0]}-#{cookbook_data['version']}.tar.gz")
end
diff --git a/chef/lib/chef/knife/cookbook_site_list.rb b/chef/lib/chef/knife/cookbook_site_list.rb
index e55f20a911..107b3101ee 100644
--- a/chef/lib/chef/knife/cookbook_site_list.rb
+++ b/chef/lib/chef/knife/cookbook_site_list.rb
@@ -36,7 +36,7 @@ class Chef
def get_cookbook_list(items=10, start=0, cookbook_collection={})
cookbooks_url = "http://cookbooks.opscode.com/api/v1/cookbooks?items=#{items}&start=#{start}"
- cr = rest.get_rest(cookbooks_url)
+ cr = noauth_rest.get_rest(cookbooks_url)
cr["items"].each do |cookbook|
cookbook_collection[cookbook["cookbook_name"]] = cookbook
end
diff --git a/chef/lib/chef/knife/cookbook_site_search.rb b/chef/lib/chef/knife/cookbook_site_search.rb
index 3faa3c583e..5df7d67327 100644
--- a/chef/lib/chef/knife/cookbook_site_search.rb
+++ b/chef/lib/chef/knife/cookbook_site_search.rb
@@ -30,7 +30,7 @@ class Chef
def search_cookbook(query, items=10, start=0, cookbook_collection={})
cookbooks_url = "http://cookbooks.opscode.com/api/v1/search?q=#{query}&items=#{items}&start=#{start}"
- cr = rest.get_rest(cookbooks_url)
+ cr = noauth_rest.get_rest(cookbooks_url)
cr["items"].each do |cookbook|
cookbook_collection[cookbook["cookbook_name"]] = cookbook
end
diff --git a/chef/lib/chef/knife/cookbook_site_show.rb b/chef/lib/chef/knife/cookbook_site_show.rb
index 816c0d685e..cbaa815092 100644
--- a/chef/lib/chef/knife/cookbook_site_show.rb
+++ b/chef/lib/chef/knife/cookbook_site_show.rb
@@ -27,16 +27,16 @@ class Chef
def run
case @name_args.length
when 1
- cookbook_data = rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{@name_args[0]}")
+ cookbook_data = noauth_rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{@name_args[0]}")
when 2
- cookbook_data = rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{@name_args[0]}/versions/#{name_args[1].gsub('.', '_')}")
+ cookbook_data = noauth_rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{@name_args[0]}/versions/#{name_args[1].gsub('.', '_')}")
end
output(format_for_display(cookbook_data))
end
def get_cookbook_list(items=10, start=0, cookbook_collection={})
cookbooks_url = "http://cookbooks.opscode.com/api/v1/cookbooks?items=#{items}&start=#{start}"
- cr = rest.get_rest(cookbooks_url)
+ cr = noauth_rest.get_rest(cookbooks_url)
cr["items"].each do |cookbook|
cookbook_collection[cookbook["cookbook_name"]] = cookbook
end