feat(api): Allow re-use of existing reqwest client in CtApiClient struct

This commit is contained in:
Tyler Beckman 2024-10-27 16:11:47 -06:00
parent f526f859a5
commit 1c2b59e9f8
Signed by: Ty
GPG key ID: 2813440C772555A4

View file

@ -1,3 +1,5 @@
use std::sync::Arc;
use reqwest::Url; use reqwest::Url;
use responses::{ use responses::{
AddChainRequest, AddChainRequest,
@ -11,18 +13,25 @@ pub mod endpoints;
pub mod responses; pub mod responses;
pub struct CtApiClient { pub struct CtApiClient {
inner_client: reqwest::Client, inner_client: Arc<reqwest::Client>,
log_url: Url log_url: Url
} }
impl CtApiClient { impl CtApiClient {
pub fn new(log_url: Url) -> reqwest::Result<Self> { pub fn new(log_url: Url) -> reqwest::Result<Self> {
Ok(Self { Ok(Self {
inner_client: reqwest::Client::builder().https_only(true).build()?, inner_client: Arc::new(reqwest::Client::builder().https_only(true).build()?),
log_url log_url
}) })
} }
pub fn new_with_client(log_url: Url, inner_client: Arc<reqwest::Client>) -> Self {
Self {
inner_client,
log_url
}
}
/// Adds a standard x509 chain to the CT log. The log will then return /// Adds a standard x509 chain to the CT log. The log will then return
/// information needed to construct a valid SCT entry, including timestamp, /// information needed to construct a valid SCT entry, including timestamp,
/// CT log signature, sct version, and any log operator extensions. /// CT log signature, sct version, and any log operator extensions.