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],
) -> Result<Value, Error> {
let client_builder = reqwest::Client::builder()
.add_root_certificate(reqwest::Certificate::from_pem(shasta_root_cert)?);
let client = if std::env::var("SOCKS5").is_ok() {
log::debug!("SOCKS5 enabled");
let socks5proxy = reqwest::Proxy::all(std::env::var("SOCKS5").unwrap())?;
client_builder.proxy(socks5proxy).build()?
} else {
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))
}
}
}