Skip to main content

openlark_platform/admin/v1/
audit.rs

1//! 审计日志 API
2//!
3//! 当前仍是 runtime stub。
4//!
5//! 平台 admin 已接入的真实审计相关接口是 `audit_info/list.rs`,
6//! 当前这个更宽泛的 `audit` facade 并没有对应的已接线服务端端点。
7//! 为避免继续返回占位 JSON,本模块现在会显式返回未接线错误。
8
9use crate::PlatformConfig;
10use openlark_core::{SDKResult, error::business_error, req_option::RequestOption};
11use std::sync::Arc;
12
13/// 审计日志 facade。
14#[derive(Debug, Clone)]
15pub struct AuditApi {
16    config: Arc<PlatformConfig>,
17}
18
19impl AuditApi {
20    /// 创建新的审计日志 facade。
21    pub fn new(config: Arc<PlatformConfig>) -> Self {
22        Self { config }
23    }
24
25    /// 查询审计日志
26    pub fn query(&self) -> QueryAuditLogsRequest {
27        QueryAuditLogsRequest::new(self.config.clone())
28    }
29
30    /// 获取日志详情
31    pub fn get(&self) -> GetAuditLogRequest {
32        GetAuditLogRequest::new(self.config.clone())
33    }
34}
35
36/// 查询审计日志请求
37pub struct QueryAuditLogsRequest {
38    // reserved:待装访问器/execute(见 #274,不完整脚手架)
39    _config: Arc<PlatformConfig>,
40    start_time: Option<String>,
41    end_time: Option<String>,
42    page_size: Option<u32>,
43}
44
45impl QueryAuditLogsRequest {
46    fn new(config: Arc<PlatformConfig>) -> Self {
47        Self {
48            _config: config,
49            start_time: None,
50            end_time: None,
51            page_size: None,
52        }
53    }
54
55    /// 设置开始时间
56    pub fn start_time(mut self, time: impl Into<String>) -> Self {
57        self.start_time = Some(time.into());
58        self
59    }
60
61    /// 设置结束时间
62    pub fn end_time(mut self, time: impl Into<String>) -> Self {
63        self.end_time = Some(time.into());
64        self
65    }
66
67    /// 设置页面大小
68    pub fn page_size(mut self, size: u32) -> Self {
69        self.page_size = Some(size);
70        self
71    }
72
73    /// 执行请求
74    pub async fn execute(self) -> SDKResult<serde_json::Value> {
75        self.execute_with_options(RequestOption::default()).await
76    }
77
78    /// 执行请求并传入请求选项。
79    pub async fn execute_with_options(
80        self,
81        _option: RequestOption,
82    ) -> SDKResult<serde_json::Value> {
83        Err(business_error(
84            "admin.audit.query: openlark-platform 尚未接入该 facade,请改用已实现的 admin.audit_info.list 等真实端点",
85        ))
86    }
87}
88
89/// 获取日志详情请求
90pub struct GetAuditLogRequest {
91    // reserved:待装访问器/execute(见 #274,不完整脚手架)
92    _config: Arc<PlatformConfig>,
93    log_id: Option<String>,
94}
95
96impl GetAuditLogRequest {
97    fn new(config: Arc<PlatformConfig>) -> Self {
98        Self {
99            _config: config,
100            log_id: None,
101        }
102    }
103
104    /// 设置日志 ID
105    pub fn log_id(mut self, log_id: impl Into<String>) -> Self {
106        self.log_id = Some(log_id.into());
107        self
108    }
109
110    /// 执行请求
111    pub async fn execute(self) -> SDKResult<serde_json::Value> {
112        self.execute_with_options(RequestOption::default()).await
113    }
114
115    /// 执行请求并传入请求选项。
116    pub async fn execute_with_options(
117        self,
118        _option: RequestOption,
119    ) -> SDKResult<serde_json::Value> {
120        Err(business_error(
121            "admin.audit.get: openlark-platform 尚未接入该 facade,请改用已实现的 admin.audit_info.list 等真实端点",
122        ))
123    }
124}
125
126#[cfg(test)]
127mod tests {
128    use super::*;
129
130    #[tokio::test]
131    async fn test_audit_stub_returns_explicit_error() {
132        let config = Arc::new(PlatformConfig::default());
133        let err = AuditApi::new(config)
134            .query()
135            .start_time("2026-01-01")
136            .end_time("2026-01-31")
137            .execute()
138            .await
139            .expect_err("audit stub should now fail explicitly");
140        assert!(err.to_string().contains("尚未接入"));
141    }
142}