Skip to main content

wekan_cli/client/boards/
domains.rs

1use reqwest::header::ACCEPT;
2use secrecy::{ExposeSecret, SecretString};
3use serde::Serialize;
4
5use super::{BoardDomain, ClientError, WekanClient};
6use crate::client::transport::decode_success;
7
8#[derive(Debug, Serialize)]
9pub struct AddBoardDomainRequest<'a> {
10    pub domain: &'a str,
11}
12
13impl WekanClient {
14    pub async fn board_domains(
15        &self,
16        board: &str,
17        token: &SecretString,
18    ) -> Result<Vec<BoardDomain>, ClientError> {
19        super::members::validate_id(board)?;
20        let body = self
21            .execute_success_request(
22                self.http
23                    .get(self.board_endpoint(board, Some("domains"))?)
24                    .header(ACCEPT, "application/json")
25                    .bearer_auth(token.expose_secret()),
26            )
27            .await?;
28        decode_success(&body, "board domain list", true)
29    }
30
31    pub async fn add_board_domain(
32        &self,
33        board: &str,
34        domain: &str,
35        token: &SecretString,
36    ) -> Result<Vec<BoardDomain>, ClientError> {
37        super::members::validate_id(board)?;
38        let body = self
39            .execute_success_request(
40                self.http
41                    .post(self.board_endpoint(board, Some("domains"))?)
42                    .header(ACCEPT, "application/json")
43                    .bearer_auth(token.expose_secret())
44                    .json(&AddBoardDomainRequest { domain }),
45            )
46            .await?;
47        decode_success(&body, "board domain add", true)
48    }
49
50    pub async fn remove_board_domain(
51        &self,
52        board: &str,
53        domain: &str,
54        token: &SecretString,
55    ) -> Result<Vec<BoardDomain>, ClientError> {
56        super::members::validate_id(board)?;
57        if domain.is_empty() || matches!(domain, "." | "..") {
58            return Err(ClientError::Protocol {
59                diagnostic: None,
60                message: "domain path values must not be empty or dot-only; no request was sent"
61                    .into(),
62                success_status_received: false,
63            });
64        }
65        let mut endpoint = self.board_endpoint(board, Some("domains"))?;
66        endpoint
67            .path_segments_mut()
68            .expect("server URL supports path segments")
69            .push(domain);
70        let body = self
71            .execute_success_request(
72                self.http
73                    .delete(endpoint)
74                    .header(ACCEPT, "application/json")
75                    .bearer_auth(token.expose_secret()),
76            )
77            .await?;
78        decode_success(&body, "board domain remove", true)
79    }
80}