Class: Momento::CredentialProvider
- Inherits:
-
Object
- Object
- Momento::CredentialProvider
- 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
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#cache_endpoint ⇒ Object
readonly
Returns the value of attribute cache_endpoint.
-
#control_endpoint ⇒ Object
readonly
Returns the value of attribute control_endpoint.
Class Method Summary collapse
-
.from_api_key_v2(api_key:, endpoint:) ⇒ Momento::CredentialProvider
Creates a CredentialProvider from a v2 API key string and endpoint.
-
.from_disposable_token(token) ⇒ Momento::CredentialProvider
Creates a CredentialProvider from a Momento disposable token.
-
.from_env_var(env_var_name) ⇒ Momento::CredentialProvider
deprecated
Deprecated.
Please use #from_env_var_v2 instead.
-
.from_env_var_v2(api_key_env_var: "MOMENTO_API_KEY", endpoint_env_var: "MOMENTO_ENDPOINT") ⇒ Momento::CredentialProvider
Creates a CredentialProvider from a v2 API key and endpoint loaded from environment variables MOMENTO_API_KEY and MOMENTO_ENDPOINT by default.
-
.from_string(api_key) ⇒ Momento::CredentialProvider
deprecated
Deprecated.
Please use #from_api_key_v2 or #from_disposable_token instead.
Instance Attribute Details
#api_key ⇒ Object (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_endpoint ⇒ Object (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_endpoint ⇒ Object (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_api_key_v2(api_key:, endpoint:) ⇒ Momento::CredentialProvider
Creates a CredentialProvider from a v2 API key string and endpoint.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/momento/auth/credential_provider.rb', line 47 def self.from_api_key_v2(api_key:, endpoint:) raise Momento::Error::InvalidArgumentError, 'API key cannot be empty' if api_key.nil? || api_key.empty? raise Momento::Error::InvalidArgumentError, 'Endpoint cannot be empty' if endpoint.nil? || endpoint.empty? unless v2_api_key?(api_key) raise Momento::Error::InvalidArgumentError, 'Received an invalid v2 API key. Are you using the correct key? \ Or did you mean to use `from_string()` with a legacy key instead?' end allocate.tap do |instance| instance.send(:initialize_from_v2, api_key, endpoint) end end |
.from_disposable_token(token) ⇒ Momento::CredentialProvider
Creates a CredentialProvider from a Momento disposable token
36 37 38 39 40 |
# File 'lib/momento/auth/credential_provider.rb', line 36 def self.from_disposable_token(token) raise Momento::Error::InvalidArgumentError, 'Auth token string cannot be empty' if token.empty? new(token) end |
.from_env_var(env_var_name) ⇒ Momento::CredentialProvider
Please use #from_env_var_v2 instead.
Creates a CredentialProvider from a Momento API key loaded from an environment variable.
14 15 16 17 18 19 |
# File 'lib/momento/auth/credential_provider.rb', line 14 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_env_var_v2(api_key_env_var: "MOMENTO_API_KEY", endpoint_env_var: "MOMENTO_ENDPOINT") ⇒ Momento::CredentialProvider
Creates a CredentialProvider from a v2 API key and endpoint loaded from environment variables MOMENTO_API_KEY and MOMENTO_ENDPOINT by default.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/momento/auth/credential_provider.rb', line 68 def self.from_env_var_v2(api_key_env_var: "MOMENTO_API_KEY", endpoint_env_var: "MOMENTO_ENDPOINT") api_key = ENV.fetch(api_key_env_var) { raise Momento::Error::InvalidArgumentError, "Env var #{api_key_env_var} must be set" } endpoint = ENV.fetch(endpoint_env_var) { raise Momento::Error::InvalidArgumentError, "Env var #{endpoint_env_var} must be set" } unless v2_api_key?(api_key) raise Momento::Error::InvalidArgumentError, 'Received an invalid v2 API key. Are you using the correct key? \ Or did you mean to use `from_env_var()` with a legacy key instead?' end allocate.tap do |instance| instance.send(:initialize_from_v2, api_key, endpoint) end end |
.from_string(api_key) ⇒ Momento::CredentialProvider
Please use #from_api_key_v2 or #from_disposable_token instead.
Creates a CredentialProvider from a Momento API key
26 27 28 29 30 |
# File 'lib/momento/auth/credential_provider.rb', line 26 def self.from_string(api_key) raise Momento::Error::InvalidArgumentError, 'Auth token string cannot be empty' if api_key.empty? new(api_key) end |