Sha256: cfc3ad021308a19126eb366cdb6a88ab5be343e8dd628822d6014f9611ae0c0d

Contents?: true

Size: 694 Bytes

Versions: 4

Compression:

Stored size: 694 Bytes

Contents

require "digest"

module Artifactory
  module GemImport
    module Gems
      class Verifier
        def call(cache_path, foreign_representation)
          md5, foreign_md5 = calculate_checksums File.open(cache_path, "r"),
                                                 foreign_representation

          md5 == foreign_md5 ? [:ok] :
            [:failed, "Checksum comparison for uploaded gem #{File.basename cache_path} failed. Expected #{md5}, got #{foreign_md5}"]
        end

        private

        def calculate_checksums(file, foreign_representation)
          [Digest::MD5.hexdigest(file.read), foreign_representation.dig("checksums", "md5")]
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
artifactory-gem_import-0.2.2 lib/artifactory/gem_import/gems/verifier.rb
artifactory-gem_import-0.2.0 lib/artifactory/gem_import/gems/verifier.rb
artifactory-gem_import-0.1.4 lib/artifactory/gem_import/gems/verifier.rb
artifactory-gem_import-0.1.3 lib/artifactory/gem_import/gems/verifier.rb