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

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo/auth/aws/credentials_cache.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Thread safe cache to store AWS credentials.

Since:

  • 2.0.0

API:

  • private

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCredentialsCache

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CredentialsCache.

Since:

  • 2.0.0

API:

  • private



32
33
34
35
# File 'lib/mongo/auth/aws/credentials_cache.rb', line 32

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

Class Method Details

.instanceCredentialsCache

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get or create the singleton instance of the cache.

Returns:

  • The singleton instance.

Since:

  • 2.0.0

API:

  • private



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

def self.instance
  @instance ||= new
end

Instance Method Details

#clearObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Clear the credentials from the cache.

Since:

  • 2.0.0

API:

  • private



67
68
69
70
71
# File 'lib/mongo/auth/aws/credentials_cache.rb', line 67

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

#credentialsAws::Credentials

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the credentials from the cache.

Returns:

  • The cached credentials.

Since:

  • 2.0.0

API:

  • private



49
50
51
52
53
# File 'lib/mongo/auth/aws/credentials_cache.rb', line 49

def credentials
  @lock.synchronize do
    @credentials
  end
end

#credentials=(credentials) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set the credentials in the cache.

Parameters:

  • The credentials to cache.

Since:

  • 2.0.0

API:

  • private



40
41
42
43
44
# File 'lib/mongo/auth/aws/credentials_cache.rb', line 40

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

#fetchAws::Credentials

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Returns:

  • The cached credentials.

Since:

  • 2.0.0

API:

  • private



59
60
61
62
63
64
# 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