pub struct ClientConfig { /* private fields */ }Expand description
configuration for the infrahub client
Implementations§
Source§impl ClientConfig
impl ClientConfig
Sourcepub fn new(base_url: impl AsRef<str>, token: impl Into<String>) -> Self
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?
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
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}Sourcepub fn with_default_branch(self, branch: impl Into<String>) -> Self
pub fn with_default_branch(self, branch: impl Into<String>) -> Self
set the default branch for graphql queries
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
set the request timeout
default: 30 seconds
Sourcepub fn with_user_agent(self, user_agent: impl Into<String>) -> Self
pub fn with_user_agent(self, user_agent: impl Into<String>) -> Self
set a custom user agent string
Sourcepub fn with_ssl_verification(self, verify: bool) -> Self
pub fn with_ssl_verification(self, verify: bool) -> Self
disable ssl certificate verification (not recommended for production)
default: enabled
Sourcepub fn with_header(self, name: HeaderName, value: HeaderValue) -> Self
pub fn with_header(self, name: HeaderName, value: HeaderValue) -> Self
add a header to every request
Sourcepub fn with_headers(self, headers: HeaderMap) -> Self
pub fn with_headers(self, headers: HeaderMap) -> Self
add a set of headers to every request
Sourcepub fn extra_headers(&self) -> &HeaderMap
pub fn extra_headers(&self) -> &HeaderMap
access extra headers configured on this client
Sourcepub fn with_http_client(self, http_client: Client) -> Self
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.
Sourcepub fn with_http_client_builder<F>(self, f: F) -> Self
pub fn with_http_client_builder<F>(self, f: F) -> Self
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
impl Clone for ClientConfig
Source§fn clone(&self) -> ClientConfig
fn clone(&self) -> ClientConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more