rust-cnb 0.1.2

[DEPRECATED - use `cnb` crate instead] rust-cnb with Generated API client
Documentation
//! Security API 客户端

use crate::error::{ApiError, Result};
use reqwest::Client;
use serde_json::Value;
use url::Url;

/// Security API 客户端
pub struct SecurityClient {
    base_url: String,
    client: Client,
}

impl SecurityClient {
    /// 创建新的 Security API 客户端
    pub fn new(base_url: String, client: Client) -> Self {
        Self { base_url, client }
    }

    /// 设置认证信息
    pub fn with_auth(self, token: &str) -> Self {
        // 这里可以扩展认证逻辑
        self
    }

    /// 查询仓库安全模块概览数据。Query the security overview data of a repository
    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()))
        }
    }

}