security_client_rs/
spaces.rs1use serde::{Deserialize, Serialize};
3use serde_json::{Map, Value};
4
5use crate::{
6 Kibana, Scope,
7 http::{Empty, Method},
8 request::endpoint,
9};
10
11#[derive(Clone, Debug, Serialize, Deserialize)]
14#[non_exhaustive]
15pub struct Space {
16 pub id: String,
17 pub name: String,
18 #[serde(default, skip_serializing_if = "Option::is_none")]
19 pub description: Option<String>,
20 #[serde(default, rename = "disabledFeatures")]
21 pub disabled_features: Vec<String>,
22 #[serde(flatten)]
24 pub extra: Map<String, Value>,
25}
26
27impl Space {
28 pub fn new(id: impl Into<String>, name: impl Into<String>) -> Self {
29 Self {
30 id: id.into(),
31 name: name.into(),
32 description: None,
33 disabled_features: Vec::new(),
34 extra: Map::new(),
35 }
36 }
37}
38
39#[derive(Clone, Copy, Debug)]
40pub struct Spaces<'a>(pub(crate) &'a Kibana);
41
42impl<'a> Spaces<'a> {
43 pub fn list(&self) -> ListSpaces<'a> {
44 ListSpaces(
45 self.0
46 .request(Method::GET, Scope::Global, &["api", "spaces", "space"]),
47 )
48 }
49
50 pub fn get(&self, id: &str) -> GetSpace<'a> {
51 GetSpace(
52 self.0
53 .request(Method::GET, Scope::Global, &["api", "spaces", "space", id]),
54 )
55 }
56
57 pub fn create<B: Serialize + ?Sized>(&self, space: &B) -> CreateSpace<'a> {
59 CreateSpace(
60 self.0
61 .request(Method::POST, Scope::Global, &["api", "spaces", "space"])
62 .json(space),
63 )
64 }
65
66 pub fn update<B: Serialize + ?Sized>(&self, id: &str, space: &B) -> UpdateSpace<'a> {
70 UpdateSpace(
71 self.0
72 .request(Method::PUT, Scope::Global, &["api", "spaces", "space", id])
73 .json(space)
74 .check_body_id(id, true),
75 )
76 }
77
78 pub fn delete(&self, id: &str) -> DeleteSpace<'a> {
80 DeleteSpace(self.0.request(
81 Method::DELETE,
82 Scope::Global,
83 &["api", "spaces", "space", id],
84 ))
85 }
86}
87
88endpoint! {
89 ListSpaces => Vec<Space>
91}
92
93endpoint! {
94 GetSpace => Space
96}
97
98endpoint! {
99 CreateSpace => Space
101}
102
103endpoint! {
104 UpdateSpace => Space
106}
107
108endpoint! {
109 DeleteSpace => Empty
111}