Thalweg · API reference ← Main docs

Authenticator

Struct Authenticator 

Source
pub struct Authenticator<K: Clock> { /* private fields */ }
Expand description

Acquires and caches an OAuth2 client-credentials bearer token for Unity Catalog. Cheap to share; the token cache is internally synchronised.

Debug is implemented manually and never prints the client secret.

Implementations§

Source§

impl<K: Clock> Authenticator<K>

Source

pub const DEFAULT_TOKEN_PATH: &'static str = "/oidc/v1/token"

Default OAuth token endpoint on a Databricks workspace host.

Source

pub const DEFAULT_REFRESH_SKEW_S: i64 = 300

Default refresh skew: renew 5 minutes before expiry, so a long-running operation never crosses the expiry with a token it acquired just before.

Source

pub const MAX_TOKEN_TTL_S: i64 = 3600

Hard cap on how long a token is trusted, regardless of the endpoint’s expires_in. Unity Catalog / Databricks tokens live at most ~1 hour; if a response ever claims longer we still refresh within the hour rather than hold a token the server has already rotated.

Source

pub fn new( client_id: impl Into<String>, client_secret: impl Into<String>, clock: K, ) -> Self

Construct an authenticator with the default token path and refresh skew.

Source

pub fn with_token_path(self, path: impl Into<String>) -> Self

Builder: override the token endpoint path.

Source

pub fn with_refresh_skew(self, seconds: i64) -> Self

Builder: override how far ahead of expiry the token is refreshed.

Larger values refresh more eagerly (safer for long operations, at the cost of a few extra token exchanges); it is clamped to at least 0.

Source

pub async fn token(&self, client: &dyn UcClient) -> Result<String, AuthError>

Return a valid bearer token, reusing the cached one until it nears expiry and otherwise acquiring a fresh one via client.

§Errors

Returns AuthError if the token endpoint is unreachable, returns a non-success status, or returns a body that cannot be parsed.

Trait Implementations§

Source§

impl<K: Clock> Debug for Authenticator<K>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Redacts the client secret; the cached token is never printed.

Auto Trait Implementations§

§

impl<K> !Freeze for Authenticator<K>

§

impl<K> RefUnwindSafe for Authenticator<K>
where K: RefUnwindSafe,

§

impl<K> Send for Authenticator<K>

§

impl<K> Sync for Authenticator<K>

§

impl<K> Unpin for Authenticator<K>
where K: Unpin,

§

impl<K> UnwindSafe for Authenticator<K>
where K: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,