Class: Anthropic::Credentials::IdentityTokenFile
- Inherits:
-
Object
- Object
- Anthropic::Credentials::IdentityTokenFile
- Defined in:
- lib/anthropic/credentials/identity_token_file.rb
Overview
An identity token provider that reads a JWT from a file on every call.
Kubernetes projected service-account tokens (and similar) are rotated in place, so the file MUST be re-read on every invocation rather than cached. This provider is used as the identity_token_provider argument to WorkloadIdentity.
Instance Attribute Summary collapse
-
#path ⇒ Pathname
readonly
The resolved path to the identity token file.
Instance Method Summary collapse
-
#call ⇒ String
Reads and returns the identity token from the file.
-
#initialize(path = nil) ⇒ IdentityTokenFile
constructor
A new instance of IdentityTokenFile.
Constructor Details
#initialize(path = nil) ⇒ IdentityTokenFile
Returns a new instance of IdentityTokenFile.
19 20 21 22 23 24 25 26 |
# File 'lib/anthropic/credentials/identity_token_file.rb', line 19 def initialize(path = nil) resolved = resolve_path(path) if resolved.nil? raise Anthropic::Errors::ConfigurationError, "No identity token file path given. Pass path or set #{Credentials::ENV_IDENTITY_TOKEN_FILE}" end @path = Pathname.new(resolved) end |
Instance Attribute Details
#path ⇒ Pathname (readonly)
Returns the resolved path to the identity token file.
13 14 15 |
# File 'lib/anthropic/credentials/identity_token_file.rb', line 13 def path @path end |
Instance Method Details
#call ⇒ String
Reads and returns the identity token from the file.
The file is re-read on every call to handle token rotation.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/anthropic/credentials/identity_token_file.rb', line 35 def call content = @path.read.strip if content.empty? raise Anthropic::Errors::ConfigurationError, "Identity token file at #{@path} is empty" end content rescue Errno::ENOENT raise Anthropic::Errors::ConfigurationError, "Identity token file not found at #{@path}" rescue Errno::EACCES => e raise Anthropic::Errors::ConfigurationError, "Identity token file at #{@path} is not readable: #{e.}" rescue Errno::EISDIR raise Anthropic::Errors::ConfigurationError, "Identity token path #{@path} is a directory, not a file" end |