class Bosh::Blobstore::Sha1VerifiableBlobstoreClient

Public Class Methods

new(client) click to toggle source
# File lib/blobstore_client/sha1_verifiable_blobstore_client.rb, line 9
def initialize(client)
  @client = client
end

Public Instance Methods

get(id, file = nil, options = {}) click to toggle source
# File lib/blobstore_client/sha1_verifiable_blobstore_client.rb, line 13
def get(id, file = nil, options = {})
  if options.has_key?(:sha1)
    expected_sha1 = options[:sha1]
    raise ArgumentError, 'sha1 must not be nil' unless expected_sha1
  end

  result_file = @client.get(id, file, options)

  if expected_sha1
    # Blobstore clients either modify passed in file
    # or return new temporary file
    check_sha1(expected_sha1, file || result_file)
  end

  result_file
end

Private Instance Methods

check_sha1(expected_sha1, file_to_check) click to toggle source
# File lib/blobstore_client/sha1_verifiable_blobstore_client.rb, line 34
def check_sha1(expected_sha1, file_to_check)
  expected_sha1 = expected_sha1
  actual_sha1   = Digest::SHA1.file(file_to_check.path).hexdigest
  unless expected_sha1 == actual_sha1
    raise BlobstoreError, "sha1 mismatch expected=#{expected_sha1} actual=#{actual_sha1}"
  end
end