Class: MinioRuby::Signer

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_keyObject (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

#dateObject (readonly)

Returns the value of attribute date.



11
12
13
# File 'lib/minio-ruby/signer.rb', line 11

def date
  @date
end

#headersObject (readonly)

Returns the value of attribute headers.



12
13
14
# File 'lib/minio-ruby/signer.rb', line 12

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



12
13
14
# File 'lib/minio-ruby/signer.rb', line 12

def method
  @method
end

#regionObject (readonly)

Returns the value of attribute region.



11
12
13
# File 'lib/minio-ruby/signer.rb', line 11

def region
  @region
end

#secret_keyObject (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

#serviceObject (readonly)

Returns the value of attribute service.



11
12
13
# File 'lib/minio-ruby/signer.rb', line 11

def service
  @service
end

#uriObject (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'] = get_authorization(headers)
  signed_headers
end