123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Auth::Aws::CredentialsCache Private

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/mongo/auth/aws/credentials_cache.rb

Overview

Thread safe cache to store AWS credentials.

Since:

  • 2.0.0

Class Method Summary

Instance Attribute Summary

Instance Method Summary

  • #clear Internal use only

    Clear the credentials from the cache.

  • #fetch ⇒ Aws::Credentials Internal use only

    Fetch the credentials from the cache or yield to get them if they are not in the cache or have expired.

Class Method Details

.instanceCredentialsCache

Get or create the singleton instance of the cache.

Returns:

  • (CredentialsCache)

    The singleton instance.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/auth/aws/credentials_cache.rb', line 28

def self.instance
  @instance ||= new
end

Instance Attribute Details

#credentialsAws::Credentials (rw)

Get the credentials from the cache.

Returns:

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/auth/aws/credentials_cache.rb', line 49

def credentials
  @lock.synchronize do
    @credentials
  end
end

#credentials=(credentials) (rw)

Set the credentials in the cache.

Parameters:

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/auth/aws/credentials_cache.rb', line 40

def credentials=(credentials)
  @lock.synchronize do
    @credentials = credentials
  end
end

Instance Method Details

#clear

Clear the credentials from the cache.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/auth/aws/credentials_cache.rb', line 67

def clear
  @lock.synchronize do
    @credentials = nil
  end
end

#fetchAws::Credentials

Fetch the credentials from the cache or yield to get them if they are not in the cache or have expired.

Returns:

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/auth/aws/credentials_cache.rb', line 59

def fetch
  @lock.synchronize do
    @credentials = yield if @credentials.nil? || @credentials.expired?
    @credentials
  end
end