rust_cnb/
security.rs

1//! Security API 客户端
2
3use crate::error::{ApiError, Result};
4use reqwest::Client;
5use serde_json::Value;
6use url::Url;
7
8/// Security API 客户端
9pub struct SecurityClient {
10    base_url: String,
11    client: Client,
12}
13
14impl SecurityClient {
15    /// 创建新的 Security API 客户端
16    pub fn new(base_url: String, client: Client) -> Self {
17        Self { base_url, client }
18    }
19
20    /// 设置认证信息
21    pub fn with_auth(self, token: &str) -> Self {
22        // 这里可以扩展认证逻辑
23        self
24    }
25
26    /// 查询仓库安全模块概览数据。Query the security overview data of a repository
27    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}