Class: Keycardai::OAuth::FlyTokenSource
- Inherits:
-
Object
- Object
- Keycardai::OAuth::FlyTokenSource
- 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
-
#identity_token ⇒ String
The current platform token.
-
#initialize(audience: nil, socket_path: DEFAULT_SOCKET_PATH) ⇒ FlyTokenSource
constructor
A new instance of FlyTokenSource.
- #source_identifier ⇒ Object
Constructor Details
#initialize(audience: nil, socket_path: DEFAULT_SOCKET_PATH) ⇒ FlyTokenSource
Returns a new instance of FlyTokenSource.
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_token ⇒ String
Returns the current platform token.
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_identifier ⇒ Object
142 143 144 |
# File 'lib/keycardai/oauth/token_sources.rb', line 142 def source_identifier "fly" end |