Class: Keycardai::OAuth::FlyTokenSource

Inherits:
Object
  • Object
show all
Defined in:
lib/keycardai/oauth/token_sources.rb

Overview

Fetches an identity token from the Fly.io machines API over its local Unix socket.

Constant Summary collapse

DEFAULT_SOCKET_PATH =
"/.fly/api"
TOKEN_PATH =
"/v1/tokens/oidc"

Instance Method Summary collapse

Constructor Details

#initialize(audience: nil, socket_path: DEFAULT_SOCKET_PATH) ⇒ FlyTokenSource

Returns a new instance of FlyTokenSource.

Parameters:

  • audience (String, nil) (defaults to: nil)

    included as audience when set

  • socket_path (String) (defaults to: DEFAULT_SOCKET_PATH)


125
126
127
128
# File 'lib/keycardai/oauth/token_sources.rb', line 125

def initialize(audience: nil, socket_path: DEFAULT_SOCKET_PATH)
  @audience = audience
  @socket_path = socket_path
end

Instance Method Details

#identity_tokenString

Returns the current platform token.

Returns:

  • (String)

    the current platform token

Raises:



132
133
134
135
136
137
138
139
140
# File 'lib/keycardai/oauth/token_sources.rb', line 132

def identity_token
  body = JSON.dump(@audience ? { "aud" => @audience } : {})
  status, response_body = post_over_socket(body)
  unless (200..299).cover?(status)
    raise WorkloadIdentityRuntimeError.new("fly API returned HTTP #{status}", source: "fly")
  end

  response_body
end

#source_identifierObject



142
143
144
# File 'lib/keycardai/oauth/token_sources.rb', line 142

def source_identifier
  "fly"
end