1use crate::error::{ApiError, Result};
4use reqwest::Client;
5use serde_json::Value;
6use url::Url;
7
8pub struct SecurityClient {
10 base_url: String,
11 client: Client,
12}
13
14impl SecurityClient {
15 pub fn new(base_url: String, client: Client) -> Self {
17 Self { base_url, client }
18 }
19
20 pub fn with_auth(self, token: &str) -> Self {
22 self
24 }
25
26 pub async fn get_repo_security_overview(
28 &self,
29 repo: String,
30 types: Option<String>,
31 ) -> Result<Value> {
32 let path = format!("/{}/-/security/overview", repo);
33 let mut url = Url::parse(&format!("{}{}", self.base_url, path))?;
34
35 if let Some(value) = types {
36 url.query_pairs_mut().append_pair("types", &value.to_string());
37 }
38
39 let request = self.client.request(
40 reqwest::Method::GET,
41 url
42 );
43
44
45
46
47 let response = request.send().await?;
48
49 if response.status().is_success() {
50 let json: Value = response.json().await?;
51 Ok(json)
52 } else {
53 Err(ApiError::HttpError(response.status().as_u16()))
54 }
55 }
56
57}