Class: MinioRuby::Signer
- Inherits:
-
Object
- Object
- MinioRuby::Signer
- Defined in:
- lib/minio-ruby/signer.rb
Constant Summary collapse
- RFC8601BASIC =
"%Y%m%dT%H%M%SZ"
- SIGNV4ALGO =
'AWS4-HMAC-SHA256'
Instance Attribute Summary collapse
-
#access_key ⇒ Object
readonly
Returns the value of attribute access_key.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(config) ⇒ Signer
constructor
Initialize signer for calculating your signature.
-
#sign_v4(method, endpoint, headers, body = nil, debug = false) ⇒ Object
Signature v4 function returns back headers with Authorization header.
Constructor Details
#initialize(config) ⇒ Signer
Initialize signer for calculating your signature. Params: config
: configuration data with access keys and region.
17 18 19 20 21 22 23 |
# File 'lib/minio-ruby/signer.rb', line 17 def initialize(config) @access_key = config[:access_key] || config["access_key"] @secret_key = config[:secret_key] || config["secret_key"] @region = config[:region] || config["region"] @date = Time.now.utc.strftime(RFC8601BASIC) @service = "s3" end |
Instance Attribute Details
#access_key ⇒ Object (readonly)
Returns the value of attribute access_key.
11 12 13 |
# File 'lib/minio-ruby/signer.rb', line 11 def access_key @access_key end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
11 12 13 |
# File 'lib/minio-ruby/signer.rb', line 11 def date @date end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
12 13 14 |
# File 'lib/minio-ruby/signer.rb', line 12 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
12 13 14 |
# File 'lib/minio-ruby/signer.rb', line 12 def method @method end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
11 12 13 |
# File 'lib/minio-ruby/signer.rb', line 11 def region @region end |
#secret_key ⇒ Object (readonly)
Returns the value of attribute secret_key.
11 12 13 |
# File 'lib/minio-ruby/signer.rb', line 11 def secret_key @secret_key end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
11 12 13 |
# File 'lib/minio-ruby/signer.rb', line 11 def service @service end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
12 13 14 |
# File 'lib/minio-ruby/signer.rb', line 12 def uri @uri end |
Instance Method Details
#sign_v4(method, endpoint, headers, body = nil, debug = false) ⇒ Object
Signature v4 function returns back headers with Authorization header. Params: method
: http method. endpoint
: S3 endpoint URL.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/minio-ruby/signer.rb', line 29 def sign_v4(method, endpoint, headers, body = nil, debug = false) @method = method.upcase @endpoint = endpoint @headers = headers @uri = URI(endpoint) puts "EP : #{@endpoint}\nHeaders: #{@headers.to_s}" headers["X-Amz-Date"] = date headers["X-Amz-Content-Sha256"] = Digestor.hexdigest(body || '') headers['X-Amz-Expires'] = headers.delete 'expire_in' if headers['expire_in'] headers["Host"] = get_host(@uri) puts "--->" + get_host(@uri) dump if debug signed_headers = headers.dup signed_headers['Authorization'] = (headers) signed_headers end |