Class FileCredential
java.lang.Object
io.superdurable.dex.FileCredential
- All Implemented Interfaces:
Credential
Reads a bearer token from a file and picks up rotations without a restart.
Construction reads the file immediately. Calls check its modification time and size at most once per second and reread changed content. Surrounding whitespace is removed. An empty or unreadable file fails calls until a later check succeeds; no stale token is sent. Concurrent callers share a short lock. Prefer atomic replacement when rotating the file.
Credential credential = new FileCredential("/var/run/secrets/dex/token");
ClientOptions clientOptions = ClientOptions.newBuilder().credential(credential).build();
WorkerOptions workerOptions = WorkerOptions.newBuilder().credential(credential).build();
-
Constructor Summary
ConstructorsConstructorDescriptionFileCredential(String path) Reads the initial token from a file path.FileCredential(Path path) Reads the initial token from a file. -
Method Summary
-
Constructor Details
-
FileCredential
Reads the initial token from a file path.- Parameters:
path- the token file path- Throws:
IllegalArgumentException- if path is null or invalidIOException- if the file cannot be read or contains only whitespace
-
FileCredential
Reads the initial token from a file.- Parameters:
path- the nonnull token file path- Throws:
IllegalArgumentException- if path is nullIOException- if the file cannot be read or contains only whitespace
-
-
Method Details
-
token
Returns the cached token after any due file check.A changed file is reloaded on the next check, at most one second after the previous check. This method is safe for concurrent callers.
- Specified by:
tokenin interfaceCredential- Returns:
- the current token without surrounding whitespace
- Throws:
IOException- if the file is unreadable or empty after trimming
-
toString
-