Class: Vara::ProductArtifactValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/vara/product_artifact_validator.rb

Class Method Summary collapse

Class Method Details

.validate_file_checksum(file_metadata, file_name) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/vara/product_artifact_validator.rb', line 5

def self.validate_file_checksum(, file_name)
  raise "No checksum for file #{file_name}!" unless .md5 || .sha1

  validate_md5(, file_name) if .md5

  validate_sha1(, file_name) if .sha1
end

.validate_md5(file_metadata, file_name) ⇒ Object



19
20
21
22
23
# File 'lib/vara/product_artifact_validator.rb', line 19

def self.validate_md5(, file_name)
  md5_got = Digest::MD5.file(file_name).hexdigest
  md5_expected = .md5
  raise "md5 mismatch for file #{file_name}, expected #{md5_expected}, got #{md5_got}" if md5_got != md5_expected
end

.validate_sha1(file_metadata, file_name) ⇒ Object



13
14
15
16
17
# File 'lib/vara/product_artifact_validator.rb', line 13

def self.validate_sha1(, file_name)
  sha1_got = Digest::SHA1.file(file_name).hexdigest
  sha1_expected = .sha1
  raise "sha1 mismatch for file #{file_name}, expected #{sha1_expected}, got #{sha1_got}" if sha1_got != sha1_expected
end