Class: Nifcloud::Auth
- Inherits:
-
Object
- Object
- Nifcloud::Auth
- Defined in:
- lib/nifcloud/auth.rb
Overview
Authentication for nifcloud api v3
Direct Known Subclasses
Constant Summary collapse
- ALGORITHM =
'HmacSHA1'
Instance Attribute Summary collapse
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
-
#initialize(access_key, secret_key) ⇒ Auth
constructor
A new instance of Auth.
- #signature_header ⇒ Object
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
#time ⇒ Object (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_header ⇒ Object
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 |