skill_web/api/
services.rs

1//! System services API operations
2
3use super::client::ApiClient;
4use super::error::ApiResult;
5use super::types::{
6    ServiceStatus, ServicesStatusResponse, StartServiceRequest, StartServiceResponse,
7    StopServiceRequest,
8};
9
10/// Services API client
11#[derive(Clone)]
12pub struct ServicesApi {
13    client: ApiClient,
14}
15
16impl ServicesApi {
17    /// Create a new services API client
18    pub fn new(client: ApiClient) -> Self {
19        Self { client }
20    }
21
22    /// List all system services and their status
23    pub async fn list(&self) -> ApiResult<Vec<ServiceStatus>> {
24        let response: ServicesStatusResponse = self.client.get("/services").await?;
25        Ok(response.services)
26    }
27
28    /// Start a service
29    pub async fn start(&self, service: &str, port: Option<u16>) -> ApiResult<StartServiceResponse> {
30        let request = StartServiceRequest {
31            service: service.to_string(),
32            port,
33        };
34        self.client.post("/services/start", &request).await
35    }
36
37    /// Stop a service
38    pub async fn stop(&self, service: &str) -> ApiResult<StartServiceResponse> {
39        let request = StopServiceRequest {
40            service: service.to_string(),
41        };
42        self.client.post("/services/stop", &request).await
43    }
44
45    /// Check if kubectl proxy is running
46    pub async fn is_kubectl_proxy_running(&self) -> ApiResult<bool> {
47        let services = self.list().await?;
48        Ok(services.iter().any(|s| s.name == "kubectl-proxy" && s.running))
49    }
50
51    /// Start kubectl proxy
52    pub async fn start_kubectl_proxy(&self, port: Option<u16>) -> ApiResult<StartServiceResponse> {
53        self.start("kubectl-proxy", port).await
54    }
55
56    /// Stop kubectl proxy
57    pub async fn stop_kubectl_proxy(&self) -> ApiResult<StartServiceResponse> {
58        self.stop("kubectl-proxy").await
59    }
60}