proxmox_api/generated/access/tfa/userid/
id.rs1#[derive(Debug, Clone)]
2pub struct IdClient<T> {
3 client: T,
4 path: String,
5}
6impl<T> IdClient<T>
7where
8 T: crate::client::Client,
9{
10 pub fn new(client: T, parent_path: &str, id: &str) -> Self {
11 Self {
12 client,
13 path: format!("{}/{}", parent_path, id),
14 }
15 }
16}
17impl<T> IdClient<T>
18where
19 T: crate::client::Client,
20{
21 #[doc = "Delete a TFA entry by ID."]
22 #[doc = ""]
23 #[doc = "Permission check: or(userid-param(\"self\"), userid-group([\"User.Modify\"]))"]
24 pub async fn delete(&self, params: DeleteParams) -> Result<(), T::Error> {
25 let path = self.path.to_string();
26 self.client.delete(&path, ¶ms).await
27 }
28}
29impl<T> IdClient<T>
30where
31 T: crate::client::Client,
32{
33 #[doc = "Fetch a requested TFA entry if present."]
34 #[doc = ""]
35 #[doc = "Permission check: or(userid-param(\"self\"), userid-group([\"User.Modify\", \"Sys.Audit\"]))"]
36 pub async fn get(&self) -> Result<GetOutput, T::Error> {
37 let path = self.path.to_string();
38 self.client.get(&path, &()).await
39 }
40}
41impl<T> IdClient<T>
42where
43 T: crate::client::Client,
44{
45 #[doc = "Add a TFA entry for a user."]
46 #[doc = ""]
47 #[doc = "Permission check: or(userid-param(\"self\"), userid-group([\"User.Modify\"]))"]
48 pub async fn put(&self, params: PutParams) -> Result<(), T::Error> {
49 let path = self.path.to_string();
50 self.client.put(&path, ¶ms).await
51 }
52}
53#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, Default)]
54pub struct DeleteParams {
55 #[serde(skip_serializing_if = "Option::is_none", default)]
56 #[doc = "The current password of the user performing the change."]
57 #[doc = ""]
58 pub password: Option<PasswordStr>,
59 #[serde(
60 flatten,
61 default,
62 skip_serializing_if = "::std::collections::HashMap::is_empty"
63 )]
64 pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
65}
66impl GetOutput {
67 pub fn new(created: i64, description: String, id: String, ty: Type) -> Self {
68 Self {
69 created,
70 description,
71 id,
72 ty,
73 enable: ::std::default::Default::default(),
74 additional_properties: ::std::default::Default::default(),
75 }
76 }
77}
78#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
79pub struct GetOutput {
80 #[serde(
81 serialize_with = "crate::types::serialize_int",
82 deserialize_with = "crate::types::deserialize_int"
83 )]
84 #[doc = "Creation time of this entry as unix epoch."]
85 #[doc = ""]
86 pub created: i64,
87 #[doc = "User chosen description for this entry."]
88 #[doc = ""]
89 pub description: String,
90 #[serde(
91 serialize_with = "crate::types::serialize_bool_optional",
92 deserialize_with = "crate::types::deserialize_bool_optional"
93 )]
94 #[serde(skip_serializing_if = "Option::is_none", default)]
95 #[doc = "Whether this TFA entry is currently enabled."]
96 #[doc = ""]
97 pub enable: Option<bool>,
98 #[doc = "The id used to reference this entry."]
99 #[doc = ""]
100 pub id: String,
101 #[serde(rename = "type")]
102 #[doc = "TFA Entry Type."]
103 #[doc = ""]
104 pub ty: Type,
105 #[serde(
106 flatten,
107 default,
108 skip_serializing_if = "::std::collections::HashMap::is_empty"
109 )]
110 pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
111}
112#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, Default)]
113pub struct PutParams {
114 #[serde(skip_serializing_if = "Option::is_none", default)]
115 #[doc = "A description to distinguish multiple entries from one another"]
116 #[doc = ""]
117 pub description: Option<DescriptionStr>,
118 #[serde(
119 serialize_with = "crate::types::serialize_bool_optional",
120 deserialize_with = "crate::types::deserialize_bool_optional"
121 )]
122 #[serde(skip_serializing_if = "Option::is_none", default)]
123 #[doc = "Whether the entry should be enabled for login."]
124 #[doc = ""]
125 pub enable: Option<bool>,
126 #[serde(skip_serializing_if = "Option::is_none", default)]
127 #[doc = "The current password of the user performing the change."]
128 #[doc = ""]
129 pub password: Option<PasswordStr>,
130 #[serde(
131 flatten,
132 default,
133 skip_serializing_if = "::std::collections::HashMap::is_empty"
134 )]
135 pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
136}
137#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, PartialEq)]
138#[doc = "TFA Entry Type."]
139#[doc = ""]
140pub enum Type {
141 #[serde(rename = "recovery")]
142 Recovery,
143 #[serde(rename = "totp")]
144 Totp,
145 #[serde(rename = "u2f")]
146 U2f,
147 #[serde(rename = "webauthn")]
148 Webauthn,
149 #[serde(rename = "yubico")]
150 Yubico,
151}
152impl TryFrom<&str> for Type {
153 type Error = String;
154 fn try_from(value: &str) -> Result<Self, <Self as TryFrom<&str>>::Error> {
155 match value {
156 "recovery" => Ok(Self::Recovery),
157 "totp" => Ok(Self::Totp),
158 "u2f" => Ok(Self::U2f),
159 "webauthn" => Ok(Self::Webauthn),
160 "yubico" => Ok(Self::Yubico),
161 v => Err(format!("Unknown variant {v}")),
162 }
163 }
164}
165#[derive(Debug, Clone, PartialEq, PartialOrd)]
166pub struct DescriptionStr {
167 value: String,
168}
169impl crate::types::bounded_string::BoundedString for DescriptionStr {
170 const MIN_LENGTH: Option<usize> = None::<usize>;
171 const MAX_LENGTH: Option<usize> = Some(255usize);
172 const DEFAULT: Option<&'static str> = None::<&'static str>;
173 const PATTERN: Option<&'static str> = None::<&'static str>;
174 const TYPE_DESCRIPTION: &'static str = "a string with length at most 255";
175 fn get_value(&self) -> &str {
176 &self.value
177 }
178 fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
179 Self::validate(&value)?;
180 Ok(Self { value })
181 }
182}
183impl std::convert::TryFrom<String> for DescriptionStr {
184 type Error = crate::types::bounded_string::BoundedStringError;
185 fn try_from(value: String) -> Result<Self, Self::Error> {
186 crate::types::bounded_string::BoundedString::new(value)
187 }
188}
189impl ::serde::Serialize for DescriptionStr {
190 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
191 where
192 S: ::serde::Serializer,
193 {
194 crate::types::bounded_string::serialize_bounded_string(self, serializer)
195 }
196}
197impl<'de> ::serde::Deserialize<'de> for DescriptionStr {
198 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
199 where
200 D: ::serde::Deserializer<'de>,
201 {
202 crate::types::bounded_string::deserialize_bounded_string(deserializer)
203 }
204}
205#[derive(Debug, Clone, PartialEq, PartialOrd)]
206pub struct PasswordStr {
207 value: String,
208}
209impl crate::types::bounded_string::BoundedString for PasswordStr {
210 const MIN_LENGTH: Option<usize> = Some(5usize);
211 const MAX_LENGTH: Option<usize> = Some(64usize);
212 const DEFAULT: Option<&'static str> = None::<&'static str>;
213 const PATTERN: Option<&'static str> = None::<&'static str>;
214 const TYPE_DESCRIPTION: &'static str = "a string with length between 5 and 64";
215 fn get_value(&self) -> &str {
216 &self.value
217 }
218 fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
219 Self::validate(&value)?;
220 Ok(Self { value })
221 }
222}
223impl std::convert::TryFrom<String> for PasswordStr {
224 type Error = crate::types::bounded_string::BoundedStringError;
225 fn try_from(value: String) -> Result<Self, Self::Error> {
226 crate::types::bounded_string::BoundedString::new(value)
227 }
228}
229impl ::serde::Serialize for PasswordStr {
230 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
231 where
232 S: ::serde::Serializer,
233 {
234 crate::types::bounded_string::serialize_bounded_string(self, serializer)
235 }
236}
237impl<'de> ::serde::Deserialize<'de> for PasswordStr {
238 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
239 where
240 D: ::serde::Deserializer<'de>,
241 {
242 crate::types::bounded_string::deserialize_bounded_string(deserializer)
243 }
244}