lib/berkshelf/locations/chef_api_location.rb in berkshelf-1.0.0.rc1 vs lib/berkshelf/locations/chef_api_location.rb in berkshelf-1.0.0.rc2
- old
+ new
@@ -43,11 +43,11 @@
# @return [Boolean]
def validate_uri(uri)
uri =~ URI.regexp(['http', 'https'])
end
- # @raise [InvalidChefAPILocation] if the given object is not a String containing a
+ # @raise [InvalidChefAPILocation] if the given object is not a String containing a
# valid Chef API URI
#
# @see validate_uri
def validate_uri!(uri)
unless validate_uri(uri)
@@ -128,29 +128,27 @@
# @param [#to_s] destination
#
# @return [Berkshelf::CachedCookbook]
def download(destination)
version, uri = target_version
- cookbook = rest.get_rest(uri)
+ scratch = download_files(download_manifest(uri))
- scratch = download_files(cookbook.manifest)
-
cb_path = File.join(destination, "#{name}-#{version}")
FileUtils.mv(scratch, cb_path)
cached = CachedCookbook.from_store_path(cb_path)
validate_cached(cached)
-
+
set_downloaded_status(true)
cached
end
# Returns a hash representing the cookbook versions on at a Chef API for location's cookbook.
# The keys are version strings and the values are URLs to download the cookbook version.
#
# @example
- # {
+ # {
# "0.101.2" => "https://api.opscode.com/organizations/vialstudios/cookbooks/nginx/0.101.2",
# "0.101.5" => "https://api.opscode.com/organizations/vialstudios/cookbooks/nginx/0.101.5"
# }
#
# @return [Hash]
@@ -198,21 +196,30 @@
private
attr_reader :rest
+ # Retrieve a cookbooks manifest from the given URL
+ #
+ # @param [String] uri
+ #
+ # @return [Hash]
+ def download_manifest(uri)
+ Chef::CookbookVersion.json_create(rest.get_rest(uri)).manifest
+ end
+
# Returns an array containing the version and download URL for the cookbook version that
# should be downloaded for this location.
#
# @example
# [ "0.101.2" => "https://api.opscode.com/organizations/vialstudios/cookbooks/nginx/0.101.2" ]
#
# @return [Array]
def target_version
if version_constraint
solution = self.class.solve_for_constraint(version_constraint, versions)
-
+
unless solution
raise NoSolution, "No cookbook version of '#{name}' found at #{self} that would satisfy constraint (#{version_constraint})."
end
solution
@@ -266,9 +273,9 @@
raise InvalidChefAPILocation, "Source '#{name}' is a 'chef_api' location with a URL for it's value but is missing options: #{missing_options.join(', ')}."
end
self.class.validate_node_name!(options[:node_name])
self.class.validate_client_key!(options[:client_key])
- self.class.validate_uri!(options[:chef_api])
+ self.class.validate_uri!(options[:chef_api])
end
end
end