Module: Conjur::API::TokenExpiration

Included in:
APIKeyAuthenticator, LocalAuthenticator
Defined in:
lib/conjur/base.rb

Constant Summary collapse

TOKEN_STALE =

The four minutes is to work around a bug in Conjur < 4.7 causing a 404 on long-running operations (when the token is used right around the 5 minute mark).

4.minutes

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#token_bornObject

Returns the value of attribute token_born.



182
183
184
# File 'lib/conjur/base.rb', line 182

def token_born
  @token_born
end

Instance Method Details

#gettimeObject



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

def gettime
  Process.clock_gettime Process::CLOCK_MONOTONIC
rescue
  # fall back to normal clock if there's no CLOCK_MONOTONIC
  Time.now.to_f
end

#needs_token_refresh?Boolean

Returns:

  • (Boolean)


184
185
186
# File 'lib/conjur/base.rb', line 184

def needs_token_refresh?
  token_age > TOKEN_STALE
end

#token_ageObject



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

def token_age
  gettime - token_born
end

#update_token_bornObject



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

def update_token_born
  self.token_born = gettime
end