]> git.proxmox.com Git - proxmox-backup.git/blame - src/api2/types/mod.rs
key: make 'default' master key explicit
[proxmox-backup.git] / src / api2 / types / mod.rs
CommitLineData
bf78f708
DM
1//! API Type Definitions
2
e7cb4dc5
WB
3use anyhow::bail;
4use serde::{Deserialize, Serialize};
4ebf0eab 5
9ea4bce4
WB
6use proxmox::api::{api, schema::*};
7use proxmox::const_regex;
60b9b48e 8use proxmox::{IPRE, IPRE_BRACKET, IPV4RE, IPV6RE, IPV4OCTET, IPV6H16, IPV6LS32};
255f378a 9
bf78f708
DM
10use crate::{
11 backup::{
12 CryptMode,
13 Fingerprint,
14 BACKUP_ID_REGEX,
15 },
16 server::UPID,
17 config::acl::Role,
18};
f28d9088 19
e7cb4dc5
WB
20#[macro_use]
21mod macros;
22
23#[macro_use]
24mod userid;
25pub use userid::{Realm, RealmRef};
e0538349 26pub use userid::{Tokenname, TokennameRef};
e7cb4dc5
WB
27pub use userid::{Username, UsernameRef};
28pub use userid::Userid;
e0538349
FG
29pub use userid::Authid;
30pub use userid::{PROXMOX_TOKEN_ID_SCHEMA, PROXMOX_TOKEN_NAME_SCHEMA, PROXMOX_GROUP_ID_SCHEMA};
e7cb4dc5 31
a0765714
DM
32mod tape;
33pub use tape::*;
34
255f378a
DM
35// File names: may not contain slashes, may not start with "."
36pub const FILENAME_FORMAT: ApiStringFormat = ApiStringFormat::VerifyFn(|name| {
37 if name.starts_with('.') {
38 bail!("file names may not start with '.'");
39 }
40 if name.contains('/') {
41 bail!("file names may not contain slashes");
42 }
43 Ok(())
44});
45
b25f313d 46macro_rules! DNS_LABEL { () => (r"(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)") }
4c95d58c 47macro_rules! DNS_NAME { () => (concat!(r"(?:(?:", DNS_LABEL!() , r"\.)*", DNS_LABEL!(), ")")) }
255f378a 48
76cf5208
DM
49macro_rules! CIDR_V4_REGEX_STR { () => (concat!(r"(?:", IPV4RE!(), r"/\d{1,2})$")) }
50macro_rules! CIDR_V6_REGEX_STR { () => (concat!(r"(?:", IPV6RE!(), r"/\d{1,3})$")) }
51
255f378a 52const_regex!{
76cf5208
DM
53 pub IP_V4_REGEX = concat!(r"^", IPV4RE!(), r"$");
54 pub IP_V6_REGEX = concat!(r"^", IPV6RE!(), r"$");
55 pub IP_REGEX = concat!(r"^", IPRE!(), r"$");
56 pub CIDR_V4_REGEX = concat!(r"^", CIDR_V4_REGEX_STR!(), r"$");
57 pub CIDR_V6_REGEX = concat!(r"^", CIDR_V6_REGEX_STR!(), r"$");
58 pub CIDR_REGEX = concat!(r"^(?:", CIDR_V4_REGEX_STR!(), "|", CIDR_V6_REGEX_STR!(), r")$");
59
255f378a
DM
60 pub SHA256_HEX_REGEX = r"^[a-f0-9]{64}$"; // fixme: define in common_regex ?
61 pub SYSTEMD_DATETIME_REGEX = r"^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$"; // fixme: define in common_regex ?
d0adf270 62
da4a15a3
DM
63 pub PASSWORD_REGEX = r"^[[:^cntrl:]]*$"; // everything but control characters
64
d0adf270
DM
65 /// Regex for safe identifiers.
66 ///
67 /// This
68 /// [article](https://dwheeler.com/essays/fixing-unix-linux-filenames.html)
69 /// contains further information why it is reasonable to restict
70 /// names this way. This is not only useful for filenames, but for
71 /// any identifier command line tools work with.
163dc16c 72 pub PROXMOX_SAFE_ID_REGEX = concat!(r"^", PROXMOX_SAFE_ID_REGEX_STR!(), r"$");
454c13ed 73
dbd45a72
FG
74 /// Regex for verification jobs 'DATASTORE:ACTUAL_JOB_ID'
75 pub VERIFICATION_JOB_WORKER_ID_REGEX = concat!(r"^(", PROXMOX_SAFE_ID_REGEX_STR!(), r"):");
76 /// Regex for sync jobs 'REMOTE:REMOTE_DATASTORE:LOCAL_DATASTORE:ACTUAL_JOB_ID'
77 pub SYNC_JOB_WORKER_ID_REGEX = concat!(r"^(", PROXMOX_SAFE_ID_REGEX_STR!(), r"):(", PROXMOX_SAFE_ID_REGEX_STR!(), r"):(", PROXMOX_SAFE_ID_REGEX_STR!(), r"):");
78
454c13ed 79 pub SINGLE_LINE_COMMENT_REGEX = r"^[[:^cntrl:]]*$";
b25f313d
DM
80
81 pub HOSTNAME_REGEX = r"^(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)$";
82
ae62c4fe 83 pub DNS_NAME_REGEX = concat!(r"^", DNS_NAME!(), r"$");
b25f313d 84
4c95d58c 85 pub DNS_NAME_OR_IP_REGEX = concat!(r"^(?:", DNS_NAME!(), "|", IPRE!(), r")$");
163dc16c 86
34aa8e13 87 pub BACKUP_REPO_URL_REGEX = concat!(r"^^(?:(?:(", USER_ID_REGEX_STR!(), "|", APITOKEN_ID_REGEX_STR!(), ")@)?(", DNS_NAME!(), "|", IPRE_BRACKET!() ,"):)?(?:([0-9]{1,5}):)?(", PROXMOX_SAFE_ID_REGEX_STR!(), r")$");
090decbe 88
d5a48b5c 89 pub FINGERPRINT_SHA256_REGEX = r"^(?:[0-9a-fA-F][0-9a-fA-F])(?::[0-9a-fA-F][0-9a-fA-F]){31}$";
ed3e60ae 90
9765092e 91 pub ACL_PATH_REGEX = concat!(r"^(?:/|", r"(?:/", PROXMOX_SAFE_ID_REGEX_STR!(), ")+", r")$");
9069debc 92
926d2531
TL
93 pub SUBSCRIPTION_KEY_REGEX = concat!(r"^pbs(?:[cbsp])-[0-9a-f]{10}$");
94
9069debc 95 pub BLOCKDEVICE_NAME_REGEX = r"^(:?(:?h|s|x?v)d[a-z]+)|(:?nvme\d+n\d+)$";
7957fabf
DC
96
97 pub ZPOOL_NAME_REGEX = r"^[a-zA-Z][a-z0-9A-Z\-_.:]+$";
bc228e5e
DM
98
99 pub UUID_REGEX = r"^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$";
255f378a 100}
4ebf0eab 101
255f378a
DM
102pub const SYSTEMD_DATETIME_FORMAT: ApiStringFormat =
103 ApiStringFormat::Pattern(&SYSTEMD_DATETIME_REGEX);
4ebf0eab 104
76cf5208
DM
105pub const IP_V4_FORMAT: ApiStringFormat =
106 ApiStringFormat::Pattern(&IP_V4_REGEX);
107
108pub const IP_V6_FORMAT: ApiStringFormat =
109 ApiStringFormat::Pattern(&IP_V6_REGEX);
110
255f378a 111pub const IP_FORMAT: ApiStringFormat =
76cf5208 112 ApiStringFormat::Pattern(&IP_REGEX);
bbf9e7e9 113
255f378a
DM
114pub const PVE_CONFIG_DIGEST_FORMAT: ApiStringFormat =
115 ApiStringFormat::Pattern(&SHA256_HEX_REGEX);
116
d5a48b5c
DM
117pub const FINGERPRINT_SHA256_FORMAT: ApiStringFormat =
118 ApiStringFormat::Pattern(&FINGERPRINT_SHA256_REGEX);
dcb8db66 119
d0adf270
DM
120pub const PROXMOX_SAFE_ID_FORMAT: ApiStringFormat =
121 ApiStringFormat::Pattern(&PROXMOX_SAFE_ID_REGEX);
122
038ee599
DM
123pub const BACKUP_ID_FORMAT: ApiStringFormat =
124 ApiStringFormat::Pattern(&BACKUP_ID_REGEX);
125
bc228e5e
DM
126pub const UUID_FORMAT: ApiStringFormat =
127 ApiStringFormat::Pattern(&UUID_REGEX);
128
454c13ed
DM
129pub const SINGLE_LINE_COMMENT_FORMAT: ApiStringFormat =
130 ApiStringFormat::Pattern(&SINGLE_LINE_COMMENT_REGEX);
131
b25f313d
DM
132pub const HOSTNAME_FORMAT: ApiStringFormat =
133 ApiStringFormat::Pattern(&HOSTNAME_REGEX);
134
135pub const DNS_NAME_FORMAT: ApiStringFormat =
136 ApiStringFormat::Pattern(&DNS_NAME_REGEX);
137
138pub const DNS_NAME_OR_IP_FORMAT: ApiStringFormat =
139 ApiStringFormat::Pattern(&DNS_NAME_OR_IP_REGEX);
140
7e7b781a
DM
141pub const PASSWORD_FORMAT: ApiStringFormat =
142 ApiStringFormat::Pattern(&PASSWORD_REGEX);
143
ed3e60ae
DM
144pub const ACL_PATH_FORMAT: ApiStringFormat =
145 ApiStringFormat::Pattern(&ACL_PATH_REGEX);
146
68da20bf
DM
147pub const NETWORK_INTERFACE_FORMAT: ApiStringFormat =
148 ApiStringFormat::Pattern(&PROXMOX_SAFE_ID_REGEX);
454c13ed 149
76cf5208
DM
150pub const CIDR_V4_FORMAT: ApiStringFormat =
151 ApiStringFormat::Pattern(&CIDR_V4_REGEX);
152
153pub const CIDR_V6_FORMAT: ApiStringFormat =
154 ApiStringFormat::Pattern(&CIDR_V6_REGEX);
155
156pub const CIDR_FORMAT: ApiStringFormat =
157 ApiStringFormat::Pattern(&CIDR_REGEX);
158
926d2531
TL
159pub const SUBSCRIPTION_KEY_FORMAT: ApiStringFormat =
160 ApiStringFormat::Pattern(&SUBSCRIPTION_KEY_REGEX);
161
9069debc
DM
162pub const BLOCKDEVICE_NAME_FORMAT: ApiStringFormat =
163 ApiStringFormat::Pattern(&BLOCKDEVICE_NAME_REGEX);
76cf5208 164
685e1334
DM
165pub const PASSWORD_SCHEMA: Schema = StringSchema::new("Password.")
166 .format(&PASSWORD_FORMAT)
167 .min_length(1)
b88f9c5b 168 .max_length(1024)
685e1334
DM
169 .schema();
170
171pub const PBS_PASSWORD_SCHEMA: Schema = StringSchema::new("User Password.")
172 .format(&PASSWORD_FORMAT)
173 .min_length(5)
174 .max_length(64)
175 .schema();
dcb8db66
DM
176
177pub const CERT_FINGERPRINT_SHA256_SCHEMA: Schema = StringSchema::new(
178 "X509 certificate fingerprint (sha256)."
179)
d5a48b5c 180 .format(&FINGERPRINT_SHA256_FORMAT)
dcb8db66
DM
181 .schema();
182
d5a48b5c
DM
183pub const TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA: Schema = StringSchema::new(
184 "Tape encryption key fingerprint (sha256)."
255f378a 185)
d5a48b5c 186 .format(&FINGERPRINT_SHA256_FORMAT)
255f378a
DM
187 .schema();
188
d5a48b5c
DM
189pub const PROXMOX_CONFIG_DIGEST_SCHEMA: Schema = StringSchema::new(
190 "Prevent changes if current configuration file has different \
191 SHA256 digest. This can be used to prevent concurrent \
192 modifications."
193)
194 .format(&PVE_CONFIG_DIGEST_FORMAT) .schema();
195
255f378a
DM
196
197pub const CHUNK_DIGEST_FORMAT: ApiStringFormat =
198 ApiStringFormat::Pattern(&SHA256_HEX_REGEX);
199
200pub const CHUNK_DIGEST_SCHEMA: Schema = StringSchema::new("Chunk digest (SHA256).")
201 .format(&CHUNK_DIGEST_FORMAT)
202 .schema();
203
204pub const NODE_SCHEMA: Schema = StringSchema::new("Node name (or 'localhost')")
205 .format(&ApiStringFormat::VerifyFn(|node| {
206 if node == "localhost" || node == proxmox::tools::nodename() {
207 Ok(())
208 } else {
209 bail!("no such node '{}'", node);
210 }
211 }))
212 .schema();
213
214pub const SEARCH_DOMAIN_SCHEMA: Schema =
215 StringSchema::new("Search domain for host-name lookup.").schema();
216
217pub const FIRST_DNS_SERVER_SCHEMA: Schema =
218 StringSchema::new("First name server IP address.")
219 .format(&IP_FORMAT)
220 .schema();
221
222pub const SECOND_DNS_SERVER_SCHEMA: Schema =
223 StringSchema::new("Second name server IP address.")
224 .format(&IP_FORMAT)
225 .schema();
226
227pub const THIRD_DNS_SERVER_SCHEMA: Schema =
228 StringSchema::new("Third name server IP address.")
229 .format(&IP_FORMAT)
230 .schema();
231
76cf5208
DM
232pub const IP_V4_SCHEMA: Schema =
233 StringSchema::new("IPv4 address.")
234 .format(&IP_V4_FORMAT)
235 .max_length(15)
236 .schema();
237
238pub const IP_V6_SCHEMA: Schema =
239 StringSchema::new("IPv6 address.")
240 .format(&IP_V6_FORMAT)
241 .max_length(39)
242 .schema();
243
244pub const IP_SCHEMA: Schema =
245 StringSchema::new("IP (IPv4 or IPv6) address.")
246 .format(&IP_FORMAT)
247 .max_length(39)
248 .schema();
249
250pub const CIDR_V4_SCHEMA: Schema =
251 StringSchema::new("IPv4 address with netmask (CIDR notation).")
252 .format(&CIDR_V4_FORMAT)
253 .max_length(18)
254 .schema();
255
256pub const CIDR_V6_SCHEMA: Schema =
257 StringSchema::new("IPv6 address with netmask (CIDR notation).")
258 .format(&CIDR_V6_FORMAT)
259 .max_length(43)
260 .schema();
261
262pub const CIDR_SCHEMA: Schema =
263 StringSchema::new("IP address (IPv4 or IPv6) with netmask (CIDR notation).")
264 .format(&CIDR_FORMAT)
265 .max_length(43)
266 .schema();
267
4b40148c
DM
268pub const TIME_ZONE_SCHEMA: Schema = StringSchema::new(
269 "Time zone. The file '/usr/share/zoneinfo/zone.tab' contains the list of valid names.")
270 .format(&SINGLE_LINE_COMMENT_FORMAT)
271 .min_length(2)
272 .max_length(64)
273 .schema();
274
ca257c80
DM
275pub const ACL_PATH_SCHEMA: Schema = StringSchema::new(
276 "Access control path.")
277 .format(&ACL_PATH_FORMAT)
278 .min_length(1)
279 .max_length(128)
280 .schema();
281
282pub const ACL_PROPAGATE_SCHEMA: Schema = BooleanSchema::new(
283 "Allow to propagate (inherit) permissions.")
284 .default(true)
285 .schema();
286
287pub const ACL_UGID_TYPE_SCHEMA: Schema = StringSchema::new(
288 "Type of 'ugid' property.")
ca257c80 289 .format(&ApiStringFormat::Enum(&[
bc0d0388
DM
290 EnumEntry::new("user", "User"),
291 EnumEntry::new("group", "Group")]))
ca257c80
DM
292 .schema();
293
bf78f708
DM
294#[api(
295 properties: {
296 propagate: {
297 schema: ACL_PROPAGATE_SCHEMA,
298 },
299 path: {
300 schema: ACL_PATH_SCHEMA,
301 },
302 ugid_type: {
303 schema: ACL_UGID_TYPE_SCHEMA,
304 },
305 ugid: {
306 type: String,
307 description: "User or Group ID.",
308 },
309 roleid: {
310 type: Role,
311 }
312 }
313)]
314#[derive(Serialize, Deserialize)]
315/// ACL list entry.
316pub struct AclListItem {
317 pub path: String,
318 pub ugid: String,
319 pub ugid_type: String,
320 pub propagate: bool,
321 pub roleid: String,
322}
323
255f378a
DM
324pub const BACKUP_ARCHIVE_NAME_SCHEMA: Schema =
325 StringSchema::new("Backup archive name.")
1ae5677d 326 .format(&PROXMOX_SAFE_ID_FORMAT)
255f378a
DM
327 .schema();
328
329pub const BACKUP_TYPE_SCHEMA: Schema =
330 StringSchema::new("Backup type.")
bc0d0388
DM
331 .format(&ApiStringFormat::Enum(&[
332 EnumEntry::new("vm", "Virtual Machine Backup"),
333 EnumEntry::new("ct", "Container Backup"),
334 EnumEntry::new("host", "Host Backup")]))
255f378a
DM
335 .schema();
336
337pub const BACKUP_ID_SCHEMA: Schema =
338 StringSchema::new("Backup ID.")
038ee599 339 .format(&BACKUP_ID_FORMAT)
255f378a
DM
340 .schema();
341
342pub const BACKUP_TIME_SCHEMA: Schema =
343 IntegerSchema::new("Backup time (Unix epoch.)")
344 .minimum(1_547_797_308)
345 .schema();
5830c205
DM
346
347pub const UPID_SCHEMA: Schema = StringSchema::new("Unique Process/Task ID.")
348 .max_length(256)
349 .schema();
66c49c21
DM
350
351pub const DATASTORE_SCHEMA: Schema = StringSchema::new("Datastore name.")
d0adf270 352 .format(&PROXMOX_SAFE_ID_FORMAT)
688fbe07 353 .min_length(3)
66c49c21
DM
354 .max_length(32)
355 .schema();
fc189b19 356
bc228e5e 357pub const MEDIA_SET_UUID_SCHEMA: Schema =
f490dda0 358 StringSchema::new("MediaSet Uuid (We use the all-zero Uuid to reseve an empty media for a specific pool).")
bc228e5e
DM
359 .format(&UUID_FORMAT)
360 .schema();
361
362pub const MEDIA_UUID_SCHEMA: Schema =
363 StringSchema::new("Media Uuid.")
364 .format(&UUID_FORMAT)
365 .schema();
366
2888b27f
DC
367pub const SYNC_SCHEDULE_SCHEMA: Schema = StringSchema::new(
368 "Run sync job at specified schedule.")
369 .format(&ApiStringFormat::VerifyFn(crate::tools::systemd::time::verify_calendar_event))
370 .schema();
371
42fdbe51
DM
372pub const GC_SCHEDULE_SCHEMA: Schema = StringSchema::new(
373 "Run garbage collection job at specified schedule.")
374 .format(&ApiStringFormat::VerifyFn(crate::tools::systemd::time::verify_calendar_event))
375 .schema();
376
67f7ffd0
DM
377pub const PRUNE_SCHEDULE_SCHEMA: Schema = StringSchema::new(
378 "Run prune job at specified schedule.")
379 .format(&ApiStringFormat::VerifyFn(crate::tools::systemd::time::verify_calendar_event))
380 .schema();
381
78efafc2 382pub const VERIFICATION_SCHEDULE_SCHEMA: Schema = StringSchema::new(
f37ef25b
HL
383 "Run verify job at specified schedule.")
384 .format(&ApiStringFormat::VerifyFn(crate::tools::systemd::time::verify_calendar_event))
385 .schema();
386
167971ed
DM
387pub const REMOTE_ID_SCHEMA: Schema = StringSchema::new("Remote ID.")
388 .format(&PROXMOX_SAFE_ID_FORMAT)
389 .min_length(3)
390 .max_length(32)
391 .schema();
392
b4900286
DM
393pub const JOB_ID_SCHEMA: Schema = StringSchema::new("Job ID.")
394 .format(&PROXMOX_SAFE_ID_FORMAT)
395 .min_length(3)
396 .max_length(32)
397 .schema();
398
399pub const REMOVE_VANISHED_BACKUPS_SCHEMA: Schema = BooleanSchema::new(
400 "Delete vanished backups. This remove the local copy if the remote backup was deleted.")
401 .default(true)
402 .schema();
403
9b2bad7a
HL
404pub const IGNORE_VERIFIED_BACKUPS_SCHEMA: Schema = BooleanSchema::new(
405 "Do not verify backups that are already verified if their verification is not outdated.")
406 .default(true)
407 .schema();
408
409pub const VERIFICATION_OUTDATED_AFTER_SCHEMA: Schema = IntegerSchema::new(
410 "Days after that a verification becomes outdated")
411 .minimum(1)
412 .schema();
413
454c13ed
DM
414pub const SINGLE_LINE_COMMENT_SCHEMA: Schema = StringSchema::new("Comment (single line).")
415 .format(&SINGLE_LINE_COMMENT_FORMAT)
416 .schema();
fc189b19 417
b25f313d
DM
418pub const HOSTNAME_SCHEMA: Schema = StringSchema::new("Hostname (as defined in RFC1123).")
419 .format(&HOSTNAME_FORMAT)
420 .schema();
421
422pub const DNS_NAME_OR_IP_SCHEMA: Schema = StringSchema::new("DNS name or IP address.")
423 .format(&DNS_NAME_OR_IP_FORMAT)
424 .schema();
425
926d2531
TL
426pub const SUBSCRIPTION_KEY_SCHEMA: Schema = StringSchema::new("Proxmox Backup Server subscription key.")
427 .format(&SUBSCRIPTION_KEY_FORMAT)
428 .min_length(15)
429 .max_length(16)
430 .schema();
431
9069debc
DM
432pub const BLOCKDEVICE_NAME_SCHEMA: Schema = StringSchema::new("Block device name (/sys/block/<name>).")
433 .format(&BLOCKDEVICE_NAME_FORMAT)
434 .min_length(3)
435 .max_length(64)
436 .schema();
fc189b19
DM
437
438// Complex type definitions
439
455e5f71
FG
440#[api(
441 properties: {
442 store: {
443 schema: DATASTORE_SCHEMA,
444 },
445 comment: {
446 optional: true,
447 schema: SINGLE_LINE_COMMENT_SCHEMA,
448 },
449 },
450)]
451#[derive(Serialize, Deserialize)]
452#[serde(rename_all="kebab-case")]
453/// Basic information about a datastore.
454pub struct DataStoreListItem {
455 pub store: String,
456 pub comment: Option<String>,
457}
458
b31c8019
DM
459#[api(
460 properties: {
461 "backup-type": {
462 schema: BACKUP_TYPE_SCHEMA,
463 },
464 "backup-id": {
465 schema: BACKUP_ID_SCHEMA,
466 },
467 "last-backup": {
468 schema: BACKUP_TIME_SCHEMA,
469 },
470 "backup-count": {
471 type: Integer,
472 },
473 files: {
474 items: {
475 schema: BACKUP_ARCHIVE_NAME_SCHEMA
476 },
477 },
e7cb4dc5 478 owner: {
e6dc35ac 479 type: Authid,
e7cb4dc5
WB
480 optional: true,
481 },
b31c8019
DM
482 },
483)]
484#[derive(Serialize, Deserialize)]
485#[serde(rename_all="kebab-case")]
486/// Basic information about a backup group.
487pub struct GroupListItem {
488 pub backup_type: String, // enum
489 pub backup_id: String,
490 pub last_backup: i64,
491 /// Number of contained snapshots
492 pub backup_count: u64,
493 /// List of contained archive files.
494 pub files: Vec<String>,
04b0ca8b
DC
495 /// The owner of group
496 #[serde(skip_serializing_if="Option::is_none")]
e6dc35ac 497 pub owner: Option<Authid>,
b31c8019
DM
498}
499
d10332a1
SR
500#[api()]
501#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
502#[serde(rename_all = "lowercase")]
503/// Result of a verify operation.
504pub enum VerifyState {
505 /// Verification was successful
506 Ok,
507 /// Verification reported one or more errors
508 Failed,
509}
510
3b2046d2
TL
511#[api(
512 properties: {
513 upid: {
514 schema: UPID_SCHEMA
515 },
516 state: {
d10332a1 517 type: VerifyState
3b2046d2
TL
518 },
519 },
520)]
521#[derive(Serialize, Deserialize)]
522/// Task properties.
523pub struct SnapshotVerifyState {
524 /// UPID of the verify task
525 pub upid: UPID,
d10332a1
SR
526 /// State of the verification. Enum.
527 pub state: VerifyState,
3b2046d2
TL
528}
529
fc189b19 530#[api(
fc189b19
DM
531 properties: {
532 "backup-type": {
533 schema: BACKUP_TYPE_SCHEMA,
534 },
535 "backup-id": {
536 schema: BACKUP_ID_SCHEMA,
537 },
538 "backup-time": {
539 schema: BACKUP_TIME_SCHEMA,
540 },
5255e641
TL
541 comment: {
542 schema: SINGLE_LINE_COMMENT_SCHEMA,
543 optional: true,
544 },
3b2046d2
TL
545 verification: {
546 type: SnapshotVerifyState,
547 optional: true,
548 },
035c40e6
FG
549 fingerprint: {
550 type: String,
551 optional: true,
552 },
71da3d6a
DM
553 files: {
554 items: {
555 schema: BACKUP_ARCHIVE_NAME_SCHEMA
556 },
557 },
e7cb4dc5 558 owner: {
e6dc35ac 559 type: Authid,
e7cb4dc5
WB
560 optional: true,
561 },
fc189b19
DM
562 },
563)]
564#[derive(Serialize, Deserialize)]
565#[serde(rename_all="kebab-case")]
71da3d6a 566/// Basic information about backup snapshot.
fc189b19
DM
567pub struct SnapshotListItem {
568 pub backup_type: String, // enum
569 pub backup_id: String,
570 pub backup_time: i64,
70030b43
DM
571 /// The first line from manifest "notes"
572 #[serde(skip_serializing_if="Option::is_none")]
573 pub comment: Option<String>,
3b2046d2
TL
574 /// The result of the last run verify task
575 #[serde(skip_serializing_if="Option::is_none")]
576 pub verification: Option<SnapshotVerifyState>,
035c40e6
FG
577 /// Fingerprint of encryption key
578 #[serde(skip_serializing_if="Option::is_none")]
579 pub fingerprint: Option<Fingerprint>,
71da3d6a 580 /// List of contained archive files.
1c090810 581 pub files: Vec<BackupContent>,
71da3d6a 582 /// Overall snapshot size (sum of all archive sizes).
fc189b19
DM
583 #[serde(skip_serializing_if="Option::is_none")]
584 pub size: Option<u64>,
04b0ca8b
DC
585 /// The owner of the snapshots group
586 #[serde(skip_serializing_if="Option::is_none")]
e6dc35ac 587 pub owner: Option<Authid>,
fc189b19 588}
ff620a3d 589
db1e061d
DM
590#[api(
591 properties: {
592 "backup-type": {
593 schema: BACKUP_TYPE_SCHEMA,
594 },
595 "backup-id": {
596 schema: BACKUP_ID_SCHEMA,
597 },
598 "backup-time": {
599 schema: BACKUP_TIME_SCHEMA,
600 },
601 },
602)]
603#[derive(Serialize, Deserialize)]
604#[serde(rename_all="kebab-case")]
605/// Prune result.
606pub struct PruneListItem {
607 pub backup_type: String, // enum
608 pub backup_id: String,
609 pub backup_time: i64,
610 /// Keep snapshot
611 pub keep: bool,
612}
613
49ff1092
DM
614pub const PRUNE_SCHEMA_KEEP_DAILY: Schema = IntegerSchema::new(
615 "Number of daily backups to keep.")
616 .minimum(1)
617 .schema();
618
619pub const PRUNE_SCHEMA_KEEP_HOURLY: Schema = IntegerSchema::new(
620 "Number of hourly backups to keep.")
621 .minimum(1)
622 .schema();
623
624pub const PRUNE_SCHEMA_KEEP_LAST: Schema = IntegerSchema::new(
625 "Number of backups to keep.")
626 .minimum(1)
627 .schema();
628
629pub const PRUNE_SCHEMA_KEEP_MONTHLY: Schema = IntegerSchema::new(
630 "Number of monthly backups to keep.")
631 .minimum(1)
632 .schema();
633
634pub const PRUNE_SCHEMA_KEEP_WEEKLY: Schema = IntegerSchema::new(
635 "Number of weekly backups to keep.")
636 .minimum(1)
637 .schema();
638
639pub const PRUNE_SCHEMA_KEEP_YEARLY: Schema = IntegerSchema::new(
640 "Number of yearly backups to keep.")
641 .minimum(1)
642 .schema();
643
09b1f7b2
DM
644#[api(
645 properties: {
646 "filename": {
647 schema: BACKUP_ARCHIVE_NAME_SCHEMA,
648 },
f28d9088
WB
649 "crypt-mode": {
650 type: CryptMode,
651 optional: true,
652 },
09b1f7b2
DM
653 },
654)]
655#[derive(Serialize, Deserialize)]
656#[serde(rename_all="kebab-case")]
657/// Basic information about archive files inside a backup snapshot.
658pub struct BackupContent {
659 pub filename: String,
f28d9088 660 /// Info if file is encrypted, signed, or neither.
e181d2f6 661 #[serde(skip_serializing_if="Option::is_none")]
f28d9088 662 pub crypt_mode: Option<CryptMode>,
09b1f7b2
DM
663 /// Archive size (from backup manifest).
664 #[serde(skip_serializing_if="Option::is_none")]
665 pub size: Option<u64>,
666}
667
a92830dc
DM
668#[api(
669 properties: {
670 "upid": {
671 optional: true,
672 schema: UPID_SCHEMA,
673 },
674 },
675)]
676#[derive(Clone, Serialize, Deserialize)]
677#[serde(rename_all="kebab-case")]
678/// Garbage collection status.
679pub struct GarbageCollectionStatus {
680 pub upid: Option<String>,
681 /// Number of processed index files.
682 pub index_file_count: usize,
683 /// Sum of bytes referred by index files.
684 pub index_data_bytes: u64,
685 /// Bytes used on disk.
686 pub disk_bytes: u64,
687 /// Chunks used on disk.
688 pub disk_chunks: usize,
689 /// Sum of removed bytes.
690 pub removed_bytes: u64,
691 /// Number of removed chunks.
692 pub removed_chunks: usize,
cf459b19
DM
693 /// Sum of pending bytes (pending removal - kept for safety).
694 pub pending_bytes: u64,
695 /// Number of pending chunks (pending removal - kept for safety).
696 pub pending_chunks: usize,
a9767cf7
SR
697 /// Number of chunks marked as .bad by verify that have been removed by GC.
698 pub removed_bad: usize,
a2285525
DC
699 /// Number of chunks still marked as .bad after garbage collection.
700 pub still_bad: usize,
a92830dc
DM
701}
702
703impl Default for GarbageCollectionStatus {
704 fn default() -> Self {
705 GarbageCollectionStatus {
706 upid: None,
707 index_file_count: 0,
708 index_data_bytes: 0,
709 disk_bytes: 0,
710 disk_chunks: 0,
711 removed_bytes: 0,
712 removed_chunks: 0,
cf459b19
DM
713 pending_bytes: 0,
714 pending_chunks: 0,
a9767cf7 715 removed_bad: 0,
a2285525 716 still_bad: 0,
a92830dc
DM
717 }
718 }
719}
720
721
1dc117bb
DM
722#[api()]
723#[derive(Serialize, Deserialize)]
724/// Storage space usage information.
725pub struct StorageStatus {
726 /// Total space (bytes).
727 pub total: u64,
728 /// Used space (bytes).
729 pub used: u64,
730 /// Available space (bytes).
731 pub avail: u64,
732}
ff620a3d 733
14e08625
DC
734#[api()]
735#[derive(Serialize, Deserialize, Default)]
736/// Backup Type group/snapshot counts.
737pub struct TypeCounts {
738 /// The number of groups of the type.
739 pub groups: u64,
740 /// The number of snapshots of the type.
741 pub snapshots: u64,
742}
743
744#[api(
745 properties: {
746 ct: {
747 type: TypeCounts,
748 optional: true,
749 },
750 host: {
751 type: TypeCounts,
752 optional: true,
753 },
754 vm: {
755 type: TypeCounts,
756 optional: true,
757 },
758 other: {
759 type: TypeCounts,
760 optional: true,
761 },
762 },
763)]
fdfcb74d 764#[derive(Serialize, Deserialize, Default)]
14e08625
DC
765/// Counts of groups/snapshots per BackupType.
766pub struct Counts {
767 /// The counts for CT backups
768 pub ct: Option<TypeCounts>,
769 /// The counts for Host backups
770 pub host: Option<TypeCounts>,
771 /// The counts for VM backups
772 pub vm: Option<TypeCounts>,
773 /// The counts for other backup types
774 pub other: Option<TypeCounts>,
775}
776
777#[api(
778 properties: {
98afc7b1
FG
779 "gc-status": {
780 type: GarbageCollectionStatus,
781 optional: true,
782 },
783 counts: {
784 type: Counts,
785 optional: true,
786 },
14e08625
DC
787 },
788)]
789#[derive(Serialize, Deserialize)]
790#[serde(rename_all="kebab-case")]
791/// Overall Datastore status and useful information.
792pub struct DataStoreStatus {
793 /// Total space (bytes).
794 pub total: u64,
795 /// Used space (bytes).
796 pub used: u64,
797 /// Available space (bytes).
798 pub avail: u64,
799 /// Status of last GC
98afc7b1
FG
800 #[serde(skip_serializing_if="Option::is_none")]
801 pub gc_status: Option<GarbageCollectionStatus>,
14e08625 802 /// Group/Snapshot counts
98afc7b1
FG
803 #[serde(skip_serializing_if="Option::is_none")]
804 pub counts: Option<Counts>,
14e08625
DC
805}
806
99384f79
DM
807#[api(
808 properties: {
e7cb4dc5 809 upid: { schema: UPID_SCHEMA },
16245d54 810 user: { type: Authid },
99384f79
DM
811 },
812)]
813#[derive(Serialize, Deserialize)]
814/// Task properties.
815pub struct TaskListItem {
816 pub upid: String,
817 /// The node name where the task is running on.
818 pub node: String,
819 /// The Unix PID
820 pub pid: i64,
821 /// The task start time (Epoch)
822 pub pstart: u64,
823 /// The task start time (Epoch)
824 pub starttime: i64,
825 /// Worker type (arbitrary ASCII string)
826 pub worker_type: String,
827 /// Worker ID (arbitrary ASCII string)
828 pub worker_id: Option<String>,
e6dc35ac 829 /// The authenticated entity who started the task
16245d54 830 pub user: Authid,
99384f79
DM
831 /// The task end time (Epoch)
832 #[serde(skip_serializing_if="Option::is_none")]
833 pub endtime: Option<i64>,
834 /// Task end status
835 #[serde(skip_serializing_if="Option::is_none")]
836 pub status: Option<String>,
837}
838
df528ee6
DC
839impl From<crate::server::TaskListInfo> for TaskListItem {
840 fn from(info: crate::server::TaskListInfo) -> Self {
841 let (endtime, status) = info
842 .state
77bd2a46 843 .map_or_else(|| (None, None), |a| (Some(a.endtime()), Some(a.to_string())));
df528ee6
DC
844
845 TaskListItem {
846 upid: info.upid_str,
847 node: "localhost".to_string(),
848 pid: info.upid.pid as i64,
849 pstart: info.upid.pstart,
850 starttime: info.upid.starttime,
851 worker_type: info.upid.worker_type,
852 worker_id: info.upid.worker_id,
16245d54 853 user: info.upid.auth_id,
df528ee6
DC
854 endtime,
855 status,
856 }
857 }
858}
859
5976c392
DC
860#[api()]
861#[derive(Eq, PartialEq, Debug, Serialize, Deserialize)]
862#[serde(rename_all = "lowercase")]
863pub enum TaskStateType {
864 /// Ok
865 OK,
866 /// Warning
867 Warning,
868 /// Error
869 Error,
870 /// Unknown
871 Unknown,
872}
873
ed751dc2
DM
874#[api()]
875#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
876#[serde(rename_all = "lowercase")]
877/// Node Power command type.
878pub enum NodePowerCommand {
879 /// Restart the server
880 Reboot,
881 /// Shutdown the server
882 Shutdown,
883}
884
c357260d
DM
885#[api()]
886#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
887#[serde(rename_all = "lowercase")]
888/// Interface configuration method
889pub enum NetworkConfigMethod {
890 /// Configuration is done manually using other tools
891 Manual,
892 /// Define interfaces with statically allocated addresses.
893 Static,
894 /// Obtain an address via DHCP
895 DHCP,
896 /// Define the loopback interface.
897 Loopback,
898}
899
bab5d18c
DM
900#[api()]
901#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
902#[serde(rename_all = "kebab-case")]
903#[allow(non_camel_case_types)]
904#[repr(u8)]
905/// Linux Bond Mode
906pub enum LinuxBondMode {
907 /// Round-robin policy
908 balance_rr = 0,
909 /// Active-backup policy
910 active_backup = 1,
911 /// XOR policy
912 balance_xor = 2,
913 /// Broadcast policy
914 broadcast = 3,
915 /// IEEE 802.3ad Dynamic link aggregation
8f2f3dd7 916 #[serde(rename = "802.3ad")]
bab5d18c
DM
917 ieee802_3ad = 4,
918 /// Adaptive transmit load balancing
919 balance_tlb = 5,
920 /// Adaptive load balancing
921 balance_alb = 6,
922}
923
8f2f3dd7
DC
924#[api()]
925#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
926#[serde(rename_all = "kebab-case")]
927#[allow(non_camel_case_types)]
928#[repr(u8)]
929/// Bond Transmit Hash Policy for LACP (802.3ad)
930pub enum BondXmitHashPolicy {
931 /// Layer 2
932 layer2 = 0,
933 /// Layer 2+3
934 #[serde(rename = "layer2+3")]
935 layer2_3 = 1,
936 /// Layer 3+4
937 #[serde(rename = "layer3+4")]
938 layer3_4 = 2,
939}
940
02269f3d
DM
941#[api()]
942#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
943#[serde(rename_all = "lowercase")]
944/// Network interface type
945pub enum NetworkInterfaceType {
946 /// Loopback
947 Loopback,
948 /// Physical Ethernet device
7b22acd0 949 Eth,
02269f3d
DM
950 /// Linux Bridge
951 Bridge,
952 /// Linux Bond
953 Bond,
954 /// Linux VLAN (eth.10)
955 Vlan,
956 /// Interface Alias (eth:1)
957 Alias,
958 /// Unknown interface type
959 Unknown,
960}
961
68da20bf
DM
962pub const NETWORK_INTERFACE_NAME_SCHEMA: Schema = StringSchema::new("Network interface name.")
963 .format(&NETWORK_INTERFACE_FORMAT)
964 .min_length(1)
965 .max_length(libc::IFNAMSIZ-1)
966 .schema();
967
3aedb738 968pub const NETWORK_INTERFACE_ARRAY_SCHEMA: Schema = ArraySchema::new(
1d9a68c2
DM
969 "Network interface list.", &NETWORK_INTERFACE_NAME_SCHEMA)
970 .schema();
971
3aedb738
DM
972pub const NETWORK_INTERFACE_LIST_SCHEMA: Schema = StringSchema::new(
973 "A list of network devices, comma separated.")
974 .format(&ApiStringFormat::PropertyString(&NETWORK_INTERFACE_ARRAY_SCHEMA))
975 .schema();
976
c357260d
DM
977#[api(
978 properties: {
979 name: {
68da20bf 980 schema: NETWORK_INTERFACE_NAME_SCHEMA,
c357260d 981 },
7b22acd0 982 "type": {
02269f3d
DM
983 type: NetworkInterfaceType,
984 },
7b22acd0 985 method: {
c357260d
DM
986 type: NetworkConfigMethod,
987 optional: true,
988 },
7b22acd0 989 method6: {
c357260d
DM
990 type: NetworkConfigMethod,
991 optional: true,
992 },
7b22acd0
DM
993 cidr: {
994 schema: CIDR_V4_SCHEMA,
995 optional: true,
996 },
997 cidr6: {
998 schema: CIDR_V6_SCHEMA,
999 optional: true,
1000 },
1001 gateway: {
1002 schema: IP_V4_SCHEMA,
1003 optional: true,
1004 },
1005 gateway6: {
1006 schema: IP_V6_SCHEMA,
1007 optional: true,
1008 },
1009 options: {
c357260d
DM
1010 description: "Option list (inet)",
1011 type: Array,
1012 items: {
68da20bf 1013 description: "Optional attribute line.",
c357260d
DM
1014 type: String,
1015 },
1016 },
7b22acd0 1017 options6: {
c357260d
DM
1018 description: "Option list (inet6)",
1019 type: Array,
1020 items: {
68da20bf 1021 description: "Optional attribute line.",
c357260d
DM
1022 type: String,
1023 },
1024 },
7b22acd0 1025 comments: {
8a6b86b8
DM
1026 description: "Comments (inet, may span multiple lines)",
1027 type: String,
1028 optional: true,
5f60a58f 1029 },
7b22acd0 1030 comments6: {
8a6b86b8
DM
1031 description: "Comments (inet6, may span multiple lines)",
1032 type: String,
1033 optional: true,
5f60a58f 1034 },
1d9a68c2 1035 bridge_ports: {
3aedb738 1036 schema: NETWORK_INTERFACE_ARRAY_SCHEMA,
1d9a68c2
DM
1037 optional: true,
1038 },
bab5d18c 1039 slaves: {
3aedb738 1040 schema: NETWORK_INTERFACE_ARRAY_SCHEMA,
42fbe91a
DM
1041 optional: true,
1042 },
bab5d18c
DM
1043 bond_mode: {
1044 type: LinuxBondMode,
1045 optional: true,
85959a99
DC
1046 },
1047 "bond-primary": {
1048 schema: NETWORK_INTERFACE_NAME_SCHEMA,
1049 optional: true,
1050 },
8f2f3dd7
DC
1051 bond_xmit_hash_policy: {
1052 type: BondXmitHashPolicy,
1053 optional: true,
1054 },
c357260d
DM
1055 }
1056)]
1057#[derive(Debug, Serialize, Deserialize)]
1058/// Network Interface configuration
1059pub struct Interface {
1060 /// Autostart interface
7b22acd0
DM
1061 #[serde(rename = "autostart")]
1062 pub autostart: bool,
c357260d
DM
1063 /// Interface is active (UP)
1064 pub active: bool,
1065 /// Interface name
1066 pub name: String,
02269f3d 1067 /// Interface type
7b22acd0 1068 #[serde(rename = "type")]
02269f3d 1069 pub interface_type: NetworkInterfaceType,
c357260d 1070 #[serde(skip_serializing_if="Option::is_none")]
7b22acd0 1071 pub method: Option<NetworkConfigMethod>,
c357260d 1072 #[serde(skip_serializing_if="Option::is_none")]
7b22acd0 1073 pub method6: Option<NetworkConfigMethod>,
c357260d 1074 #[serde(skip_serializing_if="Option::is_none")]
8b57cd44 1075 /// IPv4 address with netmask
7b22acd0 1076 pub cidr: Option<String>,
c357260d
DM
1077 #[serde(skip_serializing_if="Option::is_none")]
1078 /// IPv4 gateway
7b22acd0 1079 pub gateway: Option<String>,
c357260d 1080 #[serde(skip_serializing_if="Option::is_none")]
8b57cd44 1081 /// IPv6 address with netmask
7b22acd0 1082 pub cidr6: Option<String>,
c357260d
DM
1083 #[serde(skip_serializing_if="Option::is_none")]
1084 /// IPv6 gateway
7b22acd0 1085 pub gateway6: Option<String>,
3fce3bc3 1086
c357260d 1087 #[serde(skip_serializing_if="Vec::is_empty")]
7b22acd0 1088 pub options: Vec<String>,
c357260d 1089 #[serde(skip_serializing_if="Vec::is_empty")]
7b22acd0 1090 pub options6: Vec<String>,
2c18efd9 1091
8a6b86b8 1092 #[serde(skip_serializing_if="Option::is_none")]
7b22acd0 1093 pub comments: Option<String>,
8a6b86b8 1094 #[serde(skip_serializing_if="Option::is_none")]
7b22acd0 1095 pub comments6: Option<String>,
5f60a58f 1096
2c18efd9
DM
1097 #[serde(skip_serializing_if="Option::is_none")]
1098 /// Maximum Transmission Unit
1099 pub mtu: Option<u64>,
1d9a68c2
DM
1100
1101 #[serde(skip_serializing_if="Option::is_none")]
1102 pub bridge_ports: Option<Vec<String>>,
7b22acd0
DM
1103 /// Enable bridge vlan support.
1104 #[serde(skip_serializing_if="Option::is_none")]
1105 pub bridge_vlan_aware: Option<bool>,
42fbe91a
DM
1106
1107 #[serde(skip_serializing_if="Option::is_none")]
bab5d18c
DM
1108 pub slaves: Option<Vec<String>>,
1109 #[serde(skip_serializing_if="Option::is_none")]
1110 pub bond_mode: Option<LinuxBondMode>,
85959a99
DC
1111 #[serde(skip_serializing_if="Option::is_none")]
1112 #[serde(rename = "bond-primary")]
1113 pub bond_primary: Option<String>,
8f2f3dd7 1114 pub bond_xmit_hash_policy: Option<BondXmitHashPolicy>,
c357260d
DM
1115}
1116
ff620a3d
DM
1117// Regression tests
1118
dcb8db66 1119#[test]
ff329f97 1120fn test_cert_fingerprint_schema() -> Result<(), anyhow::Error> {
dcb8db66
DM
1121
1122 let schema = CERT_FINGERPRINT_SHA256_SCHEMA;
1123
1124 let invalid_fingerprints = [
1125 "86:88:7c:be:26:77:a5:62:67:d9:06:f5:e4::61:3e:20:dc:cd:43:92:07:7f:fb:65:54:6c:ff:d2:96:36:f8",
1126 "88:7C:BE:26:77:a5:62:67:D9:06:f5:e4:14:61:3e:20:dc:cd:43:92:07:7f:fb:65:54:6c:ff:d2:96:36:f8",
1127 "86:88:7c:be:26:77:a5:62:67:d9:06:f5:e4::14:61:3e:20:dc:cd:43:92:07:7f:fb:65:54:6c:ff:d2:96:36:f8:ff",
1128 "XX:88:7c:be:26:77:a5:62:67:d9:06:f5:e4::14:61:3e:20:dc:cd:43:92:07:7f:fb:65:54:6c:ff:d2:96:36:f8",
1129 "86:88:Y4:be:26:77:a5:62:67:d9:06:f5:e4:14:61:3e:20:dc:cd:43:92:07:7f:fb:65:54:6c:ff:d2:96:36:f8",
1130 "86:88:0:be:26:77:a5:62:67:d9:06:f5:e4:14:61:3e:20:dc:cd:43:92:07:7f:fb:65:54:6c:ff:d2:96:36:f8",
1131 ];
1132
1133 for fingerprint in invalid_fingerprints.iter() {
3984a5fd 1134 if parse_simple_value(fingerprint, &schema).is_ok() {
add5861e 1135 bail!("test fingerprint '{}' failed - got Ok() while exception an error.", fingerprint);
dcb8db66
DM
1136 }
1137 }
1138
1139 let valid_fingerprints = [
1140 "86:88:7c:be:26:77:a5:62:67:d9:06:f5:e4:14:61:3e:20:dc:cd:43:92:07:7f:fb:65:54:6c:ff:d2:96:36:f8",
1141 "86:88:7C:BE:26:77:a5:62:67:D9:06:f5:e4:14:61:3e:20:dc:cd:43:92:07:7f:fb:65:54:6c:ff:d2:96:36:f8",
1142 ];
1143
1144 for fingerprint in valid_fingerprints.iter() {
1145 let v = match parse_simple_value(fingerprint, &schema) {
1146 Ok(v) => v,
1147 Err(err) => {
1148 bail!("unable to parse fingerprint '{}' - {}", fingerprint, err);
1149 }
1150 };
1151
1152 if v != serde_json::json!(fingerprint) {
1153 bail!("unable to parse fingerprint '{}' - got wrong value {:?}", fingerprint, v);
1154 }
1155 }
1156
1157 Ok(())
1158}
1159
ff620a3d 1160#[test]
ff329f97 1161fn test_proxmox_user_id_schema() -> Result<(), anyhow::Error> {
ff620a3d
DM
1162 let invalid_user_ids = [
1163 "x", // too short
1164 "xx", // too short
1165 "xxx", // no realm
1166 "xxx@", // no realm
1167 "xx x@test", // contains space
1168 "xx\nx@test", // contains control character
1169 "x:xx@test", // contains collon
1170 "xx/x@test", // contains slash
1171 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@test", // too long
1172 ];
1173
1174 for name in invalid_user_ids.iter() {
3984a5fd 1175 if parse_simple_value(name, &Userid::API_SCHEMA).is_ok() {
add5861e 1176 bail!("test userid '{}' failed - got Ok() while exception an error.", name);
ff620a3d
DM
1177 }
1178 }
1179
1180 let valid_user_ids = [
1181 "xxx@y",
1182 "name@y",
1183 "xxx@test-it.com",
1184 "xxx@_T_E_S_T-it.com",
1185 "x_x-x.x@test-it.com",
1186 ];
1187
1188 for name in valid_user_ids.iter() {
e7cb4dc5 1189 let v = match parse_simple_value(name, &Userid::API_SCHEMA) {
ff620a3d
DM
1190 Ok(v) => v,
1191 Err(err) => {
1192 bail!("unable to parse userid '{}' - {}", name, err);
1193 }
1194 };
1195
1196 if v != serde_json::json!(name) {
1197 bail!("unable to parse userid '{}' - got wrong value {:?}", name, v);
1198 }
1199 }
1200
1201 Ok(())
1202}
a2f862ee
DM
1203
1204#[api()]
1205#[derive(Copy, Clone, Serialize, Deserialize)]
1206#[serde(rename_all = "UPPERCASE")]
1207pub enum RRDMode {
1208 /// Maximum
1209 Max,
1210 /// Average
1211 Average,
1212}
1213
1214
1215#[api()]
1216#[repr(u64)]
1217#[derive(Copy, Clone, Serialize, Deserialize)]
1218#[serde(rename_all = "lowercase")]
1219pub enum RRDTimeFrameResolution {
1220 /// 1 min => last 70 minutes
1221 Hour = 60,
1222 /// 30 min => last 35 hours
1223 Day = 60*30,
1224 /// 3 hours => about 8 days
1225 Week = 60*180,
1226 /// 12 hours => last 35 days
1227 Month = 60*720,
1228 /// 1 week => last 490 days
1229 Year = 60*10080,
1230}
a4e86972
SR
1231
1232#[api()]
ed2beb33 1233#[derive(Debug, Clone, Serialize, Deserialize)]
a4e86972
SR
1234#[serde(rename_all = "PascalCase")]
1235/// Describes a package for which an update is available.
1236pub struct APTUpdateInfo {
1237 /// Package name
1238 pub package: String,
1239 /// Package title
1240 pub title: String,
1241 /// Package architecture
1242 pub arch: String,
1243 /// Human readable package description
1244 pub description: String,
1245 /// New version to be updated to
1246 pub version: String,
1247 /// Old version currently installed
1248 pub old_version: String,
1249 /// Package origin
1250 pub origin: String,
1251 /// Package priority in human-readable form
1252 pub priority: String,
1253 /// Package section
1254 pub section: String,
1255 /// URL under which the package's changelog can be retrieved
1256 pub change_log_url: String,
6f0073bb
TL
1257 /// Custom extra field for additional package information
1258 #[serde(skip_serializing_if="Option::is_none")]
2decf85d 1259 pub extra_info: Option<String>,
a4e86972 1260}
6e545d00
DM
1261
1262#[api()]
1263#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
1264#[serde(rename_all = "lowercase")]
1265/// When do we send notifications
1266pub enum Notify {
1267 /// Never send notification
1268 Never,
1269 /// Send notifications for failed and sucessful jobs
1270 Always,
1271 /// Send notifications for failed jobs only
1272 Error,
1273}
c26c9390
DM
1274
1275#[api(
1276 properties: {
1277 gc: {
1278 type: Notify,
1279 optional: true,
1280 },
1281 verify: {
1282 type: Notify,
1283 optional: true,
1284 },
1285 sync: {
1286 type: Notify,
1287 optional: true,
1288 },
1289 },
1290)]
1291#[derive(Debug, Serialize, Deserialize)]
1292/// Datastore notify settings
1293pub struct DatastoreNotify {
1294 /// Garbage collection settings
1295 pub gc: Option<Notify>,
1296 /// Verify job setting
1297 pub verify: Option<Notify>,
1298 /// Sync job setting
1299 pub sync: Option<Notify>,
1300}
1301
1302pub const DATASTORE_NOTIFY_STRING_SCHEMA: Schema = StringSchema::new(
1303 "Datastore notification setting")
1304 .format(&ApiStringFormat::PropertyString(&DatastoreNotify::API_SCHEMA))
1305 .schema();
82a103c8
DM
1306
1307
1308pub const PASSWORD_HINT_SCHEMA: Schema = StringSchema::new("Password hint.")
1309 .format(&SINGLE_LINE_COMMENT_FORMAT)
1310 .min_length(1)
1311 .max_length(64)
1312 .schema();
69b8bc3b
DM
1313
1314#[api(default: "scrypt")]
1315#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
1316#[serde(rename_all = "lowercase")]
1317/// Key derivation function for password protected encryption keys.
1318pub enum Kdf {
1319 /// Do not encrypt the key.
1320 None,
1321 /// Encrypt they key with a password using SCrypt.
1322 Scrypt,
1323 /// Encrtypt the Key with a password using PBKDF2
1324 PBKDF2,
1325}
1326
1327impl Default for Kdf {
1328 #[inline]
1329 fn default() -> Self {
1330 Kdf::Scrypt
1331 }
1332}
1333
1334#[api(
1335 properties: {
1336 kdf: {
1337 type: Kdf,
1338 },
1339 fingerprint: {
1340 schema: CERT_FINGERPRINT_SHA256_SCHEMA,
1341 optional: true,
1342 },
1343 },
1344)]
1345#[derive(Deserialize, Serialize)]
1346/// Encryption Key Information
1347pub struct KeyInfo {
1348 /// Path to key (if stored in a file)
1349 #[serde(skip_serializing_if="Option::is_none")]
1350 pub path: Option<String>,
1351 pub kdf: Kdf,
1352 /// Key creation time
1353 pub created: i64,
1354 /// Key modification time
1355 pub modified: i64,
1356 /// Key fingerprint
1357 #[serde(skip_serializing_if="Option::is_none")]
1358 pub fingerprint: Option<String>,
1359 /// Password hint
1360 #[serde(skip_serializing_if="Option::is_none")]
1361 pub hint: Option<String>,
1362}