spec/support/chef_api.rb in berkshelf-1.1.6 vs spec/support/chef_api.rb in berkshelf-1.2.0.rc1
- old
+ new
@@ -1,49 +1,44 @@
-require 'pathname'
-require 'chef/rest'
-require 'chef/cookbook_version'
-
module Berkshelf
module RSpec
module ChefAPI
# Return an array of Hashes containing cookbooks and their information
#
# @return [Array]
def get_cookbooks
- rest.get_rest("cookbooks")
+ ridley.cookbook.all
end
def upload_cookbook(path)
cached = CachedCookbook.from_store_path(path)
uploader.upload(cached)
end
- # Remove all versions of all cookbooks from the Chef Server defined in your
- # Knife config.
- def purge_cookbooks
- get_cookbooks.each do |name, info|
- info["versions"].each do |version_info|
- rest.delete_rest("cookbooks/#{name}/#{version_info["version"]}?purge=true")
- end
- end
- end
-
# Remove the version of the given cookbook from the Chef Server defined
# in your Knife config.
#
# @param [#to_s] name
# @param [#to_s] version
- def purge_cookbook(name, version)
- rest.delete_rest("cookbooks/#{name}/#{version}?purge=true")
- rescue Net::HTTPServerException => e
- raise unless e.to_s =~ /^404/
+ def purge_cookbook(name, version = nil)
+ if version.nil?
+ ridley.cookbook.delete_all(name, purge: true)
+ else
+ ridley.cookbook.delete(name, version, purge: true)
+ end
+ rescue Ridley::Errors::HTTPNotFound
+ true
end
- def server_has_cookbook?(name, version)
- rest.get_rest("cookbooks/#{name}/#{version}")
- true
- rescue Net::HTTPServerException => e
+ def server_has_cookbook?(name, version = nil)
+ versions = ridley.cookbook.versions(name)
+
+ if version.nil?
+ !versions.empty?
+ else
+ !versions.find { |ver| ver == version }.nil?
+ end
+ rescue Ridley::Errors::HTTPNotFound
false
end
def generate_cookbook(path, name, version, options = {})
path = Pathname.new(path)
@@ -96,18 +91,24 @@
cookbook_path
end
private
- def rest
- quietly { Chef::REST.new(Chef::Config[:chef_server_url]) }
+ def ridley
+ @ridley ||= Ridley.new(
+ server_url: Berkshelf::Chef::Config[:chef_server_url],
+ client_name: Berkshelf::Chef::Config[:node_name],
+ client_key: Berkshelf::Chef::Config[:client_key],
+ ssl: { verify: false }
+ )
end
def uploader
@uploader ||= Berkshelf::Uploader.new(
- server_url: Chef::Config[:chef_server_url],
- client_name: Chef::Config[:node_name],
- client_key: Chef::Config[:client_key]
+ server_url: Berkshelf::Chef::Config[:chef_server_url],
+ client_name: Berkshelf::Chef::Config[:node_name],
+ client_key: Berkshelf::Chef::Config[:client_key],
+ ssl: { verify: false }
)
end
end
end
end