Class: Conjur::API::APIKeyAuthenticator
- Inherits:
-
Object
- Object
- Conjur::API::APIKeyAuthenticator
- 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
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Attributes included from TokenExpiration
Instance Method Summary collapse
- #gettime ⇒ Object
-
#initialize(username, api_key) ⇒ APIKeyAuthenticator
constructor
A new instance of APIKeyAuthenticator.
- #refresh_token ⇒ Object
- #update_token_born ⇒ Object
Methods included from TokenExpiration
#needs_token_refresh?, #token_age
Methods included from MonotonicTime
Constructor Details
#initialize(username, api_key) ⇒ APIKeyAuthenticator
Returns a new instance of APIKeyAuthenticator.
301 302 303 304 305 |
# File 'lib/conjur/base.rb', line 301 def initialize username, api_key @username = username @api_key = api_key update_token_born end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
299 300 301 |
# File 'lib/conjur/base.rb', line 299 def api_key @api_key end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
299 300 301 |
# File 'lib/conjur/base.rb', line 299 def username @username end |
Instance Method Details
#gettime ⇒ Object
317 318 319 |
# File 'lib/conjur/base.rb', line 317 def gettime monotonic_time end |
#refresh_token ⇒ Object
307 308 309 310 311 |
# File 'lib/conjur/base.rb', line 307 def refresh_token Conjur::API.authenticate(username, api_key).tap do update_token_born end end |
#update_token_born ⇒ Object
313 314 315 |
# File 'lib/conjur/base.rb', line 313 def update_token_born self.token_born = gettime end |