Class: Anthropic::Credentials::CredentialsFile
- Inherits:
-
ConfigProvider
- Object
- ConfigProvider
- Anthropic::Credentials::CredentialsFile
- Defined in:
- lib/anthropic/credentials/credentials_file.rb,
sig/anthropic/credentials.rbs
Overview
An access token provider backed by a named profile.
A profile is a pair of files under the config directory
(+~/.config/anthropic/+ by default; override with ANTHROPIC_CONFIG_DIR):
configs/<profile>.json-- non-secret. Holds the nestedauthenticationobject (discriminated by itstypefield), plus top-levelorganization_id,workspace_id, andbase_url. Theauthenticationobject may contain acredentials_pathfield overriding the credentials file location.credentials/<profile>.json-- secret (0600). Holdsaccess_token,expires_at, and (foruser_oauthwith aclient_id)refresh_token.
Dispatches on the authentication.type discriminator:
[+oidc_federation+]
OIDC workload identity federation. Lazily constructs a WorkloadIdentity
delegate from the nested auth fields plus the top-level organization_id
and calls it to perform the jwt-bearer exchange.
[+user_oauth+]
Output of an interactive PKCE login. The credentials file contains the
access_token (and optionally refresh_token). Currently refresh is not
implemented in Ruby; the credentials file is treated as externally rotated.
Instance Attribute Summary collapse
-
#config_path ⇒ Pathname
readonly
Path to the config file.
-
#profile ⇒ String
readonly
The profile name.
Instance Method Summary collapse
- #config_dir ⇒ Pathname
- #config_file_path(profile) ⇒ Pathname
- #credentials_file_path(profile) ⇒ Pathname
-
#initialize(profile = nil) ⇒ CredentialsFile
constructor
A new instance of CredentialsFile.
- #resolve_profile ⇒ String
Methods inherited from ConfigProvider
#auth_block, #bind_base_url, #build_workload_delegate, #call, #call_oidc_federation, #call_user_oauth, #coerce_expires_at, #extra_headers, #fill, #fill_missing_from_env, #read_credentials, #read_credentials_if_exists, #resolve_base_url, #resolve_identity_token_provider, #resolved_base_url, #write_credentials
Constructor Details
#initialize(profile = nil) ⇒ CredentialsFile
Returns a new instance of CredentialsFile.
38 39 40 41 42 43 |
# File 'lib/anthropic/credentials/credentials_file.rb', line 38 def initialize(profile = nil) super() @profile = profile || resolve_profile Anthropic::Config.validate_profile_name!(@profile) @config_path = config_file_path(@profile) end |
Instance Attribute Details
#config_path ⇒ Pathname (readonly)
Returns path to the config file.
34 35 36 |
# File 'lib/anthropic/credentials/credentials_file.rb', line 34 def config_path @config_path end |
#profile ⇒ String (readonly)
Returns the profile name.
31 32 33 |
# File 'lib/anthropic/credentials/credentials_file.rb', line 31 def profile @profile end |
Instance Method Details
#config_dir ⇒ Pathname
110 111 112 |
# File 'lib/anthropic/credentials/credentials_file.rb', line 110 def config_dir Anthropic::Credentials.config_dir end |
#config_file_path(profile) ⇒ Pathname
114 115 116 |
# File 'lib/anthropic/credentials/credentials_file.rb', line 114 def config_file_path(profile) Anthropic::Credentials.config_file_path(profile) end |
#credentials_file_path(profile) ⇒ Pathname
118 119 120 |
# File 'lib/anthropic/credentials/credentials_file.rb', line 118 def credentials_file_path(profile) Anthropic::Credentials.config_dir.join("credentials", "#{profile}.json") end |
#resolve_profile ⇒ String
106 107 108 |
# File 'lib/anthropic/credentials/credentials_file.rb', line 106 def resolve_profile Anthropic::Credentials.active_profile end |