VertexAIAuth

Struct VertexAIAuth 

pub struct VertexAIAuth { /* private fields */ }
Expand description

Vertex AI Bearer token authentication.

Uses a project/location pair to construct the Vertex AI WebSocket URL, and a Bearer token for the Authorization header.

Supports two token modes:

  • Fixed (new): token is set once at construction. Best for WebSocket connections where the token is only needed at connect time.
  • Refreshable (with_token_refresher): a closure is called on every auth_headers() invocation, ensuring fresh tokens for long-running HTTP clients (e.g., generate API calls).

Implementations§

§

impl VertexAIAuth

pub fn new( project: impl Into<String>, location: impl Into<String>, token: impl Into<String>, ) -> VertexAIAuth

Create a new Vertex AI auth provider with a fixed token.

The token is stored and reused for all requests. Use this for WebSocket connections where the token is only needed at connect time.

pub fn with_token_refresher( project: impl Into<String>, location: impl Into<String>, refresher: impl Fn() -> String + Send + Sync + 'static, ) -> VertexAIAuth

Create a Vertex AI auth provider with a dynamic token refresher.

The refresher closure is called on every auth_headers() invocation, allowing token refresh for long-running HTTP clients. The closure should handle caching internally to avoid unnecessary overhead.

Trait Implementations§

§

impl AuthProvider for VertexAIAuth

§

fn ws_url(&self, model: &GeminiModel) -> String

Build the WebSocket URL for the given model.
§

fn rest_url( &self, endpoint: ServiceEndpoint, model: Option<&GeminiModel>, ) -> String

Build a REST API URL for the given service endpoint and model. Read more
§

fn auth_headers<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<(String, String)>, AuthError>> + Send + 'async_trait>>
where 'life0: 'async_trait, VertexAIAuth: 'async_trait,

HTTP headers for the WebSocket upgrade request (e.g., Bearer token).
§

fn query_params(&self) -> Vec<(String, String)>

Query parameters to append to the URL (e.g., API key).
§

fn refresh<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), AuthError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Called on auth failure to allow token refresh. Default: no-op.

Auto Trait Implementations§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more