Skip to main content

proxmox_api/generated/access/
acl.rs

1#[derive(Debug, Clone)]
2pub struct AclClient<T> {
3    client: T,
4    path: String,
5}
6impl<T> AclClient<T>
7where
8    T: crate::client::Client,
9{
10    pub fn new(client: T, parent_path: &str) -> Self {
11        Self {
12            client,
13            path: format!("{}{}", parent_path, "/acl"),
14        }
15    }
16}
17impl<T> AclClient<T>
18where
19    T: crate::client::Client,
20{
21    #[doc = "Get Access Control List (ACLs)."]
22    #[doc = ""]
23    #[doc = "The returned list is restricted to objects where you have rights to modify permissions."]
24    pub async fn get(&self) -> Result<Vec<GetOutputItems>, T::Error> {
25        let path = self.path.to_string();
26        let optional_vec: Option<Vec<GetOutputItems>> = self.client.get(&path, &()).await?;
27        Ok(optional_vec.unwrap_or_default())
28    }
29}
30impl<T> AclClient<T>
31where
32    T: crate::client::Client,
33{
34    #[doc = "Update Access Control List (add or remove permissions)."]
35    #[doc = ""]
36    #[doc = "Permission check: perm-modify(\"{path}\")"]
37    pub async fn put(&self, params: PutParams) -> Result<(), T::Error> {
38        let path = self.path.to_string();
39        self.client.put(&path, &params).await
40    }
41}
42impl GetOutputItems {
43    pub fn new(path: String, roleid: String, ty: Type, ugid: String) -> Self {
44        Self {
45            path,
46            roleid,
47            ty,
48            ugid,
49            propagate: ::std::default::Default::default(),
50        }
51    }
52}
53#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
54pub struct GetOutputItems {
55    #[doc = "Access control path"]
56    #[doc = ""]
57    pub path: String,
58    #[serde(
59        serialize_with = "crate::types::serialize_bool_optional",
60        deserialize_with = "crate::types::deserialize_bool_optional"
61    )]
62    #[serde(skip_serializing_if = "Option::is_none", default)]
63    #[doc = "Allow to propagate (inherit) permissions."]
64    #[doc = ""]
65    pub propagate: Option<bool>,
66    pub roleid: String,
67    #[serde(rename = "type")]
68    pub ty: Type,
69    pub ugid: String,
70}
71impl PutParams {
72    pub fn new(path: String, roles: String) -> Self {
73        Self {
74            path,
75            roles,
76            delete: ::std::default::Default::default(),
77            groups: ::std::default::Default::default(),
78            propagate: ::std::default::Default::default(),
79            tokens: ::std::default::Default::default(),
80            users: ::std::default::Default::default(),
81            additional_properties: ::std::default::Default::default(),
82        }
83    }
84}
85#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
86pub struct PutParams {
87    #[serde(
88        serialize_with = "crate::types::serialize_bool_optional",
89        deserialize_with = "crate::types::deserialize_bool_optional"
90    )]
91    #[serde(skip_serializing_if = "Option::is_none", default)]
92    #[doc = "Remove permissions (instead of adding it)."]
93    #[doc = ""]
94    pub delete: Option<bool>,
95    #[serde(skip_serializing_if = "Option::is_none", default)]
96    #[doc = "List of groups."]
97    #[doc = ""]
98    pub groups: Option<String>,
99    #[doc = "Access control path"]
100    #[doc = ""]
101    pub path: String,
102    #[serde(
103        serialize_with = "crate::types::serialize_bool_optional",
104        deserialize_with = "crate::types::deserialize_bool_optional"
105    )]
106    #[serde(skip_serializing_if = "Option::is_none", default)]
107    #[doc = "Allow to propagate (inherit) permissions."]
108    #[doc = ""]
109    pub propagate: Option<bool>,
110    #[doc = "List of roles."]
111    #[doc = ""]
112    pub roles: String,
113    #[serde(skip_serializing_if = "Option::is_none", default)]
114    #[doc = "List of API tokens."]
115    #[doc = ""]
116    pub tokens: Option<String>,
117    #[serde(skip_serializing_if = "Option::is_none", default)]
118    #[doc = "List of users."]
119    #[doc = ""]
120    pub users: Option<String>,
121    #[serde(
122        flatten,
123        default,
124        skip_serializing_if = "::std::collections::HashMap::is_empty"
125    )]
126    pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
127}
128#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, PartialEq)]
129pub enum Type {
130    #[serde(rename = "group")]
131    Group,
132    #[serde(rename = "token")]
133    Token,
134    #[serde(rename = "user")]
135    User,
136}
137impl TryFrom<&str> for Type {
138    type Error = String;
139    fn try_from(value: &str) -> Result<Self, <Self as TryFrom<&str>>::Error> {
140        match value {
141            "group" => Ok(Self::Group),
142            "token" => Ok(Self::Token),
143            "user" => Ok(Self::User),
144            v => Err(format!("Unknown variant {v}")),
145        }
146    }
147}