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:
`@access_key_id`
`@secret_access_key`
`@session_token`
`@expiration`
@api private
# File lib/aws-sdk-core/refreshing_credentials.rb, line 18 def initialize(options = {}) @mutex = Mutex.new refresh end
@return [Credentials]
# File lib/aws-sdk-core/refreshing_credentials.rb, line 24 def credentials refresh_if_near_expiration @credentials end
@return [Time,nil]
# File lib/aws-sdk-core/refreshing_credentials.rb, line 30 def expiration refresh_if_near_expiration @expiration end
Refresh credentials. @return [void]
# File lib/aws-sdk-core/refreshing_credentials.rb, line 37 def refresh! @mutex.synchronize { refresh } end
# 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
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