class Vara::Tarball
Represents a binary file that is packaged in a .pivotal product
Attributes
metadata[R]
target_dir[R]
Public Class Methods
new(metadata, target_dir)
click to toggle source
@param [#basename,#url,#md5] metadata @param [String] target_dir
path to folder where binary should be saved
# File lib/vara/tarball.rb, line 13 def initialize(metadata, target_dir) @metadata = metadata @target_dir = target_dir end
Public Instance Methods
sync_local_copy()
click to toggle source
Based on the metadata, downloads the binary from the metadata#url and verifies the checksum. @return [String] path to the downloaded/verified release taball @raise [RuntimeError] if the checksum of the downloaded file does not match the expected checksum
# File lib/vara/tarball.rb, line 21 def sync_local_copy download validate_tarball validate_checksum path_to_binary end
Private Instance Methods
download()
click to toggle source
# File lib/vara/tarball.rb, line 36 def download return if File.exist?(path_to_binary) log.info("Beginning download of #{metadata.url} to #{path_to_binary}") Downloader.download(metadata, path_to_binary) log.info("File download from #{metadata.url} to #{path_to_binary} complete") end
path_to_binary()
click to toggle source
# File lib/vara/tarball.rb, line 32 def path_to_binary File.join(target_dir, metadata.basename) end
validate_checksum()
click to toggle source
# File lib/vara/tarball.rb, line 58 def validate_checksum log.info("Beginning checksum validation of #{metadata}") log.info("Path to File: #{path_to_binary}") raise "Metadata doesn't include SHA1 or MD5 checksum!" unless metadata.md5 || metadata.sha1 validate_md5 if metadata.md5 validate_sha1 if metadata.sha1 log.info("#{metadata} checksum validation complete") end
validate_md5()
click to toggle source
# File lib/vara/tarball.rb, line 74 def validate_md5 log.info("Expected MD5: #{metadata.md5}") actual_md5 = Digest::MD5.file(path_to_binary).hexdigest log.info("Actual MD5: #{actual_md5}") raise "MD5 doesn't match expected value!" unless actual_md5 == metadata.md5 end
validate_sha1()
click to toggle source
# File lib/vara/tarball.rb, line 67 def validate_sha1 log.info("Expected SHA1: #{metadata.sha1}") actual_sha1 = Digest::SHA1.file(path_to_binary).hexdigest log.info("Actual SHA1: #{actual_sha1}") raise "SHA1 doesn't match expected value!" unless actual_sha1 == metadata.sha1 end
validate_tarball()
click to toggle source
# File lib/vara/tarball.rb, line 44 def validate_tarball stdout_string = '' stderr_string = '' cmd_args = "tar -tvzf #{path_to_binary}" status = Open4.popen4(cmd_args) do |_, _, stdout, stderr| stdout_string = stdout.read stderr_string = stderr.read end raise "Invalid tarball: #{path_to_binary}. Tar command STDOUT: #{stdout_string}\n STDERR:#{stderr_string}" unless status.success? log.info("Verified that #{path_to_binary} as a valid tar file") end