module Aws::RefreshingCredentials

Base class used credential classes that can be refreshed. This provides basic refresh logic in a thread-safe manor. Classes mixing in this module are expected to implement a refresh method that populates the following instance variables:

@api private

Public Class Methods

new(options = {}) click to toggle source
# File lib/aws-sdk-core/refreshing_credentials.rb, line 18
def initialize(options = {})
  @mutex = Mutex.new
  refresh
end

Public Instance Methods

credentials() click to toggle source

@return [Credentials]

# File lib/aws-sdk-core/refreshing_credentials.rb, line 24
def credentials
  refresh_if_near_expiration
  @credentials
end
expiration() click to toggle source

@return [Time,nil]

# File lib/aws-sdk-core/refreshing_credentials.rb, line 30
def expiration
  refresh_if_near_expiration
  @expiration
end
refresh!() click to toggle source

Refresh credentials. @return [void]

# File lib/aws-sdk-core/refreshing_credentials.rb, line 37
def refresh!
  @mutex.synchronize { refresh }
end

Private Instance Methods

near_expiration?() click to toggle source
# File lib/aws-sdk-core/refreshing_credentials.rb, line 53
def near_expiration?
  if @expiration
    # are we within 5 minutes of expiration?
    (Time.now.to_i + 5 * 60) > @expiration.to_i
  else
    true
  end
end
refresh_if_near_expiration() click to toggle source

Refreshes instance metadata credentials if they are within 5 minutes of expiration.

# File lib/aws-sdk-core/refreshing_credentials.rb, line 45
def refresh_if_near_expiration
  if near_expiration?
    @mutex.synchronize do
      refresh if near_expiration?
    end
  end
end