Package com.openai.auth
Class K8sServiceAccountTokenProvider
-
- All Implemented Interfaces:
-
com.openai.auth.SubjectTokenProvider,java.lang.AutoCloseable
public final class K8sServiceAccountTokenProvider implements SubjectTokenProvider, AutoCloseable
A SubjectTokenProvider that reads a Kubernetes service account JWT from the filesystem.
By default, reads the token from
/var/run/secrets/kubernetes.io/serviceaccount/token, which is the default path Kubernetes mounts service account tokens to. A custom path can be provided via the builder.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classK8sServiceAccountTokenProvider.Builder
-
Method Summary
Modifier and Type Method Description SubjectTokenTypetokenType()Returns the format of the token produced by getToken and getTokenAsync. StringgetToken(HttpClient httpClient, JsonMapper jsonMapper)Synchronously fetches a subject token. CompletableFuture<String>getTokenAsync(HttpClient httpClient, JsonMapper jsonMapper)Asynchronously fetches a subject token. Unitclose()final static K8sServiceAccountTokenProvider.Builderbuilder()-
-
Method Detail
-
tokenType
SubjectTokenType tokenType()
Returns the format of the token produced by getToken and getTokenAsync.
-
getToken
String getToken(HttpClient httpClient, JsonMapper jsonMapper)
Synchronously fetches a subject token.
- Parameters:
httpClient- the HTTP client to use for any network requestsjsonMapper- the JSON mapper to use for deserializing responses- Returns:
the raw token string
-
getTokenAsync
CompletableFuture<String> getTokenAsync(HttpClient httpClient, JsonMapper jsonMapper)
Asynchronously fetches a subject token.
- Parameters:
httpClient- the HTTP client to use for any network requestsjsonMapper- the JSON mapper to use for deserializing responses- Returns:
a CompletableFuture that completes with the raw token string
-
builder
final static K8sServiceAccountTokenProvider.Builder builder()
-
-
-
-