Class: Nifcloud::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/nifcloud/auth.rb

Overview

Authentication for nifcloud api v3

Direct Known Subclasses

Client

Constant Summary collapse

ALGORITHM =
'HmacSHA1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_key, secret_key) ⇒ Auth

Returns a new instance of Auth.



12
13
14
15
# File 'lib/nifcloud/auth.rb', line 12

def initialize(access_key, secret_key)
  @access_key = access_key || ENV.fetch('ACCESS_KEY', nil)
  @secret_key = secret_key || ENV.fetch('SECRET_KEY', nil)
end

Instance Attribute Details

#timeObject (readonly)

Returns the value of attribute time.



24
25
26
# File 'lib/nifcloud/auth.rb', line 24

def time
  @time
end

Instance Method Details

#signature_headerObject



17
18
19
20
21
22
# File 'lib/nifcloud/auth.rb', line 17

def signature_header
  @time = Time.now.httpdate
  hmac = HMAC::SHA1.new(@secret_key).update(@time)
  signature = Base64.encode64(hmac.digest.to_s)
  "NIFTY3-HTTPS NiftyAccessKeyId=#{@access_key},Algorithm=#{ALGORITHM},Signature=#{signature.chomp}"
end