Class: Cerberus::CerberusClientToken

Inherits:
Object
  • Object
show all
Defined in:
lib/cerberus/cerberus_client_token.rb

Overview

Object to hold the Cerberus client token credentials and check for expiration and refresh

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authToken, cacheLifetimeSec, policiesArray) ⇒ CerberusClientToken

Init with an authToken. Expired will be true approximately cacheLifetimeSec seconds from when new is called. Optionally, set the cache lifetime. For now this is primarily used for testing.



19
20
21
22
23
24
25
26
# File 'lib/cerberus/cerberus_client_token.rb', line 19

def initialize(authToken, cacheLifetimeSec, policiesArray)
  @createTime = Time.now
  @cacheLifetimeSec = cacheLifetimeSec
  @policies = policiesArray
  CerberusUtils::Log.instance.debug("AwsCredentials cache lifetime set to #{@cacheLifetimeSec} seconds")
  CerberusUtils::Log.instance.debug("AwsCredentials policies: #{@policies.join(", ")}")
  @authToken = authToken
end

Instance Attribute Details

#authTokenObject (readonly)

Returns the value of attribute authToken.



12
13
14
# File 'lib/cerberus/cerberus_client_token.rb', line 12

def authToken
  @authToken
end

#cacheLifetimeSecObject (readonly)

Returns the value of attribute cacheLifetimeSec.



13
14
15
# File 'lib/cerberus/cerberus_client_token.rb', line 13

def cacheLifetimeSec
  @cacheLifetimeSec
end

Instance Method Details

#expired?Boolean

Return true if cache lifetime has expired This object doesn’t enforce expiration - someone else can worry about making sure the credentials are valid

Returns:

  • (Boolean)


32
33
34
# File 'lib/cerberus/cerberus_client_token.rb', line 32

def expired?
  ((@createTime + @cacheLifetimeSec) <=> Time.now) == -1
end