class documentation
class Bearer(ParentBearer): (source)
Constructor: Bearer(file, refresh_period, metrics)
Bearer that provides file-backed Receiver instances.
The bearer accepts either a string path or a pathlib.Path
and expands the user's home directory. It does not validate the
existence of the file at construction time. Tokens are cached for
refresh_period seconds; pass 0 to keep a successfully-read token
cached until an authentication failure invalidates it.
Example
Construct a bearer and use it to initialize the SDK:
from nebius.sdk import SDK
from nebius.aio.token.file import Bearer
sdk = SDK(credentials=Bearer("~/nebius.token"))
| Parameters | |
| file | Filesystem path (string or pathlib.Path) to
the token file. Tilde expansion is performed. |
| refresh | Cache freshness window in seconds. Defaults to five minutes. |
| metrics | Optional auth metrics callbacks used to record file reads, cache hits, cache misses, and invalidations. |
| Method | __init__ |
Create a bearer for the given token file. |
| Method | fetch |
Return a cached file token or read and cache it from disk. |
| Method | receiver |
Return a Receiver that reads tokens from the file. |
| Method | set |
Attach auth metrics callbacks used by subsequently created receivers. |
| Method | should |
Invalidate cached token and return whether the file token changed. |
| Method | _invalidate |
Undocumented |
| Method | _read |
Undocumented |
| Instance Variable | _cached |
Undocumented |
| Instance Variable | _file |
Undocumented |
| Instance Variable | _metrics |
Undocumented |
| Instance Variable | _refresh |
Undocumented |
| Instance Variable | _refresh |
Undocumented |
Inherited from Bearer:
| Class Method | default |
Return this bearer's default fully qualified metric provider label. |
| Async Method | close |
Close the bearer and any wrapped resources. |
| Property | metrics |
Provider label used for auth metrics. |
| Property | name |
Optional human-readable name for the bearer. |
| Property | wrapped |
Return the wrapped bearer or None if not wrapping. |
def __init__(self, file:
str | Path, refresh_period: float = 5 * 60, metrics: AuthMetricsLike = None):
(source)
¶
Create a bearer for the given token file.