skill_web/api/
services.rs1use super::client::ApiClient;
4use super::error::ApiResult;
5use super::types::{
6 ServiceStatus, ServicesStatusResponse, StartServiceRequest, StartServiceResponse,
7 StopServiceRequest,
8};
9
10#[derive(Clone)]
12pub struct ServicesApi {
13 client: ApiClient,
14}
15
16impl ServicesApi {
17 pub fn new(client: ApiClient) -> Self {
19 Self { client }
20 }
21
22 pub async fn list(&self) -> ApiResult<Vec<ServiceStatus>> {
24 let response: ServicesStatusResponse = self.client.get("/services").await?;
25 Ok(response.services)
26 }
27
28 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 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 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 pub async fn start_kubectl_proxy(&self, port: Option<u16>) -> ApiResult<StartServiceResponse> {
53 self.start("kubectl-proxy", port).await
54 }
55
56 pub async fn stop_kubectl_proxy(&self) -> ApiResult<StartServiceResponse> {
58 self.stop("kubectl-proxy").await
59 }
60}