Class: Legate::Auth::Credential
- Inherits:
-
Object
- Object
- Legate::Auth::Credential
- Defined in:
- lib/legate/auth/credential.rb
Overview
Represents authentication credentials required by different schemes. Handles different types of credentials such as API keys, OAuth2 client credentials, service account keys, and more.
Constant Summary collapse
- VALID_TYPES =
Valid credential types
%i[api_key oauth2 oidc service_account google_service_account http_bearer basic].freeze
- ENV_PREFIX =
Prefix for environment variable references
'ENV:'
Instance Attribute Summary collapse
-
#auth_type ⇒ Symbol
readonly
The type of authentication.
Instance Method Summary collapse
-
#[](name, resolve_env: true) ⇒ Object?
Get an attribute value.
-
#[]=(name, value) ⇒ Object
Set an attribute value.
-
#has_attribute?(name) ⇒ Boolean
Check if the credential has an attribute.
-
#initialize(auth_type:, **kwargs) ⇒ Credential
constructor
Initialize a new credential.
-
#to_h(resolve_env: false) ⇒ Hash
Convert to a hash.
Constructor Details
#initialize(auth_type:, **kwargs) ⇒ Credential
Initialize a new credential
36 37 38 39 40 41 42 |
# File 'lib/legate/auth/credential.rb', line 36 def initialize(auth_type:, **kwargs) @auth_type = auth_type.to_sym @attributes = kwargs validate_auth_type! validate_required_attributes! end |
Instance Attribute Details
#auth_type ⇒ Symbol (readonly)
Returns The type of authentication.
30 31 32 |
# File 'lib/legate/auth/credential.rb', line 30 def auth_type @auth_type end |
Instance Method Details
#[](name, resolve_env: true) ⇒ Object?
Get an attribute value
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/legate/auth/credential.rb', line 49 def [](name, resolve_env: true) attr_name = name.to_sym value = @attributes[attr_name] if resolve_env && value.is_a?(String) && value.start_with?(ENV_PREFIX) resolve_environment_variable(value) else value end end |
#[]=(name, value) ⇒ Object
Set an attribute value
63 64 65 |
# File 'lib/legate/auth/credential.rb', line 63 def []=(name, value) @attributes[name.to_sym] = value end |
#has_attribute?(name) ⇒ Boolean
Check if the credential has an attribute
87 88 89 |
# File 'lib/legate/auth/credential.rb', line 87 def has_attribute?(name) @attributes.key?(name.to_sym) end |
#to_h(resolve_env: false) ⇒ Hash
Convert to a hash
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/legate/auth/credential.rb', line 70 def to_h(resolve_env: false) result = { auth_type: @auth_type } @attributes.each do |key, value| result[key] = if resolve_env && value.is_a?(String) && value.start_with?(ENV_PREFIX) resolve_environment_variable(value) else value end end result end |