Class: Conjur::API::APIKeyAuthenticator

Inherits:
Object
  • Object
show all
Includes:
TokenExpiration
Defined in:
lib/conjur/base.rb

Overview

When the API is constructed with an API key, the token can be refreshed using the username and API key. This authenticator assumes that the token was minted immediately before the API instance was created.

Constant Summary

Constants included from TokenExpiration

TokenExpiration::TOKEN_STALE

Instance Attribute Summary collapse

Attributes included from TokenExpiration

#token_born

Instance Method Summary collapse

Methods included from TokenExpiration

#needs_token_refresh?, #token_age

Methods included from MonotonicTime

#monotonic_time

Constructor Details

#initialize(account, username, api_key) ⇒ APIKeyAuthenticator

Returns a new instance of APIKeyAuthenticator.



190
191
192
193
194
195
# File 'lib/conjur/base.rb', line 190

def initialize , username, api_key
  @account = 
  @username = username
  @api_key = api_key
  update_token_born
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



188
189
190
# File 'lib/conjur/base.rb', line 188

def 
  @account
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



188
189
190
# File 'lib/conjur/base.rb', line 188

def api_key
  @api_key
end

#usernameObject (readonly)

Returns the value of attribute username.



188
189
190
# File 'lib/conjur/base.rb', line 188

def username
  @username
end

Instance Method Details

#gettimeObject



207
208
209
# File 'lib/conjur/base.rb', line 207

def gettime
  monotonic_time
end

#refresh_tokenObject



197
198
199
200
201
# File 'lib/conjur/base.rb', line 197

def refresh_token
  Conjur::API.authenticate(username, api_key, account: ).tap do
    update_token_born
  end
end

#update_token_bornObject



203
204
205
# File 'lib/conjur/base.rb', line 203

def update_token_born
  self.token_born = gettime
end