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:

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:



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

def credentials
  refresh_if_near_expiration!
  @credentials
end

#initialize(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :before_refresh (Proc)

    A Proc called before credentials are refreshed. It accepts self as the only argument.



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

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.



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

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

    refresh
  end
end