Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow artifact_file to handle snapshot and latest version correctly (V2 !) #128

Merged
merged 5 commits into from
Mar 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions libraries/chef_artifact_nexus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ def retrieve_from_nexus(source, destination_dir)
def get_artifact_sha(coordinates)
REXML::Document.new(remote.get_artifact_info(coordinates)).elements["//sha1"].text
end

# Makes a call to Nexus and parses the returned XML to return
# the Nexus Server's stored filename for the given artifact.
#
# @param coordinates [String] a colon-separated Maven identifier that represents the artifact
#
# @return [String] the filename entry for the artifact
def get_artifact_filename(coordinates)
::File.basename(REXML::Document.new(remote.get_artifact_info(coordinates)).elements["//repositoryPath"].text)
end
end
end
end
18 changes: 16 additions & 2 deletions providers/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,18 @@ def load_current_resource
run_proc :after_download
end
elsif Chef::Artifact.from_nexus?(file_location)
unless ::File.exists?(new_resource.path) && checksum_valid?
unless ::File.exists?(new_resource.path) && checksum_valid? && (!Chef::Artifact.snapshot?(file_location) || !Chef::Artifact.latest?(file_location))
begin
nexus_connection.retrieve_from_nexus(file_location, ::File.dirname(new_resource.path))
if ::File.exists?(new_resource.path)
if Digest::SHA1.file(new_resource.path).hexdigest != nexus_connection.get_artifact_sha(file_location)
nexus_connection.retrieve_from_nexus(file_location, ::File.dirname(new_resource.path))
end
else
nexus_connection.retrieve_from_nexus(file_location, ::File.dirname(new_resource.path))
end
if nexus_connection.get_artifact_filename(file_location) != ::File.basename(new_resource.path)
::File.rename(::File.join(::File.dirname(new_resource.path), nexus_connection.get_artifact_filename(file_location)), new_resource.path)
end
run_proc :after_download
rescue NexusCli::PermissionsException => e
msg = "The artifact server returned 401 (Unauthorized) when attempting to retrieve this artifact. Confirm that your credentials are correct."
Expand Down Expand Up @@ -92,6 +101,11 @@ def checksum_valid?
require 'digest'

if cached_checksum_exists?
if Chef::Artifact.from_nexus?(file_location)
if Chef::Artifact.snapshot?(file_location) || Chef::Artifact.latest?(file_location)
return Digest::SHA1.file(new_resource.path).hexdigest == nexus_connection.get_artifact_sha(file_location)
end
end
return Digest::SHA256.file(new_resource.path).hexdigest == read_checksum
end

Expand Down