summaryrefslogtreecommitdiff
path: root/lib/chef/knife
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2015-12-02 12:19:33 +0000
committerThom May <thom@chef.io>2016-01-11 15:40:42 +0000
commitd99e306a41b1402209d320cb7119b12a3bbb962f (patch)
treef65940702826deb991e6198967d3e9e96cb2857a /lib/chef/knife
parent1b71aeb423b009f6d1a44215c89e9976957b47e9 (diff)
downloadchef-d99e306a41b1402209d320cb7119b12a3bbb962f.tar.gz
Convert all uses of Chef::REST to Chef::ServerAPItm/no_more_rest
In the process, stop auto-expanding JSON in the HTTP client, and let individual classes control that themselves. Fixes #2737, Fixes #3518
Diffstat (limited to 'lib/chef/knife')
-rw-r--r--lib/chef/knife/bootstrap/client_builder.rb12
-rw-r--r--lib/chef/knife/cookbook_bulk_delete.rb4
-rw-r--r--lib/chef/knife/cookbook_delete.rb4
-rw-r--r--lib/chef/knife/cookbook_download.rb5
-rw-r--r--lib/chef/knife/cookbook_list.rb2
-rw-r--r--lib/chef/knife/cookbook_show.rb10
-rw-r--r--lib/chef/knife/cookbook_site_download.rb6
-rw-r--r--lib/chef/knife/cookbook_site_list.rb2
-rw-r--r--lib/chef/knife/cookbook_site_search.rb2
-rw-r--r--lib/chef/knife/cookbook_site_share.rb2
-rw-r--r--lib/chef/knife/cookbook_site_show.rb6
-rw-r--r--lib/chef/knife/cookbook_site_unshare.rb2
-rw-r--r--lib/chef/knife/data_bag_create.rb4
-rw-r--r--lib/chef/knife/data_bag_delete.rb4
-rw-r--r--lib/chef/knife/data_bag_edit.rb2
-rw-r--r--lib/chef/knife/environment_compare.rb2
-rw-r--r--lib/chef/knife/index_rebuild.rb4
-rw-r--r--lib/chef/knife/raw.rb1
-rw-r--r--lib/chef/knife/recipe_list.rb2
19 files changed, 38 insertions, 38 deletions
diff --git a/lib/chef/knife/bootstrap/client_builder.rb b/lib/chef/knife/bootstrap/client_builder.rb
index 6414ac5c72..f5a2ff2bb1 100644
--- a/lib/chef/knife/bootstrap/client_builder.rb
+++ b/lib/chef/knife/bootstrap/client_builder.rb
@@ -17,7 +17,7 @@
#
require 'chef/node'
-require 'chef/rest'
+require 'chef/server_api'
require 'chef/api_client/registration'
require 'chef/api_client'
require 'chef/knife/bootstrap'
@@ -185,22 +185,22 @@ class Chef
# @param relative_path [String] URI path relative to the chef organization
# @return [Boolean] if the relative path exists or returns a 404
def resource_exists?(relative_path)
- rest.get_rest(relative_path)
+ rest.get(relative_path)
true
rescue Net::HTTPServerException => e
raise unless e.response.code == "404"
false
end
- # @return [Chef::REST] REST client using the client credentials
+ # @return [Chef::ServerAPI] REST client using the client credentials
def client_rest
- @client_rest ||= Chef::REST.new(chef_server_url, node_name, client_path)
+ @client_rest ||= Chef::ServerAPI.new(chef_server_url, :client_name => node_name, :signing_key_filename => client_path)
end
- # @return [Chef::REST] REST client using the cli user's knife credentials
+ # @return [Chef::ServerAPI] REST client using the cli user's knife credentials
# this uses the users's credentials
def rest
- @rest ||= Chef::REST.new(chef_server_url)
+ @rest ||= Chef::ServerAPI.new(chef_server_url)
end
end
end
diff --git a/lib/chef/knife/cookbook_bulk_delete.rb b/lib/chef/knife/cookbook_bulk_delete.rb
index 65fa888486..ec0d06937f 100644
--- a/lib/chef/knife/cookbook_bulk_delete.rb
+++ b/lib/chef/knife/cookbook_bulk_delete.rb
@@ -60,9 +60,9 @@ class Chef
cookbooks_names.each do |cookbook_name|
- versions = rest.get_rest("cookbooks/#{cookbook_name}")[cookbook_name]["versions"].map {|v| v["version"]}.flatten
+ versions = rest.get("cookbooks/#{cookbook_name}")[cookbook_name]["versions"].map {|v| v["version"]}.flatten
versions.each do |version|
- object = rest.delete_rest("cookbooks/#{cookbook_name}/#{version}#{config[:purge] ? "?purge=true" : ""}")
+ object = rest.delete("cookbooks/#{cookbook_name}/#{version}#{config[:purge] ? "?purge=true" : ""}")
ui.info("Deleted cookbook #{cookbook_name.ljust(25)} [#{version}]")
end
end
diff --git a/lib/chef/knife/cookbook_delete.rb b/lib/chef/knife/cookbook_delete.rb
index f436d270bd..5fe0e9664d 100644
--- a/lib/chef/knife/cookbook_delete.rb
+++ b/lib/chef/knife/cookbook_delete.rb
@@ -85,7 +85,7 @@ class Chef
end
def available_versions
- @available_versions ||= rest.get_rest("cookbooks/#{@cookbook_name}").map do |name, url_and_version|
+ @available_versions ||= rest.get("cookbooks/#{@cookbook_name}").map do |name, url_and_version|
url_and_version["versions"].map {|url_by_version| url_by_version["version"]}
end.flatten
rescue Net::HTTPServerException => e
@@ -143,7 +143,7 @@ class Chef
def delete_request(path)
path += "?purge=true" if config[:purge]
- rest.delete_rest(path)
+ rest.delete(path)
end
end
diff --git a/lib/chef/knife/cookbook_download.rb b/lib/chef/knife/cookbook_download.rb
index cb8eeb8edf..6ba5fc7d6c 100644
--- a/lib/chef/knife/cookbook_download.rb
+++ b/lib/chef/knife/cookbook_download.rb
@@ -69,7 +69,7 @@ class Chef
ui.info("Downloading #{@cookbook_name} cookbook version #{@version}")
- cookbook = rest.get_rest("cookbooks/#{@cookbook_name}/#{@version}")
+ cookbook = Chef::CookbookVersion.load(@cookbook_name, @version)
manifest = cookbook.manifest
basedir = File.join(config[:download_directory], "#{@cookbook_name}-#{cookbook.version}")
@@ -90,8 +90,7 @@ class Chef
dest = File.join(basedir, segment_file['path'].gsub('/', File::SEPARATOR))
Chef::Log.debug("Downloading #{segment_file['path']} to #{dest}")
FileUtils.mkdir_p(File.dirname(dest))
- rest.sign_on_redirect = false
- tempfile = rest.get_rest(segment_file['url'], true)
+ tempfile = rest.streaming_request(segment_file['url'])
FileUtils.mv(tempfile.path, dest)
end
end
diff --git a/lib/chef/knife/cookbook_list.rb b/lib/chef/knife/cookbook_list.rb
index 75f18a154b..dd78e854da 100644
--- a/lib/chef/knife/cookbook_list.rb
+++ b/lib/chef/knife/cookbook_list.rb
@@ -39,7 +39,7 @@ class Chef
env = config[:environment]
num_versions = config[:all_versions] ? "num_versions=all" : "num_versions=1"
api_endpoint = env ? "/environments/#{env}/cookbooks?#{num_versions}" : "/cookbooks?#{num_versions}"
- cookbook_versions = rest.get_rest(api_endpoint)
+ cookbook_versions = rest.get(api_endpoint)
ui.output(format_cookbook_list_for_display(cookbook_versions))
end
end
diff --git a/lib/chef/knife/cookbook_show.rb b/lib/chef/knife/cookbook_show.rb
index 7c9cbebdb1..07f7684c27 100644
--- a/lib/chef/knife/cookbook_show.rb
+++ b/lib/chef/knife/cookbook_show.rb
@@ -67,9 +67,9 @@ class Chef
cookbook_name, segment, filename = @name_args[0], @name_args[2], @name_args[3]
cookbook_version = @name_args[1] == 'latest' ? '_latest' : @name_args[1]
- cookbook = rest.get_rest("cookbooks/#{cookbook_name}/#{cookbook_version}")
+ cookbook = rest.get("cookbooks/#{cookbook_name}/#{cookbook_version}")
manifest_entry = cookbook.preferred_manifest_record(node, segment, filename)
- temp_file = rest.get_rest(manifest_entry[:url], true)
+ temp_file = rest.get(manifest_entry[:url], true)
# the temp file is cleaned up elsewhere
temp_file.open if temp_file.closed?
@@ -77,16 +77,16 @@ class Chef
when 3 # We are showing a specific part of the cookbook
cookbook_version = @name_args[1] == 'latest' ? '_latest' : @name_args[1]
- result = rest.get_rest("cookbooks/#{@name_args[0]}/#{cookbook_version}")
+ result = rest.get("cookbooks/#{@name_args[0]}/#{cookbook_version}")
output(result.manifest[@name_args[2]])
when 2 # We are showing the whole cookbook data
cookbook_version = @name_args[1] == 'latest' ? '_latest' : @name_args[1]
- output(rest.get_rest("cookbooks/#{@name_args[0]}/#{cookbook_version}"))
+ output(rest.get("cookbooks/#{@name_args[0]}/#{cookbook_version}"))
when 1 # We are showing the cookbook versions (all of them)
cookbook_name = @name_args[0]
env = config[:environment]
api_endpoint = env ? "environments/#{env}/cookbooks/#{cookbook_name}" : "cookbooks/#{cookbook_name}"
- output(format_cookbook_list_for_display(rest.get_rest(api_endpoint)))
+ output(format_cookbook_list_for_display(rest.get(api_endpoint)))
when 0
show_usage
ui.fatal("You must specify a cookbook name")
diff --git a/lib/chef/knife/cookbook_site_download.rb b/lib/chef/knife/cookbook_site_download.rb
index 3e586e6542..72608f3a30 100644
--- a/lib/chef/knife/cookbook_site_download.rb
+++ b/lib/chef/knife/cookbook_site_download.rb
@@ -63,7 +63,7 @@ class Chef
def current_cookbook_data
@current_cookbook_data ||= begin
- noauth_rest.get_rest "#{cookbooks_api_url}/#{@name_args[0]}"
+ noauth_rest.get "#{cookbooks_api_url}/#{@name_args[0]}"
end
end
@@ -79,14 +79,14 @@ class Chef
specific_cookbook_version_url
end
- noauth_rest.get_rest uri
+ noauth_rest.get uri
end
end
def download_cookbook
ui.info "Downloading #{@name_args[0]} from Supermarket at version #{version} to #{download_location}"
noauth_rest.sign_on_redirect = false
- tf = noauth_rest.get_rest desired_cookbook_data["file"], true
+ tf = noauth_rest.get desired_cookbook_data["file"], true
::FileUtils.cp tf.path, download_location
ui.info "Cookbook saved: #{download_location}"
diff --git a/lib/chef/knife/cookbook_site_list.rb b/lib/chef/knife/cookbook_site_list.rb
index 846123c867..b5354ed6e6 100644
--- a/lib/chef/knife/cookbook_site_list.rb
+++ b/lib/chef/knife/cookbook_site_list.rb
@@ -42,7 +42,7 @@ class Chef
def get_cookbook_list(items=10, start=0, cookbook_collection={})
cookbooks_url = "https://supermarket.chef.io/api/v1/cookbooks?items=#{items}&start=#{start}"
- cr = noauth_rest.get_rest(cookbooks_url)
+ cr = noauth_rest.get(cookbooks_url)
cr["items"].each do |cookbook|
cookbook_collection[cookbook["cookbook_name"]] = cookbook
end
diff --git a/lib/chef/knife/cookbook_site_search.rb b/lib/chef/knife/cookbook_site_search.rb
index 0baaf90f1c..decbf6c2c3 100644
--- a/lib/chef/knife/cookbook_site_search.rb
+++ b/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 = "https://supermarket.chef.io/api/v1/search?q=#{query}&items=#{items}&start=#{start}"
- cr = noauth_rest.get_rest(cookbooks_url)
+ cr = noauth_rest.get(cookbooks_url)
cr["items"].each do |cookbook|
cookbook_collection[cookbook["cookbook_name"]] = cookbook
end
diff --git a/lib/chef/knife/cookbook_site_share.rb b/lib/chef/knife/cookbook_site_share.rb
index beb98b71b8..043ca84a58 100644
--- a/lib/chef/knife/cookbook_site_share.rb
+++ b/lib/chef/knife/cookbook_site_share.rb
@@ -108,7 +108,7 @@ class Chef
def get_category(cookbook_name)
begin
- data = noauth_rest.get_rest("https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}")
+ data = noauth_rest.get("https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}")
if !data["category"] && data["error_code"]
ui.fatal("Received an error from Supermarket: #{data["error_code"]}. On the first time you upload it, you are required to specify the category you want to share this cookbook to.")
exit(1)
diff --git a/lib/chef/knife/cookbook_site_show.rb b/lib/chef/knife/cookbook_site_show.rb
index 6b65b62570..521a60eb36 100644
--- a/lib/chef/knife/cookbook_site_show.rb
+++ b/lib/chef/knife/cookbook_site_show.rb
@@ -31,15 +31,15 @@ class Chef
def get_cookbook_data
case @name_args.length
when 1
- noauth_rest.get_rest("https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}")
+ noauth_rest.get("https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}")
when 2
- noauth_rest.get_rest("https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}/versions/#{name_args[1].gsub('.', '_')}")
+ noauth_rest.get("https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}/versions/#{name_args[1].gsub('.', '_')}")
end
end
def get_cookbook_list(items=10, start=0, cookbook_collection={})
cookbooks_url = "https://supermarket.chef.io/api/v1/cookbooks?items=#{items}&start=#{start}"
- cr = noauth_rest.get_rest(cookbooks_url)
+ cr = noauth_rest.get(cookbooks_url)
cr["items"].each do |cookbook|
cookbook_collection[cookbook["cookbook_name"]] = cookbook
end
diff --git a/lib/chef/knife/cookbook_site_unshare.rb b/lib/chef/knife/cookbook_site_unshare.rb
index 77bb18322c..0c196c328a 100644
--- a/lib/chef/knife/cookbook_site_unshare.rb
+++ b/lib/chef/knife/cookbook_site_unshare.rb
@@ -41,7 +41,7 @@ class Chef
confirm "Do you really want to unshare all versions of the cookbook #{@cookbook_name}"
begin
- rest.delete_rest "https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}"
+ rest.delete "https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}"
rescue Net::HTTPServerException => e
raise e unless e.message =~ /Forbidden/
ui.error "Forbidden: You must be the maintainer of #{@cookbook_name} to unshare it."
diff --git a/lib/chef/knife/data_bag_create.rb b/lib/chef/knife/data_bag_create.rb
index f8a7619a8a..1becad88b9 100644
--- a/lib/chef/knife/data_bag_create.rb
+++ b/lib/chef/knife/data_bag_create.rb
@@ -51,7 +51,7 @@ class Chef
# create the data bag
begin
- rest.post_rest("data", { "name" => @data_bag_name })
+ rest.post("data", { "name" => @data_bag_name })
ui.info("Created data_bag[#{@data_bag_name}]")
rescue Net::HTTPServerException => e
raise unless e.to_s =~ /^409/
@@ -68,7 +68,7 @@ class Chef
output
end)
item.data_bag(@data_bag_name)
- rest.post_rest("data/#{@data_bag_name}", item)
+ rest.post("data/#{@data_bag_name}", item)
end
end
end
diff --git a/lib/chef/knife/data_bag_delete.rb b/lib/chef/knife/data_bag_delete.rb
index 575e9d604d..a3215d4c54 100644
--- a/lib/chef/knife/data_bag_delete.rb
+++ b/lib/chef/knife/data_bag_delete.rb
@@ -32,11 +32,11 @@ class Chef
def run
if @name_args.length == 2
delete_object(Chef::DataBagItem, @name_args[1], "data_bag_item") do
- rest.delete_rest("data/#{@name_args[0]}/#{@name_args[1]}")
+ rest.delete("data/#{@name_args[0]}/#{@name_args[1]}")
end
elsif @name_args.length == 1
delete_object(Chef::DataBag, @name_args[0], "data_bag") do
- rest.delete_rest("data/#{@name_args[0]}")
+ rest.delete("data/#{@name_args[0]}")
end
else
show_usage
diff --git a/lib/chef/knife/data_bag_edit.rb b/lib/chef/knife/data_bag_edit.rb
index 6ef4b33f59..88c5669508 100644
--- a/lib/chef/knife/data_bag_edit.rb
+++ b/lib/chef/knife/data_bag_edit.rb
@@ -65,7 +65,7 @@ class Chef
item_to_save = edited_item
end
- rest.put_rest("data/#{@name_args[0]}/#{@name_args[1]}", item_to_save)
+ rest.put("data/#{@name_args[0]}/#{@name_args[1]}", item_to_save)
stdout.puts("Saved data_bag_item[#{@name_args[1]}]")
ui.output(edited_item) if config[:print_after]
end
diff --git a/lib/chef/knife/environment_compare.rb b/lib/chef/knife/environment_compare.rb
index 792ec444ea..54f011f323 100644
--- a/lib/chef/knife/environment_compare.rb
+++ b/lib/chef/knife/environment_compare.rb
@@ -57,7 +57,7 @@ class Chef
end
# Get all cookbooks so we can compare them all
- cookbooks = rest.get_rest("/cookbooks?num_versions=1") if config[:all]
+ cookbooks = rest.get("/cookbooks?num_versions=1") if config[:all]
# display matrix view of in the requested format.
if config[:format] == 'summary'
diff --git a/lib/chef/knife/index_rebuild.rb b/lib/chef/knife/index_rebuild.rb
index 4b9fcdd159..95b0dcaffb 100644
--- a/lib/chef/knife/index_rebuild.rb
+++ b/lib/chef/knife/index_rebuild.rb
@@ -38,7 +38,7 @@ class Chef
else
deprecated_server_message
nag
- output rest.post_rest("/search/reindex", {})
+ output rest.post("/search/reindex", {})
end
end
@@ -50,7 +50,7 @@ class Chef
# for a node we know won't exist; the 404 response that comes
# back will give us what we want
dummy_node = "knife_index_rebuild_test_#{rand(1000000)}"
- rest.get_rest("/nodes/#{dummy_node}")
+ rest.get("/nodes/#{dummy_node}")
rescue Net::HTTPServerException => exception
r = exception.response
parse_api_info(r)
diff --git a/lib/chef/knife/raw.rb b/lib/chef/knife/raw.rb
index 601cfcef9b..de8742deb9 100644
--- a/lib/chef/knife/raw.rb
+++ b/lib/chef/knife/raw.rb
@@ -1,4 +1,5 @@
require 'chef/knife'
+require 'chef/http'
class Chef
class Knife
diff --git a/lib/chef/knife/recipe_list.rb b/lib/chef/knife/recipe_list.rb
index ed7d2a9509..46ad619f1d 100644
--- a/lib/chef/knife/recipe_list.rb
+++ b/lib/chef/knife/recipe_list.rb
@@ -22,7 +22,7 @@ class Chef::Knife::RecipeList < Chef::Knife
banner "knife recipe list [PATTERN]"
def run
- recipes = rest.get_rest('cookbooks/_recipes')
+ recipes = rest.get('cookbooks/_recipes')
if pattern = @name_args.first
recipes = recipes.grep(Regexp.new(pattern))
end