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