module AwsAssumeRole::Vendored::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_assume_role/vendored/aws/refreshing_credentials.rb, line 14
  def initialize(_options = {})
      @mutex = Mutex.new
      refresh
end

Public Instance Methods

credentials() click to toggle source

@return [Credentials]

# File lib/aws_assume_role/vendored/aws/refreshing_credentials.rb, line 20
def credentials
    refresh_if_near_expiration
    @credentials
end
expiration() click to toggle source

@return [Time,nil]

# File lib/aws_assume_role/vendored/aws/refreshing_credentials.rb, line 26
def expiration
    refresh_if_near_expiration
    @expiration
end
refresh!() click to toggle source

Refresh credentials. @return [void]

# File lib/aws_assume_role/vendored/aws/refreshing_credentials.rb, line 33
def refresh!
    @mutex.synchronize { refresh }
end

Private Instance Methods

near_expiration?() click to toggle source
# File lib/aws_assume_role/vendored/aws/refreshing_credentials.rb, line 49
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_assume_role/vendored/aws/refreshing_credentials.rb, line 41
def refresh_if_near_expiration
    if near_expiration?
        @mutex.synchronize do
            refresh if near_expiration?
        end
    end
end