123456789_123456789_123456789_123456789_123456789_

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

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.

Constructor Details

.newCredentialsCache

Since:

  • 2.0.0

[ GitHub ]

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

def initialize
  @lock = Mutex.new
  @credentials = nil
end

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 27

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 48

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 39

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 66

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 58

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