use crate::error::{ApiError, Result};
use reqwest::Client;
use serde_json::Value;
use url::Url;
pub struct SecurityClient {
base_url: String,
client: Client,
}
impl SecurityClient {
pub fn new(base_url: String, client: Client) -> Self {
Self { base_url, client }
}
pub fn with_auth(self, token: &str) -> Self {
self
}
pub async fn get_repo_security_overview(
&self,
repo: String,
types: Option<String>,
) -> Result<Value> {
let path = format!("/{}/-/security/overview", repo);
let mut url = Url::parse(&format!("{}{}", self.base_url, path))?;
if let Some(value) = types {
url.query_pairs_mut().append_pair("types", &value.to_string());
}
let request = self.client.request(
reqwest::Method::GET,
url
);
let response = request.send().await?;
if response.status().is_success() {
let json: Value = response.json().await?;
Ok(json)
} else {
Err(ApiError::HttpError(response.status().as_u16()))
}
}
}