module Aws::RefreshingToken

def expiration

Returns:
  • (Time, nil) -
def expiration
  refresh_if_near_expiration
  @expiration
end

def initialize(options = {})

def initialize(options = {})
  @mutex = Mutex.new
  @before_refresh = options.delete(:before_refresh) if Hash === options
  @before_refresh.call(self) if @before_refresh
  refresh
end

def near_expiration?

def near_expiration?
  if @token && @token.expiration
    # are we within 5 minutes of expiration?
    (Time.now.to_i + 5 * 60) > @token.expiration.to_i
  else
    true
  end
end

def refresh!

Returns:
  • (void) -
def refresh!
  @mutex.synchronize do
    @before_refresh.call(self) if @before_refresh
    refresh
  end
end

def refresh_if_near_expiration

5 minutes of expiration.
Refreshes token if it is within
def refresh_if_near_expiration
  if near_expiration?
    @mutex.synchronize do
      if near_expiration?
        @before_refresh.call(self) if @before_refresh
        refresh
      end
    end
  end
end

def token

Returns:
  • (Token) -
def token
  refresh_if_near_expiration
  @token
end