class Fog::AWS::Storage::Real::S3Streamer

See docs.aws.amazon.com/AmazonS3/latest/API/sigv4-streaming.html

Attributes

body[RW]
date[RW]
finished[RW]
initial_signature[RW]
signature[RW]
signer[RW]

Public Class Methods

new(body, signature, signer, date) click to toggle source
# File lib/fog/aws/storage.rb, line 707
def initialize(body, signature, signer, date)
  self.body = body
  self.date = date
  self.signature = signature
  self.initial_signature = signature
  self.signer = signer
  if body.respond_to?(:binmode)
    body.binmode
  end

  if body.respond_to?(:pos=)
    body.pos = 0
  end

end

Public Instance Methods

call() click to toggle source
# File lib/fog/aws/storage.rb, line 731
def call
  if finished
    ''
  else
    next_chunk
  end
end
next_chunk() click to toggle source
# File lib/fog/aws/storage.rb, line 739
def next_chunk
  data = body.read(0x10000)
  if data.nil?
    self.finished = true
    data = ''
  end
  self.signature = sign_chunk(data, signature)
  "#{data.length.to_s(16)};chunk-signature=#{signature}\r\n#{data}\r\n"
end
rewind() click to toggle source

called if excon wants to retry the request. As well as rewinding the body we must also reset the signature

# File lib/fog/aws/storage.rb, line 725
def rewind
  self.signature = initial_signature
  self.finished = false
  body.rewind
end
sign_chunk(data, previous_signature) click to toggle source
# File lib/fog/aws/storage.rb, line 750
          def sign_chunk(data, previous_signature)
            string_to_sign = <<-DATA
AWS4-HMAC-SHA256-PAYLOAD
#{date.to_iso8601_basic}
#{signer.credential_scope(date)}
#{previous_signature}
#{OpenSSL::Digest::SHA256.hexdigest('')}
#{OpenSSL::Digest::SHA256.hexdigest(data)}
DATA
            hmac = signer.derived_hmac(date)
            hmac.sign(string_to_sign.strip).unpack('H*').first
          end