Class: Momento::CredentialProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/momento/auth/credential_provider.rb

Overview

Contains the information required for a Momento client to connect to and authenticate with Momento services.

Defined Under Namespace

Classes: AuthTokenData

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



7
8
9
# File 'lib/momento/auth/credential_provider.rb', line 7

def api_key
  @api_key
end

#cache_endpointObject (readonly)

Returns the value of attribute cache_endpoint.



7
8
9
# File 'lib/momento/auth/credential_provider.rb', line 7

def cache_endpoint
  @cache_endpoint
end

#control_endpointObject (readonly)

Returns the value of attribute control_endpoint.



7
8
9
# File 'lib/momento/auth/credential_provider.rb', line 7

def control_endpoint
  @control_endpoint
end

Class Method Details

.from_env_var(env_var_name) ⇒ Momento::CredentialProvider

Creates a CredentialProvider from a Momento API key loaded from an environment variable.

Parameters:

  • env_var_name (String)

    the environment variable containing the API key

Returns:

Raises:



13
14
15
16
17
18
# File 'lib/momento/auth/credential_provider.rb', line 13

def self.from_env_var(env_var_name)
  api_key = ENV.fetch(env_var_name) {
    raise Momento::Error::InvalidArgumentError, "Env var #{env_var_name} must be set"
  }
  new(api_key)
end

.from_string(api_key) ⇒ Momento::CredentialProvider

Creates a CredentialProvider from a Momento API key

Parameters:

  • api_key (String)

    the Momento API key

Returns:

Raises:



24
25
26
27
28
# File 'lib/momento/auth/credential_provider.rb', line 24

def self.from_string(api_key)
  raise Momento::Error::InvalidArgumentError, 'Auth token string cannot be empty' if api_key.empty?

  new(api_key)
end