Module: Aws::RefreshingCredentials

Overview

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

  • @access_key_id
  • @secret_access_key
  • @session_token
  • @expiration

Constant Summary collapse

SYNC_EXPIRATION_LENGTH =

5 minutes

300
ASYNC_EXPIRATION_LENGTH =

10 minutes

600
CLIENT_EXCLUDE_OPTIONS =
Set.new([:before_refresh]).freeze

Instance Method Summary collapse

Instance Method Details

#credentialsCredentials

Returns:



29
30
31
32
# File 'gems/aws-sdk-core/lib/aws-sdk-core/refreshing_credentials.rb', line 29

def credentials
  refresh_if_near_expiration!
  @credentials
end

#initialize(options = {}) ⇒ Object



20
21
22
23
24
25
26
# File 'gems/aws-sdk-core/lib/aws-sdk-core/refreshing_credentials.rb', line 20

def initialize(options = {})
  @mutex = Mutex.new
  @before_refresh = options.delete(:before_refresh) if options.is_a?(Hash)

  @before_refresh.call(self) if @before_refresh
  refresh
end

#refresh!void

This method returns an undefined value.

Refresh credentials.



36
37
38
39
40
41
42
# File 'gems/aws-sdk-core/lib/aws-sdk-core/refreshing_credentials.rb', line 36

def refresh!
  @mutex.synchronize do
    @before_refresh.call(self) if @before_refresh

    refresh
  end
end