use serde_json::Value;
use crate::error::Error;
pub async fn process_get_http_request(
shasta_token: &str,
api_url: String,
shasta_root_cert: &[u8],
socks5_proxy: Option<&str>,
) -> Result<Value, Error> {
let client_builder = reqwest::Client::builder()
.add_root_certificate(reqwest::Certificate::from_pem(shasta_root_cert)?);
let client = match socks5_proxy {
Some(proxy) => client_builder.proxy(reqwest::Proxy::all(proxy)?).build()?,
None => client_builder.build()?,
};
let response = client
.get(api_url)
.bearer_auth(shasta_token)
.send()
.await
.map_err(|e| Error::NetError(e))?;
match response.status().is_success() {
true => response.json().await.map_err(|e| Error::NetError(e)), false => {
let e: Value = response.json().await.map_err(|e| Error::NetError(e))?;
Err(Error::CsmError(e))
}
}
}