Class: CarrierWave::UCloud::Digest

Inherits:
Object
  • Object
show all
Defined in:
lib/carrierwave/ucloud/digest.rb

Class Method Summary collapse

Class Method Details

.authorization(uploader, req) ⇒ Object



5
6
7
8
# File 'lib/carrierwave/ucloud/digest.rb', line 5

def authorization(uploader, req)
  sign = sign(uploader, req)
  "UCloud #{uploader.public_key}:#{sign}"
end

.canonicalized_resource(uploader) ⇒ Object



26
27
28
# File 'lib/carrierwave/ucloud/digest.rb', line 26

def canonicalized_resource(uploader)
  "/#{uploader.ucloud_bucket}/#{uploader.store_path}"
end

.sign(uploader, req) ⇒ Object



10
11
12
13
14
# File 'lib/carrierwave/ucloud/digest.rb', line 10

def sign(uploader, req)
  string = string_to_sign(uploader, req)
  digest = OpenSSL::Digest.new('sha1')
  Base64.encode64(OpenSSL::HMAC.digest(digest, uploader.private_key, string))
end

.string_to_sign(uploader, req) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/carrierwave/ucloud/digest.rb', line 16

def string_to_sign(uploader, req)
  headers = req.headers
  http_verb = "#{req.method.upcase}\n"
  content_md5 = "\n"
  content_type = "#{headers['Content-Type']}\n"
  date = "\n"
  canonicalized_ucloud_headers = ''
  http_verb + content_md5 + content_type + date + canonicalized_ucloud_headers + canonicalized_resource(uploader)
end