Skip to main content

ClientConfig

Struct ClientConfig 

Source
pub struct ClientConfig { /* private fields */ }
Expand description

configuration for the infrahub client

Implementations§

Source§

impl ClientConfig

Source

pub fn new(base_url: impl AsRef<str>, token: impl Into<String>) -> Self

create a new client configuration

§arguments
  • base_url - the base url of the infrahub instance (with or without trailing slash)
  • token - the api authentication token
§example
use infrahub::ClientConfig;

let config = ClientConfig::new("https://infrahub.example.com", "your-token-here");
Examples found in repository?
examples/typed_query.rs (line 25)
20async fn main() -> Result<(), Box<dyn std::error::Error>> {
21    let base_url = env::var("INFRAHUB_URL").unwrap_or_else(|_| "http://localhost:8000".to_string());
22    let token = env::var("INFRAHUB_TOKEN").expect("INFRAHUB_TOKEN is required");
23    let branch = env::var("INFRAHUB_BRANCH").ok();
24
25    let config = ClientConfig::new(base_url, token);
26    let client = Client::new(config)?;
27
28    let response = client
29        .execute::<Data>(
30            "query { InfrahubInfo { deployment_id version } }",
31            None,
32            branch.as_deref(),
33        )
34        .await?;
35
36    println!("response: {response:?}");
37    Ok(())
38}
More examples
Hide additional examples
examples/simple_query.rs (line 10)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let base_url = env::var("INFRAHUB_URL").unwrap_or_else(|_| "http://localhost:8000".to_string());
7    let token = env::var("INFRAHUB_TOKEN").expect("INFRAHUB_TOKEN is required");
8    let branch = env::var("INFRAHUB_BRANCH").ok();
9
10    let config = ClientConfig::new(base_url, token);
11    let client = Client::new(config)?;
12
13    let response = client
14        .execute_raw(
15            "{ InfrahubInfo { deployment_id version } }",
16            None,
17            branch.as_deref(),
18        )
19        .await?;
20
21    println!("data: {}", response.data.unwrap_or_default());
22
23    Ok(())
24}
Source

pub fn with_default_branch(self, branch: impl Into<String>) -> Self

set the default branch for graphql queries

Source

pub fn with_timeout(self, timeout: Duration) -> Self

set the request timeout

default: 30 seconds

Source

pub fn with_user_agent(self, user_agent: impl Into<String>) -> Self

set a custom user agent string

Source

pub fn with_ssl_verification(self, verify: bool) -> Self

disable ssl certificate verification (not recommended for production)

default: enabled

Source

pub fn with_header(self, name: HeaderName, value: HeaderValue) -> Self

add a header to every request

Source

pub fn with_headers(self, headers: HeaderMap) -> Self

add a set of headers to every request

Source

pub fn extra_headers(&self) -> &HeaderMap

access extra headers configured on this client

Source

pub fn with_http_client(self, http_client: Client) -> Self

inject a prebuilt http client.

when set, this client is used as-is and takes precedence over with_http_client_builder. all transport configuration — auth headers, tls, timeouts, ssl verification, user agent — comes from the prebuilt client; the corresponding ClientConfig fields are ignored.

because auth is managed by the caller, an empty token is accepted when this option is set.

Source

pub fn with_http_client_builder<F>(self, f: F) -> Self
where F: Fn(ClientBuilder) -> ClientBuilder + Send + Sync + 'static,

customize the http client builder before the client is created.

the callback receives a builder that already has the auth header, extra headers, user agent, timeout, and ssl settings applied. use this to add proxy config, custom tls roots, or other transport settings without reimplementing the defaults.

ignored if with_http_client is also set.

Trait Implementations§

Source§

impl Clone for ClientConfig

Source§

fn clone(&self) -> ClientConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ClientConfig

Source§

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

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

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

Source§

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
Source§

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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