Class: Sndacs::Signature
- Inherits:
-
Object
- Object
- Sndacs::Signature
- Defined in:
- lib/sndacs/signature.rb
Overview
Class responsible for generating signatures to requests.
Implements algorithm defined by GrandCloud Web Services to sign request with secret private credentials
See
cs-console.grandcloud.cn/public/docs/GrandCloud_Storage_Developer_Guide.pdf
Class Method Summary collapse
-
.generate(options) ⇒ Object
Generates signature for given parameters.
-
.generate_temporary_url_signature(options) ⇒ Object
Generates temporary URL signature for given resource.
Class Method Details
.generate(options) ⇒ Object
Generates signature for given parameters
Options
-
:host
- Hostname -
:request
- Net::HTTPRequest object with correct headers -
:access_key_id
- Access key id -
:secret_access_key
- Secret access key
Returns
Generated signature string for given hostname and request
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sndacs/signature.rb', line 24 def self.generate() request = [:request] access_key_id = [:access_key_id] .merge!(:headers => request, :method => request.method, :resource => request.path) signature = canonicalized_signature() "SNDA #{access_key_id}:#{signature}" end |
.generate_temporary_url_signature(options) ⇒ Object
Generates temporary URL signature for given resource
Options
-
:bucket
- Bucket in which the resource resides -
:resource
- Path to the resouce you want to create a temporary link to -
:secret_access_key
- Secret access key -
:expires_at
- Unix time stamp of when the resouce link will expire -
:method
- HTTP request method you want to use on the resource, defaults to GET -
:headers
- Any additional HTTP headers you intend to use when requesting the resource
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/sndacs/signature.rb', line 48 def self.generate_temporary_url_signature() bucket = [:bucket] resource = [:resource] secret_access_key = [:secret_access_key] expires = [:expires_at] headers = [:headers] || {} headers.merge!("date" => expires.to_i.to_s) .merge!(:resource => "/#{bucket}/#{URI.escape(resource)}", :method => [:method] || :get, :headers => headers) signature = canonicalized_signature() CGI.escape(signature) end |