Class: Fog::AWS::Storage::Real::S3Streamer

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/aws/storage.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, signature, signer, date) ⇒ S3Streamer

Returns a new instance of S3Streamer.



736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
# File 'lib/fog/aws/storage.rb', line 736

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

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



735
736
737
# File 'lib/fog/aws/storage.rb', line 735

def body
  @body
end

#dateObject

Returns the value of attribute date.



735
736
737
# File 'lib/fog/aws/storage.rb', line 735

def date
  @date
end

#finishedObject

Returns the value of attribute finished.



735
736
737
# File 'lib/fog/aws/storage.rb', line 735

def finished
  @finished
end

#initial_signatureObject

Returns the value of attribute initial_signature.



735
736
737
# File 'lib/fog/aws/storage.rb', line 735

def initial_signature
  @initial_signature
end

#signatureObject

Returns the value of attribute signature.



735
736
737
# File 'lib/fog/aws/storage.rb', line 735

def signature
  @signature
end

#signerObject

Returns the value of attribute signer.



735
736
737
# File 'lib/fog/aws/storage.rb', line 735

def signer
  @signer
end

Instance Method Details

#callObject



760
761
762
763
764
765
766
# File 'lib/fog/aws/storage.rb', line 760

def call
  if finished
    ''
  else
    next_chunk
  end
end

#next_chunkObject



768
769
770
771
772
773
774
775
776
# File 'lib/fog/aws/storage.rb', line 768

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

#rewindObject

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



754
755
756
757
758
# File 'lib/fog/aws/storage.rb', line 754

def rewind
  self.signature = initial_signature
  self.finished = false
  body.rewind
end

#sign_chunk(data, previous_signature) ⇒ Object



779
780
781
782
783
784
785
786
787
788
789
790
# File 'lib/fog/aws/storage.rb', line 779

def sign_chunk(data, previous_signature)
  string_to_sign = "AWS4-HMAC-SHA256-PAYLOAD\n\#{date.to_iso8601_basic}\n\#{signer.credential_scope(date)}\n\#{previous_signature}\n\#{OpenSSL::Digest::SHA256.hexdigest('')}\n\#{OpenSSL::Digest::SHA256.hexdigest(data)}\n"
  hmac = signer.derived_hmac(date)
  hmac.sign(string_to_sign.strip).unpack('H*').first
end