From: Wolfgang Bumiller Date: Fri, 8 Oct 2021 09:19:37 +0000 (+0200) Subject: update to first proxmox crate split X-Git-Tag: v2.0.12~11 X-Git-Url: https://git.proxmox.com/?p=proxmox-backup.git;a=commitdiff_plain;h=6ef1b649d96ef0eee58314ce5e1638bf06d34082 update to first proxmox crate split Signed-off-by: Wolfgang Bumiller --- diff --git a/Cargo.toml b/Cargo.toml index a6e0ee35..d2e3fa1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,6 +58,7 @@ thiserror = "1.0" futures = "0.3" h2 = { version = "0.3", features = [ "stream" ] } handlebars = "3.0" +hex = "0.4.3" http = "0.2" hyper = { version = "0.14", features = [ "full" ] } lazy_static = "1.4" @@ -96,11 +97,20 @@ zstd = { version = "0.6", features = [ "bindgen" ] } pathpatterns = "0.1.2" pxar = { version = "0.10.1", features = [ "tokio-io" ] } -proxmox = { version = "0.14.0", features = [ "sortable-macro", "api-macro", "cli", "router", "tfa" ] } -proxmox-acme-rs = "0.2.1" -proxmox-apt = "0.7.0" +proxmox = { version = "0.14.0", features = [ "sortable-macro" ] } proxmox-http = { version = "0.5.0", features = [ "client", "http-helpers", "websocket" ] } -proxmox-openid = "0.7.0" +proxmox-io = "1" +proxmox-lang = "1" +proxmox-router = { version = "1", features = [ "cli" ] } +proxmox-schema = { version = "1", features = [ "api-macro" ] } +proxmox-section-config = "1" +proxmox-tfa = { version = "1", features = [ "u2f" ] } +proxmox-time = "1" +proxmox-uuid = "1" + +proxmox-acme-rs = "0.2.1" +proxmox-apt = "0.8.0" +proxmox-openid = "0.8.0" pbs-api-types = { path = "pbs-api-types" } pbs-buildcfg = { path = "pbs-buildcfg" } diff --git a/examples/cipherbench.rs b/examples/cipherbench.rs index 581c101a..40e4984b 100644 --- a/examples/cipherbench.rs +++ b/examples/cipherbench.rs @@ -1,4 +1,4 @@ -use anyhow::{Error}; +use anyhow::Error; // chacha20-poly1305 diff --git a/examples/completion.rs b/examples/completion.rs index 316dd0dc..e2556c83 100644 --- a/examples/completion.rs +++ b/examples/completion.rs @@ -1,6 +1,7 @@ use anyhow::{Error}; -use proxmox::api::{*, cli::*}; +use proxmox_schema::*; +use proxmox_router::cli::*; #[api( input: { diff --git a/examples/download-speed.rs b/examples/download-speed.rs index 471d30f0..a248ae87 100644 --- a/examples/download-speed.rs +++ b/examples/download-speed.rs @@ -1,6 +1,6 @@ use std::io::Write; -use anyhow::{Error}; +use anyhow::Error; use pbs_api_types::Authid; use pbs_client::{HttpClient, HttpClientOptions, BackupReader}; @@ -34,7 +34,7 @@ async fn run() -> Result<(), Error> { let client = HttpClient::new(host, 8007, auth_id, options)?; - let backup_time = proxmox::tools::time::parse_rfc3339("2019-06-28T10:49:48Z")?; + let backup_time = proxmox_time::parse_rfc3339("2019-06-28T10:49:48Z")?; let client = BackupReader::start(client, None, "store2", "host", "elsa", backup_time, true) .await?; diff --git a/examples/dynamic-files.rs b/examples/dynamic-files.rs index 8338dee2..777b95bf 100644 --- a/examples/dynamic-files.rs +++ b/examples/dynamic-files.rs @@ -1,9 +1,9 @@ -use anyhow::{bail, Error}; - use std::thread; use std::path::PathBuf; use std::io::Write; +use anyhow::{bail, Error}; + // tar handle files that shrink during backup, by simply padding with zeros. // // this binary run multiple thread which writes some large files, then truncates diff --git a/examples/upload-speed.rs b/examples/upload-speed.rs index 7c2fd0e7..b670d060 100644 --- a/examples/upload-speed.rs +++ b/examples/upload-speed.rs @@ -16,7 +16,7 @@ async fn upload_speed() -> Result { let client = HttpClient::new(host, 8007, auth_id, options)?; - let backup_time = proxmox::tools::time::epoch_i64(); + let backup_time = proxmox_time::epoch_i64(); let client = BackupWriter::start(client, None, datastore, "host", "speedtest", backup_time, false, true).await?; diff --git a/pbs-api-types/Cargo.toml b/pbs-api-types/Cargo.toml index ade37721..2a51bd3a 100644 --- a/pbs-api-types/Cargo.toml +++ b/pbs-api-types/Cargo.toml @@ -14,7 +14,11 @@ openssl = "0.10" regex = "1.2" serde = { version = "1.0", features = ["derive"] } +proxmox = "0.14.0" +proxmox-lang = "1.0.0" proxmox-schema = { version = "1.0.0", features = [ "api-macro" ] } +proxmox-time = "1.0.0" +proxmox-uuid = { version = "1.0.0", features = [ "serde" ] } proxmox-rrd-api-types = { path = "../proxmox-rrd-api-types" } proxmox-systemd = { path = "../proxmox-systemd" } diff --git a/pbs-api-types/src/acl.rs b/pbs-api-types/src/acl.rs index ad8c66a7..6cdd0ee6 100644 --- a/pbs-api-types/src/acl.rs +++ b/pbs-api-types/src/acl.rs @@ -1,13 +1,12 @@ use std::str::FromStr; -use serde::{Deserialize, Serialize}; use serde::de::{value, IntoDeserializer}; +use serde::{Deserialize, Serialize}; -use proxmox::api::api; -use proxmox::api::schema::{ - ApiStringFormat, BooleanSchema, EnumEntry, Schema, StringSchema, +use proxmox_lang::constnamedbitmap; +use proxmox_schema::{ + api, const_regex, ApiStringFormat, BooleanSchema, EnumEntry, Schema, StringSchema, }; -use proxmox::{constnamedbitmap, const_regex}; const_regex! { pub ACL_PATH_REGEX = concat!(r"^(?:/|", r"(?:/", PROXMOX_SAFE_ID_REGEX_STR!(), ")+", r")$"); @@ -222,7 +221,6 @@ pub enum Role { TapeReader = ROLE_TAPE_READER, } - impl FromStr for Role { type Err = value::Error; @@ -231,26 +229,24 @@ impl FromStr for Role { } } -pub const ACL_PATH_FORMAT: ApiStringFormat = - ApiStringFormat::Pattern(&ACL_PATH_REGEX); +pub const ACL_PATH_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&ACL_PATH_REGEX); -pub const ACL_PATH_SCHEMA: Schema = StringSchema::new( - "Access control path.") +pub const ACL_PATH_SCHEMA: Schema = StringSchema::new("Access control path.") .format(&ACL_PATH_FORMAT) .min_length(1) .max_length(128) .schema(); -pub const ACL_PROPAGATE_SCHEMA: Schema = BooleanSchema::new( - "Allow to propagate (inherit) permissions.") - .default(true) - .schema(); +pub const ACL_PROPAGATE_SCHEMA: Schema = + BooleanSchema::new("Allow to propagate (inherit) permissions.") + .default(true) + .schema(); -pub const ACL_UGID_TYPE_SCHEMA: Schema = StringSchema::new( - "Type of 'ugid' property.") +pub const ACL_UGID_TYPE_SCHEMA: Schema = StringSchema::new("Type of 'ugid' property.") .format(&ApiStringFormat::Enum(&[ EnumEntry::new("user", "User"), - EnumEntry::new("group", "Group")])) + EnumEntry::new("group", "Group"), + ])) .schema(); #[api( diff --git a/pbs-api-types/src/crypto.rs b/pbs-api-types/src/crypto.rs index 7b36e85f..016970f8 100644 --- a/pbs-api-types/src/crypto.rs +++ b/pbs-api-types/src/crypto.rs @@ -3,7 +3,7 @@ use std::fmt::{self, Display}; use anyhow::Error; use serde::{Deserialize, Serialize}; -use proxmox::api::api; +use proxmox_schema::api; use pbs_tools::format::{as_fingerprint, bytes_as_fingerprint}; diff --git a/pbs-api-types/src/datastore.rs b/pbs-api-types/src/datastore.rs index 75f82ea4..462081e4 100644 --- a/pbs-api-types/src/datastore.rs +++ b/pbs-api-types/src/datastore.rs @@ -1,13 +1,10 @@ use serde::{Deserialize, Serialize}; -use proxmox::api::api; -use proxmox::api::schema::{ - ApiStringFormat, ApiType, ArraySchema, EnumEntry, IntegerSchema, ReturnType, Schema, - StringSchema, Updater, +use proxmox_schema::{ + api, const_regex, ApiStringFormat, ApiType, ArraySchema, EnumEntry, IntegerSchema, ReturnType, + Schema, StringSchema, Updater, }; -use proxmox::const_regex; - use crate::{ PROXMOX_SAFE_ID_FORMAT, SHA256_HEX_REGEX, SINGLE_LINE_COMMENT_SCHEMA, CryptMode, UPID, Fingerprint, Userid, Authid, diff --git a/pbs-api-types/src/file_restore.rs b/pbs-api-types/src/file_restore.rs index eedb172b..5748f3a7 100644 --- a/pbs-api-types/src/file_restore.rs +++ b/pbs-api-types/src/file_restore.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use proxmox::api::api; +use proxmox_schema::api; #[api] #[derive(Serialize, Deserialize)] diff --git a/pbs-api-types/src/jobs.rs b/pbs-api-types/src/jobs.rs index a9c64779..f47a294a 100644 --- a/pbs-api-types/src/jobs.rs +++ b/pbs-api-types/src/jobs.rs @@ -1,8 +1,6 @@ use serde::{Deserialize, Serialize}; -use proxmox::const_regex; - -use proxmox::api::{api, schema::*}; +use proxmox_schema::*; use crate::{ Userid, Authid, REMOTE_ID_SCHEMA, DRIVE_NAME_SCHEMA, MEDIA_POOL_NAME_SCHEMA, diff --git a/pbs-api-types/src/key_derivation.rs b/pbs-api-types/src/key_derivation.rs index 9a53130c..26b86c30 100644 --- a/pbs-api-types/src/key_derivation.rs +++ b/pbs-api-types/src/key_derivation.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use proxmox::api::api; +use proxmox_schema::api; use crate::CERT_FINGERPRINT_SHA256_SCHEMA; diff --git a/pbs-api-types/src/lib.rs b/pbs-api-types/src/lib.rs index 83ef386b..cdf765a1 100644 --- a/pbs-api-types/src/lib.rs +++ b/pbs-api-types/src/lib.rs @@ -3,9 +3,9 @@ use serde::{Deserialize, Serialize}; use anyhow::bail; -use proxmox::api::api; -use proxmox::api::schema::{ApiStringFormat, ApiType, ArraySchema, Schema, StringSchema, ReturnType}; -use proxmox::const_regex; +use proxmox_schema::{ + api, const_regex, ApiStringFormat, ApiType, ArraySchema, Schema, StringSchema, ReturnType, +}; use proxmox::{IPRE, IPRE_BRACKET, IPV4OCTET, IPV4RE, IPV6H16, IPV6LS32, IPV6RE}; #[rustfmt::skip] @@ -60,7 +60,7 @@ pub use userid::{PROXMOX_GROUP_ID_SCHEMA, PROXMOX_TOKEN_ID_SCHEMA, PROXMOX_TOKEN mod user; pub use user::*; -pub use proxmox::api::upid::*; +pub use proxmox_schema::upid::*; mod crypto; pub use crypto::{CryptMode, Fingerprint}; diff --git a/pbs-api-types/src/network.rs b/pbs-api-types/src/network.rs index d3a8e43c..de27df7e 100644 --- a/pbs-api-types/src/network.rs +++ b/pbs-api-types/src/network.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use proxmox::api::{api, schema::*}; +use proxmox_schema::*; use crate::{ PROXMOX_SAFE_ID_REGEX, diff --git a/pbs-api-types/src/remote.rs b/pbs-api-types/src/remote.rs index 2784e353..15c336b7 100644 --- a/pbs-api-types/src/remote.rs +++ b/pbs-api-types/src/remote.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use super::*; -use proxmox::api::{api, schema::*}; +use proxmox_schema::*; pub const REMOTE_PASSWORD_SCHEMA: Schema = StringSchema::new("Password or auth token for remote host.") .format(&PASSWORD_FORMAT) diff --git a/pbs-api-types/src/tape/changer.rs b/pbs-api-types/src/tape/changer.rs index e36eb32c..c9c7fcaa 100644 --- a/pbs-api-types/src/tape/changer.rs +++ b/pbs-api-types/src/tape/changer.rs @@ -2,22 +2,11 @@ use serde::{Deserialize, Serialize}; -use proxmox::api::{ - api, - schema::{ - Schema, - ApiStringFormat, - ArraySchema, - IntegerSchema, - StringSchema, - Updater, - }, +use proxmox_schema::{ + api, ApiStringFormat, ArraySchema, IntegerSchema, Schema, StringSchema, Updater, }; -use crate::{ - PROXMOX_SAFE_ID_FORMAT, - OptionalDeviceIdentification, -}; +use crate::{OptionalDeviceIdentification, PROXMOX_SAFE_ID_FORMAT}; pub const CHANGER_NAME_SCHEMA: Schema = StringSchema::new("Tape Changer Identifier.") .format(&PROXMOX_SAFE_ID_FORMAT) @@ -25,9 +14,8 @@ pub const CHANGER_NAME_SCHEMA: Schema = StringSchema::new("Tape Changer Identifi .max_length(32) .schema(); -pub const SCSI_CHANGER_PATH_SCHEMA: Schema = StringSchema::new( - "Path to Linux generic SCSI device (e.g. '/dev/sg4')") - .schema(); +pub const SCSI_CHANGER_PATH_SCHEMA: Schema = + StringSchema::new("Path to Linux generic SCSI device (e.g. '/dev/sg4')").schema(); pub const MEDIA_LABEL_SCHEMA: Schema = StringSchema::new("Media Label/Barcode.") .format(&PROXMOX_SAFE_ID_FORMAT) @@ -36,16 +24,18 @@ pub const MEDIA_LABEL_SCHEMA: Schema = StringSchema::new("Media Label/Barcode.") .schema(); pub const SLOT_ARRAY_SCHEMA: Schema = ArraySchema::new( - "Slot list.", &IntegerSchema::new("Slot number") - .minimum(1) - .schema()) - .schema(); + "Slot list.", + &IntegerSchema::new("Slot number").minimum(1).schema(), +) +.schema(); -pub const EXPORT_SLOT_LIST_SCHEMA: Schema = StringSchema::new("\ +pub const EXPORT_SLOT_LIST_SCHEMA: Schema = StringSchema::new( + "\ A list of slot numbers, comma separated. Those slots are reserved for Import/Export, i.e. any media in those slots are considered to be 'offline'. -") +", +) .format(&ApiStringFormat::PropertyString(&SLOT_ARRAY_SCHEMA)) .schema(); @@ -63,14 +53,14 @@ Import/Export, i.e. any media in those slots are considered to be }, }, )] -#[derive(Serialize,Deserialize,Updater)] +#[derive(Serialize, Deserialize, Updater)] #[serde(rename_all = "kebab-case")] /// SCSI tape changer pub struct ScsiTapeChanger { #[updater(skip)] pub name: String, pub path: String, - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub export_slots: Option, } @@ -84,7 +74,7 @@ pub struct ScsiTapeChanger { }, }, )] -#[derive(Serialize,Deserialize)] +#[derive(Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] /// Changer config with optional device identification attributes pub struct ChangerListEntry { @@ -95,7 +85,7 @@ pub struct ChangerListEntry { } #[api()] -#[derive(Serialize,Deserialize)] +#[derive(Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] /// Mtx Entry Kind pub enum MtxEntryKind { @@ -118,7 +108,7 @@ pub enum MtxEntryKind { }, }, )] -#[derive(Serialize,Deserialize)] +#[derive(Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] /// Mtx Status Entry pub struct MtxStatusEntry { @@ -126,12 +116,12 @@ pub struct MtxStatusEntry { /// The ID of the slot or drive pub entry_id: u64, /// The media label (volume tag) if the slot/drive is full - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub label_text: Option, /// The slot the drive was loaded from - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub loaded_slot: Option, /// The current state of the drive - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub state: Option, } diff --git a/pbs-api-types/src/tape/device.rs b/pbs-api-types/src/tape/device.rs index 368a0015..54fad8b0 100644 --- a/pbs-api-types/src/tape/device.rs +++ b/pbs-api-types/src/tape/device.rs @@ -1,6 +1,6 @@ use ::serde::{Deserialize, Serialize}; -use proxmox::api::api; +use proxmox_schema::api; #[api()] #[derive(Serialize,Deserialize)] diff --git a/pbs-api-types/src/tape/drive.rs b/pbs-api-types/src/tape/drive.rs index 3e207a99..e177d39f 100644 --- a/pbs-api-types/src/tape/drive.rs +++ b/pbs-api-types/src/tape/drive.rs @@ -4,10 +4,7 @@ use std::convert::TryFrom; use anyhow::{bail, Error}; use serde::{Deserialize, Serialize}; -use proxmox::api::{ - api, - schema::{Schema, IntegerSchema, StringSchema, Updater}, -}; +use proxmox_schema::{api, Schema, IntegerSchema, StringSchema, Updater}; use crate::{ PROXMOX_SAFE_ID_FORMAT, diff --git a/pbs-api-types/src/tape/media.rs b/pbs-api-types/src/tape/media.rs index 4e301c98..61d7be04 100644 --- a/pbs-api-types/src/tape/media.rs +++ b/pbs-api-types/src/tape/media.rs @@ -1,9 +1,7 @@ use ::serde::{Deserialize, Serialize}; -use proxmox::{ - api::{api, schema::*}, - tools::Uuid, -}; +use proxmox_schema::*; +use proxmox_uuid::Uuid; use crate::{ UUID_FORMAT, diff --git a/pbs-api-types/src/tape/media_location.rs b/pbs-api-types/src/tape/media_location.rs index a917c609..a05f1156 100644 --- a/pbs-api-types/src/tape/media_location.rs +++ b/pbs-api-types/src/tape/media_location.rs @@ -1,18 +1,8 @@ use anyhow::{bail, Error}; -use proxmox::api::{ - schema::{ - Schema, - StringSchema, - ApiStringFormat, - parse_simple_value, - }, -}; +use proxmox_schema::{parse_simple_value, ApiStringFormat, Schema, StringSchema}; -use crate::{ - PROXMOX_SAFE_ID_FORMAT, - CHANGER_NAME_SCHEMA, -}; +use crate::{CHANGER_NAME_SCHEMA, PROXMOX_SAFE_ID_FORMAT}; pub const VAULT_NAME_SCHEMA: Schema = StringSchema::new("Vault name.") .format(&PROXMOX_SAFE_ID_FORMAT) @@ -35,28 +25,27 @@ pub enum MediaLocation { proxmox::forward_deserialize_to_from_str!(MediaLocation); proxmox::forward_serialize_to_display!(MediaLocation); -impl proxmox::api::schema::ApiType for MediaLocation { +impl proxmox_schema::ApiType for MediaLocation { const API_SCHEMA: Schema = StringSchema::new( - "Media location (e.g. 'offline', 'online-', 'vault-')") - .format(&ApiStringFormat::VerifyFn(|text| { - let location: MediaLocation = text.parse()?; - match location { - MediaLocation::Online(ref changer) => { - parse_simple_value(changer, &CHANGER_NAME_SCHEMA)?; - } - MediaLocation::Vault(ref vault) => { - parse_simple_value(vault, &VAULT_NAME_SCHEMA)?; - } - MediaLocation::Offline => { /* OK */} + "Media location (e.g. 'offline', 'online-', 'vault-')", + ) + .format(&ApiStringFormat::VerifyFn(|text| { + let location: MediaLocation = text.parse()?; + match location { + MediaLocation::Online(ref changer) => { + parse_simple_value(changer, &CHANGER_NAME_SCHEMA)?; } - Ok(()) - })) - .schema(); + MediaLocation::Vault(ref vault) => { + parse_simple_value(vault, &VAULT_NAME_SCHEMA)?; + } + MediaLocation::Offline => { /* OK */ } + } + Ok(()) + })) + .schema(); } - impl std::fmt::Display for MediaLocation { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { MediaLocation::Offline => { diff --git a/pbs-api-types/src/tape/media_pool.rs b/pbs-api-types/src/tape/media_pool.rs index 9e3d8b56..148ae051 100644 --- a/pbs-api-types/src/tape/media_pool.rs +++ b/pbs-api-types/src/tape/media_pool.rs @@ -9,10 +9,7 @@ use std::str::FromStr; use anyhow::Error; use serde::{Deserialize, Serialize}; -use proxmox::api::{ - api, - schema::{Schema, StringSchema, ApiStringFormat, Updater}, -}; +use proxmox_schema::{api, Schema, StringSchema, ApiStringFormat, Updater}; use proxmox_systemd::time::{parse_calendar_event, parse_time_span, CalendarEvent, TimeSpan}; diff --git a/pbs-api-types/src/tape/media_status.rs b/pbs-api-types/src/tape/media_status.rs index 5a3bff96..9815b91f 100644 --- a/pbs-api-types/src/tape/media_status.rs +++ b/pbs-api-types/src/tape/media_status.rs @@ -1,6 +1,6 @@ -use ::serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; -use proxmox::api::api; +use proxmox_schema::api; #[api()] /// Media status diff --git a/pbs-api-types/src/tape/mod.rs b/pbs-api-types/src/tape/mod.rs index a77be7f7..58777a52 100644 --- a/pbs-api-types/src/tape/mod.rs +++ b/pbs-api-types/src/tape/mod.rs @@ -22,13 +22,10 @@ pub use media_location::*; mod media; pub use media::*; -use ::serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; -use proxmox::api::api; -use proxmox::api::schema::{Schema, StringSchema, ApiStringFormat}; -use proxmox::tools::Uuid; - -use proxmox::const_regex; +use proxmox_schema::{api, const_regex, Schema, StringSchema, ApiStringFormat}; +use proxmox_uuid::Uuid; use crate::{ FINGERPRINT_SHA256_FORMAT, BACKUP_ID_SCHEMA, BACKUP_TYPE_SCHEMA, diff --git a/pbs-api-types/src/user.rs b/pbs-api-types/src/user.rs index 8a7480ad..94ed07c0 100644 --- a/pbs-api-types/src/user.rs +++ b/pbs-api-types/src/user.rs @@ -1,8 +1,7 @@ use serde::{Deserialize, Serialize}; -use proxmox::api::api; -use proxmox::api::schema::{ - BooleanSchema, IntegerSchema, Schema, StringSchema, Updater, +use proxmox_schema::{ + api, BooleanSchema, IntegerSchema, Schema, StringSchema, Updater, }; use super::{SINGLE_LINE_COMMENT_FORMAT, SINGLE_LINE_COMMENT_SCHEMA}; @@ -133,7 +132,7 @@ impl ApiToken { return false; } if let Some(expire) = self.expire { - let now = proxmox::tools::time::epoch_i64(); + let now = proxmox_time::epoch_i64(); if expire > 0 && expire <= now { return false; } @@ -198,7 +197,7 @@ impl User { return false; } if let Some(expire) = self.expire { - let now = proxmox::tools::time::epoch_i64(); + let now = proxmox_time::epoch_i64(); if expire > 0 && expire <= now { return false; } diff --git a/pbs-api-types/src/userid.rs b/pbs-api-types/src/userid.rs index 1794c720..8c58da2e 100644 --- a/pbs-api-types/src/userid.rs +++ b/pbs-api-types/src/userid.rs @@ -29,9 +29,9 @@ use anyhow::{bail, format_err, Error}; use lazy_static::lazy_static; use serde::{Deserialize, Serialize}; -use proxmox::api::api; -use proxmox::api::schema::{ApiStringFormat, ApiType, Schema, StringSchema, UpdaterType}; -use proxmox::const_regex; +use proxmox_schema::{ + api, const_regex, ApiStringFormat, ApiType, Schema, StringSchema, UpdaterType, +}; // we only allow a limited set of characters // colon is not allowed, because we store usernames in diff --git a/pbs-api-types/src/zfs.rs b/pbs-api-types/src/zfs.rs index 517ca914..5fe49561 100644 --- a/pbs-api-types/src/zfs.rs +++ b/pbs-api-types/src/zfs.rs @@ -1,8 +1,6 @@ use serde::{Deserialize, Serialize}; -use proxmox::api::{api, schema::*}; - -use proxmox::const_regex; +use proxmox_schema::*; const_regex! { pub ZPOOL_NAME_REGEX = r"^[a-zA-Z][a-z0-9A-Z\-_.:]+$"; diff --git a/pbs-client/Cargo.toml b/pbs-client/Cargo.toml index 58da9f30..272cf356 100644 --- a/pbs-client/Cargo.toml +++ b/pbs-client/Cargo.toml @@ -28,9 +28,14 @@ tower-service = "0.3.0" xdg = "2.2" pathpatterns = "0.1.2" -proxmox = { version = "0.14.0", default-features = false, features = [ "cli" ] } +proxmox = "0.14.0" proxmox-fuse = "0.1.1" proxmox-http = { version = "0.5.0", features = [ "client", "http-helpers", "websocket" ] } +proxmox-io = { version = "1", features = [ "tokio" ] } +proxmox-lang = "1" +proxmox-router = { version = "1", features = [ "cli" ] } +proxmox-schema = "1" +proxmox-time = "1" pxar = { version = "0.10.1", features = [ "tokio-io" ] } pbs-api-types = { path = "../pbs-api-types" } diff --git a/pbs-client/src/backup_specification.rs b/pbs-client/src/backup_specification.rs index 627c183c..ea32b97c 100644 --- a/pbs-client/src/backup_specification.rs +++ b/pbs-client/src/backup_specification.rs @@ -1,8 +1,8 @@ use anyhow::{bail, Error}; -use proxmox::api::schema::*; +use proxmox_schema::*; -proxmox::const_regex! { +const_regex! { BACKUPSPEC_REGEX = r"^([a-zA-Z0-9_-]+\.(pxar|img|conf|log)):(.+)$"; } diff --git a/pbs-client/src/catalog_shell.rs b/pbs-client/src/catalog_shell.rs index defa6238..6a35f135 100644 --- a/pbs-client/src/catalog_shell.rs +++ b/pbs-client/src/catalog_shell.rs @@ -13,9 +13,9 @@ use nix::fcntl::OFlag; use nix::sys::stat::Mode; use pathpatterns::{MatchEntry, MatchList, MatchPattern, MatchType, PatternFlag}; -use proxmox::api::api; -use proxmox::api::cli::{self, CliCommand, CliCommandMap, CliHelper, CommandLineInterface}; use proxmox::tools::fs::{create_path, CreateOptions}; +use proxmox_router::cli::{self, CliCommand, CliCommandMap, CliHelper, CommandLineInterface}; +use proxmox_schema::api; use pxar::{EntryKind, Metadata}; use pbs_runtime::block_in_place; diff --git a/pbs-client/src/http_client.rs b/pbs-client/src/http_client.rs index a83b8d3c..d135bc4f 100644 --- a/pbs-client/src/http_client.rs +++ b/pbs-client/src/http_client.rs @@ -15,10 +15,10 @@ use percent_encoding::percent_encode; use xdg::BaseDirectories; use proxmox::{ - api::error::HttpError, sys::linux::tty, tools::fs::{file_get_json, replace_file, CreateOptions}, }; +use proxmox_router::HttpError; use proxmox_http::client::HttpsConnector; use proxmox_http::uri::build_authority; @@ -230,7 +230,7 @@ fn store_ticket_info(prefix: &str, server: &str, username: &str, ticket: &str, t let mut data = file_get_json(&path, Some(json!({})))?; - let now = proxmox::tools::time::epoch_i64(); + let now = proxmox_time::epoch_i64(); data[server][username] = json!({ "timestamp": now, "ticket": ticket, "token": token}); @@ -261,7 +261,7 @@ fn load_ticket_info(prefix: &str, server: &str, userid: &Userid) -> Option<(Stri // usually /run/user//... let path = base.place_runtime_file("tickets").ok()?; let data = file_get_json(&path, None).ok()?; - let now = proxmox::tools::time::epoch_i64(); + let now = proxmox_time::epoch_i64(); let ticket_lifetime = ticket::TICKET_LIFETIME - 60; let uinfo = data[server][userid.as_str()].as_object()?; let timestamp = uinfo["timestamp"].as_i64()?; diff --git a/pbs-client/src/pxar/create.rs b/pbs-client/src/pxar/create.rs index 96888c7c..4ad29258 100644 --- a/pbs-client/src/pxar/create.rs +++ b/pbs-client/src/pxar/create.rs @@ -19,11 +19,11 @@ use pathpatterns::{MatchEntry, MatchFlag, MatchList, MatchType, PatternFlag}; use pxar::Metadata; use pxar::encoder::{SeqWrite, LinkOffset}; -use proxmox::c_str; use proxmox::sys::error::SysError; use proxmox::tools::fd::RawFdNum; -use proxmox::tools::vec; use proxmox::tools::fd::Fd; +use proxmox_io::vec; +use proxmox_lang::c_str; use pbs_datastore::catalog::BackupCatalogWriter; use pbs_tools::{acl, fs, xattr}; diff --git a/pbs-client/src/pxar/extract.rs b/pbs-client/src/pxar/extract.rs index a03b5a54..52c6bf34 100644 --- a/pbs-client/src/pxar/extract.rs +++ b/pbs-client/src/pxar/extract.rs @@ -22,10 +22,8 @@ use pxar::format::Device; use pxar::{Entry, EntryKind, Metadata}; use proxmox::c_result; -use proxmox::tools::{ - fs::{create_path, CreateOptions}, - io::{sparse_copy, sparse_copy_async}, -}; +use proxmox::tools::fs::{create_path, CreateOptions}; +use proxmox_io::{sparse_copy, sparse_copy_async}; use pbs_tools::zip::{ZipEncoder, ZipEntry}; diff --git a/pbs-client/src/pxar/fuse.rs b/pbs-client/src/pxar/fuse.rs index 91970c8e..e8bb89ff 100644 --- a/pbs-client/src/pxar/fuse.rs +++ b/pbs-client/src/pxar/fuse.rs @@ -20,7 +20,7 @@ use futures::select; use futures::sink::SinkExt; use futures::stream::{StreamExt, TryStreamExt}; -use proxmox::tools::vec; +use proxmox_io::vec; use pxar::accessor::{self, EntryRangeInfo, ReadAt}; use proxmox_fuse::requests::{self, FuseRequest}; diff --git a/pbs-client/src/pxar/tools.rs b/pbs-client/src/pxar/tools.rs index 3fd0fc00..4dab2af7 100644 --- a/pbs-client/src/pxar/tools.rs +++ b/pbs-client/src/pxar/tools.rs @@ -115,7 +115,7 @@ fn mode_string(entry: &Entry) -> String { } fn format_mtime(mtime: &StatxTimestamp) -> String { - if let Ok(s) = proxmox::tools::time::strftime_local("%Y-%m-%d %H:%M:%S", mtime.secs) { + if let Ok(s) = proxmox_time::strftime_local("%Y-%m-%d %H:%M:%S", mtime.secs) { return s; } format!("{}.{}", mtime.secs, mtime.nanos) diff --git a/pbs-client/src/task_log.rs b/pbs-client/src/task_log.rs index 1d1af141..e8874619 100644 --- a/pbs-client/src/task_log.rs +++ b/pbs-client/src/task_log.rs @@ -5,7 +5,7 @@ use serde_json::{json, Value}; use tokio::signal::unix::{signal, SignalKind}; use futures::*; -use proxmox::api::cli::format_and_print_result; +use proxmox_router::cli::format_and_print_result; use pbs_tools::percent_encoding::percent_encode_component; diff --git a/pbs-client/src/tools/key_source.rs b/pbs-client/src/tools/key_source.rs index a3a2bf1a..32e2b264 100644 --- a/pbs-client/src/tools/key_source.rs +++ b/pbs-client/src/tools/key_source.rs @@ -6,9 +6,9 @@ use std::io::Read; use anyhow::{bail, format_err, Error}; use serde_json::Value; -use proxmox::api::schema::*; use proxmox::sys::linux::tty; use proxmox::tools::fs::file_get_contents; +use proxmox_schema::*; use pbs_api_types::CryptMode; diff --git a/pbs-client/src/tools/mod.rs b/pbs-client/src/tools/mod.rs index f3d63ae5..f6ae4bcd 100644 --- a/pbs-client/src/tools/mod.rs +++ b/pbs-client/src/tools/mod.rs @@ -10,11 +10,9 @@ use anyhow::{bail, format_err, Context, Error}; use serde_json::{json, Value}; use xdg::BaseDirectories; -use proxmox::{ - api::schema::*, - api::cli::shellword_split, - tools::fs::file_get_json, -}; +use proxmox_schema::*; +use proxmox_router::cli::shellword_split; +use proxmox::tools::fs::file_get_json; use pbs_api_types::{BACKUP_REPO_URL, Authid, UserWithTokens}; use pbs_datastore::BackupDir; diff --git a/pbs-client/src/vsock_client.rs b/pbs-client/src/vsock_client.rs index 38fa121a..07e9125a 100644 --- a/pbs-client/src/vsock_client.rs +++ b/pbs-client/src/vsock_client.rs @@ -13,7 +13,7 @@ use serde_json::Value; use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, ReadBuf}; use tokio::net::UnixStream; -use proxmox::api::error::HttpError; +use proxmox_router::HttpError; pub const DEFAULT_VSOCK_PORT: u16 = 807; diff --git a/pbs-config/Cargo.toml b/pbs-config/Cargo.toml index 51b4bd8b..49d4cf6f 100644 --- a/pbs-config/Cargo.toml +++ b/pbs-config/Cargo.toml @@ -6,17 +6,23 @@ edition = "2018" description = "Configuration file management for PBS" [dependencies] -libc = "0.2" anyhow = "1.0" +hex = "0.4.3" lazy_static = "1.4" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -openssl = "0.10" +libc = "0.2" nix = "0.19.1" -regex = "1.2" once_cell = "1.3.1" +openssl = "0.10" +regex = "1.2" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" -proxmox = { version = "0.14.0", default-features = false, features = [ "cli" ] } +proxmox = "0.14.0" +proxmox-lang = "1" +proxmox-router = "1" +proxmox-schema = "1" +proxmox-section-config = "1" +proxmox-time = "1" pbs-api-types = { path = "../pbs-api-types" } pbs-buildcfg = { path = "../pbs-buildcfg" } diff --git a/pbs-config/src/acl.rs b/pbs-config/src/acl.rs index 7a3fe972..13af45a9 100644 --- a/pbs-config/src/acl.rs +++ b/pbs-config/src/acl.rs @@ -8,7 +8,7 @@ use anyhow::{bail, Error}; use lazy_static::lazy_static; -use proxmox::api::schema::{Schema, StringSchema, ApiStringFormat, ApiType}; +use proxmox_schema::{ApiStringFormat, ApiType, Schema, StringSchema}; use pbs_api_types::{Authid, Userid, Role, ROLE_NAME_NO_ACCESS}; diff --git a/pbs-config/src/cached_user_info.rs b/pbs-config/src/cached_user_info.rs index 960864f2..495fdd12 100644 --- a/pbs-config/src/cached_user_info.rs +++ b/pbs-config/src/cached_user_info.rs @@ -3,11 +3,11 @@ use std::sync::{RwLock, Arc}; use anyhow::{Error, bail}; - -use proxmox::api::section_config::SectionConfigData; use lazy_static::lazy_static; -use proxmox::api::UserInformation; -use proxmox::tools::time::epoch_i64; + +use proxmox_router::UserInformation; +use proxmox_section_config::SectionConfigData; +use proxmox_time::epoch_i64; use pbs_api_types::{Authid, Userid, User, ApiToken, ROLE_ADMIN}; diff --git a/pbs-config/src/datastore.rs b/pbs-config/src/datastore.rs index d8f6694d..953551d2 100644 --- a/pbs-config/src/datastore.rs +++ b/pbs-config/src/datastore.rs @@ -2,14 +2,8 @@ use anyhow::{Error}; use lazy_static::lazy_static; use std::collections::HashMap; -use proxmox::api::{ - schema::{ApiType, Schema}, - section_config::{ - SectionConfig, - SectionConfigData, - SectionConfigPlugin, - } -}; +use proxmox_schema::{ApiType, Schema}; +use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use pbs_api_types::{DataStoreConfig, DATASTORE_SCHEMA}; diff --git a/pbs-config/src/domains.rs b/pbs-config/src/domains.rs index 6119cea7..3d3f93b0 100644 --- a/pbs-config/src/domains.rs +++ b/pbs-config/src/domains.rs @@ -1,17 +1,11 @@ +use std::collections::HashMap; + use anyhow::{Error}; use lazy_static::lazy_static; -use std::collections::HashMap; use serde::{Serialize, Deserialize}; -use proxmox::api::{ - api, - schema::*, - section_config::{ - SectionConfig, - SectionConfigData, - SectionConfigPlugin, - } -}; +use proxmox_schema::{api, ApiType, Updater, Schema}; +use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use pbs_api_types::{REALM_ID_SCHEMA, SINGLE_LINE_COMMENT_SCHEMA}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; @@ -59,7 +53,7 @@ pub enum OpenIdUserAttribute { }, }, )] -#[derive(Serialize,Deserialize,Updater)] +#[derive(Serialize, Deserialize, Updater)] #[serde(rename_all="kebab-case")] /// OpenID configuration properties. pub struct OpenIdRealmConfig { diff --git a/pbs-config/src/drive.rs b/pbs-config/src/drive.rs index b1ff8548..b800cd8b 100644 --- a/pbs-config/src/drive.rs +++ b/pbs-config/src/drive.rs @@ -16,16 +16,8 @@ use std::collections::HashMap; use anyhow::{bail, Error}; use lazy_static::lazy_static; -use proxmox::{ - api::{ - schema::*, - section_config::{ - SectionConfig, - SectionConfigData, - SectionConfigPlugin, - }, - }, -}; +use proxmox_schema::*; +use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; diff --git a/pbs-config/src/key_config.rs b/pbs-config/src/key_config.rs index 9e71368f..9c4b3b57 100644 --- a/pbs-config/src/key_config.rs +++ b/pbs-config/src/key_config.rs @@ -5,7 +5,7 @@ use anyhow::{bail, format_err, Context, Error}; use serde::{Deserialize, Serialize}; use proxmox::tools::fs::{file_get_contents, replace_file, CreateOptions}; -use proxmox::try_block; +use proxmox_lang::try_block; use pbs_api_types::{Kdf, KeyInfo, Fingerprint}; @@ -122,7 +122,7 @@ impl KeyConfig { let crypt_config = CryptConfig::new(raw_key.clone())?; let fingerprint = Some(Fingerprint::new(crypt_config.fingerprint())); - let created = proxmox::tools::time::epoch_i64(); + let created = proxmox_time::epoch_i64(); Ok(Self { kdf: None, created, @@ -183,7 +183,7 @@ impl KeyConfig { enc_data.extend_from_slice(&tag); enc_data.extend_from_slice(&encrypted_key); - let created = proxmox::tools::time::epoch_i64(); + let created = proxmox_time::epoch_i64(); // always compute fingerprint let crypt_config = CryptConfig::new(raw_key.clone())?; @@ -370,8 +370,8 @@ fn encrypt_decrypt_test() -> Result<(), Error> { let key = KeyConfig { kdf: None, - created: proxmox::tools::time::epoch_i64(), - modified: proxmox::tools::time::epoch_i64(), + created: proxmox_time::epoch_i64(), + modified: proxmox_time::epoch_i64(), data: (0u8..32u8).collect(), fingerprint: Some(Fingerprint::new([ 14, 171, 212, 70, 11, 110, 185, 202, 52, 80, 35, 222, 226, 183, 120, 199, 144, 229, 74, @@ -396,8 +396,8 @@ fn encrypt_decrypt_test() -> Result<(), Error> { fn fingerprint_checks() -> Result<(), Error> { let key = KeyConfig { kdf: None, - created: proxmox::tools::time::epoch_i64(), - modified: proxmox::tools::time::epoch_i64(), + created: proxmox_time::epoch_i64(), + modified: proxmox_time::epoch_i64(), data: (0u8..32u8).collect(), fingerprint: Some(Fingerprint::new([0u8; 32])), // wrong FP hint: None, @@ -413,8 +413,8 @@ fn fingerprint_checks() -> Result<(), Error> { let key = KeyConfig { kdf: None, - created: proxmox::tools::time::epoch_i64(), - modified: proxmox::tools::time::epoch_i64(), + created: proxmox_time::epoch_i64(), + modified: proxmox_time::epoch_i64(), data: (0u8..32u8).collect(), fingerprint: None, hint: None, diff --git a/pbs-config/src/media_pool.rs b/pbs-config/src/media_pool.rs index 3512c70a..5193061a 100644 --- a/pbs-config/src/media_pool.rs +++ b/pbs-config/src/media_pool.rs @@ -4,23 +4,15 @@ //! provides a type safe interface to store [`MediaPoolConfig`], //! //! [MediaPoolConfig]: crate::api2::types::MediaPoolConfig -//! [SectionConfig]: proxmox::api::section_config::SectionConfig +//! [SectionConfig]: proxmox_section_config::SectionConfig use std::collections::HashMap; use anyhow::Error; use lazy_static::lazy_static; -use proxmox::{ - api::{ - schema::*, - section_config::{ - SectionConfig, - SectionConfigData, - SectionConfigPlugin, - } - }, -}; +use proxmox_schema::*; +use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use pbs_api_types::{MEDIA_POOL_NAME_SCHEMA, MediaPoolConfig}; diff --git a/pbs-config/src/remote.rs b/pbs-config/src/remote.rs index 77d574f4..fb19cb53 100644 --- a/pbs-config/src/remote.rs +++ b/pbs-config/src/remote.rs @@ -1,15 +1,10 @@ -use anyhow::{Error}; -use lazy_static::lazy_static; use std::collections::HashMap; -use proxmox::api::{ - schema::*, - section_config::{ - SectionConfig, - SectionConfigData, - SectionConfigPlugin, - } -}; +use anyhow::Error; +use lazy_static::lazy_static; + +use proxmox_schema::*; +use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use pbs_api_types::{Remote, REMOTE_ID_SCHEMA}; diff --git a/pbs-config/src/sync.rs b/pbs-config/src/sync.rs index 63b30c94..a9e3a0de 100644 --- a/pbs-config/src/sync.rs +++ b/pbs-config/src/sync.rs @@ -1,15 +1,10 @@ -use anyhow::{Error}; -use lazy_static::lazy_static; use std::collections::HashMap; -use proxmox::api::{ - schema::*, - section_config::{ - SectionConfig, - SectionConfigData, - SectionConfigPlugin, - } -}; +use anyhow::Error; +use lazy_static::lazy_static; + +use proxmox_schema::{ApiType, Schema}; +use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use pbs_api_types::{JOB_ID_SCHEMA, SyncJobConfig}; diff --git a/pbs-config/src/tape_job.rs b/pbs-config/src/tape_job.rs index c0c98fd3..60084e4f 100644 --- a/pbs-config/src/tape_job.rs +++ b/pbs-config/src/tape_job.rs @@ -2,14 +2,8 @@ use anyhow::{Error}; use lazy_static::lazy_static; use std::collections::HashMap; -use proxmox::api::{ - schema::{Schema, ApiType}, - section_config::{ - SectionConfig, - SectionConfigData, - SectionConfigPlugin, - } -}; +use proxmox_schema::{Schema, ApiType}; +use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use pbs_api_types::{TapeBackupJobConfig, JOB_ID_SCHEMA}; diff --git a/pbs-config/src/user.rs b/pbs-config/src/user.rs index 13287738..db66ab7d 100644 --- a/pbs-config/src/user.rs +++ b/pbs-config/src/user.rs @@ -4,14 +4,8 @@ use std::sync::{Arc, RwLock}; use anyhow::{bail, Error}; use lazy_static::lazy_static; -use proxmox::api::{ - schema::*, - section_config::{ - SectionConfig, - SectionConfigData, - SectionConfigPlugin, - } -}; +use proxmox_schema::*; +use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use pbs_api_types::{ Authid, Userid, ApiToken, User, diff --git a/pbs-config/src/verify.rs b/pbs-config/src/verify.rs index 310cf4bf..f72bfebb 100644 --- a/pbs-config/src/verify.rs +++ b/pbs-config/src/verify.rs @@ -1,15 +1,10 @@ -use anyhow::{Error}; -use lazy_static::lazy_static; use std::collections::HashMap; -use proxmox::api::{ - schema::*, - section_config::{ - SectionConfig, - SectionConfigData, - SectionConfigPlugin, - } -}; +use anyhow::Error; +use lazy_static::lazy_static; + +use proxmox_schema::*; +use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use pbs_api_types::{JOB_ID_SCHEMA, VerificationJobConfig}; diff --git a/pbs-datastore/Cargo.toml b/pbs-datastore/Cargo.toml index 52b9278b..8d53e995 100644 --- a/pbs-datastore/Cargo.toml +++ b/pbs-datastore/Cargo.toml @@ -25,7 +25,12 @@ zstd = { version = "0.6", features = [ "bindgen" ] } pathpatterns = "0.1.2" pxar = "0.10.1" -proxmox = { version = "0.14.0", default-features = false, features = [ "api-macro" ] } +proxmox = "0.14.0" +proxmox-io = "1" +proxmox-lang = "1" +proxmox-schema = { version = "1", features = [ "api-macro" ] } +proxmox-time = "1" +proxmox-uuid = "1" pbs-api-types = { path = "../pbs-api-types" } pbs-tools = { path = "../pbs-tools" } diff --git a/pbs-datastore/src/backup_info.rs b/pbs-datastore/src/backup_info.rs index f77098ee..9d1ab991 100644 --- a/pbs-datastore/src/backup_info.rs +++ b/pbs-datastore/src/backup_info.rs @@ -138,7 +138,7 @@ impl BackupGroup { } } - let timestamp = proxmox::tools::time::parse_rfc3339(backup_time)?; + let timestamp = proxmox_time::parse_rfc3339(backup_time)?; if let Some(last_timestamp) = last { if timestamp > last_timestamp { last = Some(timestamp); @@ -215,7 +215,7 @@ impl BackupDir { V: Into, { let backup_time_string = backup_time_string.into(); - let backup_time = proxmox::tools::time::parse_rfc3339(&backup_time_string)?; + let backup_time = proxmox_time::parse_rfc3339(&backup_time_string)?; let group = BackupGroup::new(backup_type.into(), backup_id.into()); Ok(Self { group, @@ -255,7 +255,7 @@ impl BackupDir { pub fn backup_time_to_string(backup_time: i64) -> Result { // fixme: can this fail? (avoid unwrap) - proxmox::tools::time::epoch_to_rfc3339_utc(backup_time) + Ok(proxmox_time::epoch_to_rfc3339_utc(backup_time)?) } } diff --git a/pbs-datastore/src/catalog.rs b/pbs-datastore/src/catalog.rs index e82417f2..02f3e41e 100644 --- a/pbs-datastore/src/catalog.rs +++ b/pbs-datastore/src/catalog.rs @@ -8,8 +8,9 @@ use anyhow::{bail, format_err, Error}; use serde::{Deserialize, Serialize}; use pathpatterns::{MatchList, MatchType}; -use proxmox::api::api; -use proxmox::tools::io::ReadExt; + +use proxmox_io::ReadExt; +use proxmox_schema::api; use crate::file_formats::PROXMOX_CATALOG_FILE_MAGIC_1_0; @@ -570,7 +571,7 @@ impl CatalogReader { } CatalogEntryType::File => { let mut mtime_string = mtime.to_string(); - if let Ok(s) = proxmox::tools::time::strftime_local("%FT%TZ", mtime as i64) { + if let Ok(s) = proxmox_time::strftime_local("%FT%TZ", mtime as i64) { mtime_string = s; } diff --git a/pbs-datastore/src/data_blob.rs b/pbs-datastore/src/data_blob.rs index 7e1e54eb..9f956d76 100644 --- a/pbs-datastore/src/data_blob.rs +++ b/pbs-datastore/src/data_blob.rs @@ -4,7 +4,7 @@ use std::io::Write; use anyhow::{bail, Error}; use openssl::symm::{decrypt_aead, Mode}; -use proxmox::tools::io::{ReadExt, WriteExt}; +use proxmox_io::{ReadExt, WriteExt}; use pbs_tools::crypt_config::CryptConfig; use pbs_api_types::CryptMode; @@ -58,13 +58,13 @@ impl DataBlob { /// accessor to crc32 checksum pub fn crc(&self) -> u32 { - let crc_o = proxmox::offsetof!(DataBlobHeader, crc); + let crc_o = proxmox_lang::offsetof!(DataBlobHeader, crc); u32::from_le_bytes(self.raw_data[crc_o..crc_o+4].try_into().unwrap()) } // set the CRC checksum field pub fn set_crc(&mut self, crc: u32) { - let crc_o = proxmox::offsetof!(DataBlobHeader, crc); + let crc_o = proxmox_lang::offsetof!(DataBlobHeader, crc); self.raw_data[crc_o..crc_o+4].copy_from_slice(&crc.to_le_bytes()); } diff --git a/pbs-datastore/src/data_blob_reader.rs b/pbs-datastore/src/data_blob_reader.rs index 9c7a8568..ba4143c0 100644 --- a/pbs-datastore/src/data_blob_reader.rs +++ b/pbs-datastore/src/data_blob_reader.rs @@ -2,7 +2,8 @@ use std::io::{BufReader, Read}; use std::sync::Arc; use anyhow::{bail, format_err, Error}; -use proxmox::tools::io::ReadExt; + +use proxmox_io::ReadExt; use pbs_tools::crypt_config::CryptConfig; diff --git a/pbs-datastore/src/data_blob_writer.rs b/pbs-datastore/src/data_blob_writer.rs index 6425cecf..30d9645f 100644 --- a/pbs-datastore/src/data_blob_writer.rs +++ b/pbs-datastore/src/data_blob_writer.rs @@ -1,8 +1,10 @@ -use anyhow::Error; -use proxmox::tools::io::WriteExt; use std::io::{Seek, SeekFrom, Write}; use std::sync::Arc; +use anyhow::Error; + +use proxmox_io::WriteExt; + use pbs_tools::crypt_config::CryptConfig; use crate::checksum_writer::ChecksumWriter; diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs index b068a9c9..79a2d9e8 100644 --- a/pbs-datastore/src/datastore.rs +++ b/pbs-datastore/src/datastore.rs @@ -620,7 +620,7 @@ impl DataStore { // writer" information and thus no safe atime cutoff let _exclusive_lock = self.chunk_store.try_exclusive_lock()?; - let phase1_start_time = proxmox::tools::time::epoch_i64(); + let phase1_start_time = proxmox_time::epoch_i64(); let oldest_writer = self.chunk_store.oldest_writer().unwrap_or(phase1_start_time); let mut gc_status = GarbageCollectionStatus::default(); @@ -742,7 +742,7 @@ impl DataStore { path.push(backup_dir.relative_path()); path.push(filename); - proxmox::try_block!({ + proxmox_lang::try_block!({ let mut file = std::fs::File::open(&path)?; DataBlob::load_from_reader(&mut file) }).map_err(|err| format_err!("unable to load blob '{:?}' - {}", path, err)) @@ -758,7 +758,7 @@ impl DataStore { let (chunk_path, digest_str) = self.chunk_store.chunk_path(digest); - proxmox::try_block!({ + proxmox_lang::try_block!({ let mut file = std::fs::File::open(&chunk_path)?; DataBlob::load_from_reader(&mut file) }).map_err(|err| format_err!( diff --git a/pbs-datastore/src/dynamic_index.rs b/pbs-datastore/src/dynamic_index.rs index bdddc138..16cd133a 100644 --- a/pbs-datastore/src/dynamic_index.rs +++ b/pbs-datastore/src/dynamic_index.rs @@ -9,9 +9,9 @@ use std::task::Context; use anyhow::{bail, format_err, Error}; -use proxmox::tools::io::ReadExt; -use proxmox::tools::uuid::Uuid; use proxmox::tools::mmap::Mmap; +use proxmox_io::ReadExt; +use proxmox_uuid::Uuid; use pxar::accessor::{MaybeReady, ReadAt, ReadAtOperation}; use pbs_tools::lru_cache::LruCache; @@ -35,7 +35,7 @@ pub struct DynamicIndexHeader { pub index_csum: [u8; 32], reserved: [u8; 4032], // overall size is one page (4096 bytes) } -proxmox::static_assert_size!(DynamicIndexHeader, 4096); +proxmox_lang::static_assert_size!(DynamicIndexHeader, 4096); // TODO: Once non-Copy unions are stabilized, use: // union DynamicIndexHeader { // reserved: [u8; 4096], @@ -119,7 +119,7 @@ impl DynamicIndexReader { bail!("got unknown magic number"); } - let ctime = proxmox::tools::time::epoch_i64(); + let ctime = proxmox_time::epoch_i64(); let index_size = stat.st_size as usize - header_size; let index_count = index_size / 40; @@ -301,7 +301,7 @@ impl DynamicIndexWriter { let mut writer = BufWriter::with_capacity(1024 * 1024, file); - let ctime = proxmox::tools::time::epoch_i64(); + let ctime = proxmox_time::epoch_i64(); let uuid = Uuid::generate(); @@ -344,7 +344,7 @@ impl DynamicIndexWriter { self.writer.flush()?; - let csum_offset = proxmox::offsetof!(DynamicIndexHeader, index_csum); + let csum_offset = proxmox_lang::offsetof!(DynamicIndexHeader, index_csum); self.writer.seek(SeekFrom::Start(csum_offset as u64))?; let csum = self.csum.take().unwrap(); diff --git a/pbs-datastore/src/fixed_index.rs b/pbs-datastore/src/fixed_index.rs index 47c69043..41622b4c 100644 --- a/pbs-datastore/src/fixed_index.rs +++ b/pbs-datastore/src/fixed_index.rs @@ -9,8 +9,8 @@ use anyhow::{bail, format_err, Error}; use pbs_tools::process_locker::ProcessLockSharedGuard; -use proxmox::tools::io::ReadExt; -use proxmox::tools::Uuid; +use proxmox_io::ReadExt; +use proxmox_uuid::Uuid; use crate::chunk_stat::ChunkStat; use crate::chunk_store::ChunkStore; @@ -30,7 +30,7 @@ pub struct FixedIndexHeader { pub chunk_size: u64, reserved: [u8; 4016], // overall size is one page (4096 bytes) } -proxmox::static_assert_size!(FixedIndexHeader, 4096); +proxmox_lang::static_assert_size!(FixedIndexHeader, 4096); // split image into fixed size chunks @@ -149,7 +149,7 @@ impl FixedIndexReader { println!("ChunkSize: {}", self.chunk_size); let mut ctime_str = self.ctime.to_string(); - if let Ok(s) = proxmox::tools::time::strftime_local("%c", self.ctime) { + if let Ok(s) = proxmox_time::strftime_local("%c", self.ctime) { ctime_str = s; } @@ -281,7 +281,7 @@ impl FixedIndexWriter { panic!("got unexpected header size"); } - let ctime = proxmox::tools::time::epoch_i64(); + let ctime = proxmox_time::epoch_i64(); let uuid = Uuid::generate(); @@ -361,7 +361,7 @@ impl FixedIndexWriter { self.unmap()?; - let csum_offset = proxmox::offsetof!(FixedIndexHeader, index_csum); + let csum_offset = proxmox_lang::offsetof!(FixedIndexHeader, index_csum); self.file.seek(SeekFrom::Start(csum_offset as u64))?; self.file.write_all(&index_csum)?; self.file.flush()?; diff --git a/pbs-datastore/src/paperkey.rs b/pbs-datastore/src/paperkey.rs index eb5896fc..da29fd98 100644 --- a/pbs-datastore/src/paperkey.rs +++ b/pbs-datastore/src/paperkey.rs @@ -4,7 +4,7 @@ use std::process::{Command, Stdio}; use anyhow::{bail, format_err, Error}; use serde::{Deserialize, Serialize}; -use proxmox::api::api; +use proxmox_schema::api; use pbs_config::key_config::KeyConfig; diff --git a/pbs-datastore/src/prune.rs b/pbs-datastore/src/prune.rs index 3b4cf4f2..70c3d91c 100644 --- a/pbs-datastore/src/prune.rs +++ b/pbs-datastore/src/prune.rs @@ -135,17 +135,17 @@ pub fn compute_prune_info( })?; } - use proxmox::tools::time::strftime_local; + use proxmox_time::strftime_local; if let Some(keep_hourly) = options.keep_hourly { mark_selections(&mut mark, &list, keep_hourly as usize, |info| { - strftime_local("%Y/%m/%d/%H", info.backup_dir.backup_time()) + strftime_local("%Y/%m/%d/%H", info.backup_dir.backup_time()).map_err(Error::from) })?; } if let Some(keep_daily) = options.keep_daily { mark_selections(&mut mark, &list, keep_daily as usize, |info| { - strftime_local("%Y/%m/%d", info.backup_dir.backup_time()) + strftime_local("%Y/%m/%d", info.backup_dir.backup_time()).map_err(Error::from) })?; } @@ -153,19 +153,19 @@ pub fn compute_prune_info( mark_selections(&mut mark, &list, keep_weekly as usize, |info| { // Note: Use iso-week year/week here. This year number // might not match the calendar year number. - strftime_local("%G/%V", info.backup_dir.backup_time()) + strftime_local("%G/%V", info.backup_dir.backup_time()).map_err(Error::from) })?; } if let Some(keep_monthly) = options.keep_monthly { mark_selections(&mut mark, &list, keep_monthly as usize, |info| { - strftime_local("%Y/%m", info.backup_dir.backup_time()) + strftime_local("%Y/%m", info.backup_dir.backup_time()).map_err(Error::from) })?; } if let Some(keep_yearly) = options.keep_yearly { mark_selections(&mut mark, &list, keep_yearly as usize, |info| { - strftime_local("%Y", info.backup_dir.backup_time()) + strftime_local("%Y", info.backup_dir.backup_time()).map_err(Error::from) })?; } diff --git a/pbs-datastore/src/snapshot_reader.rs b/pbs-datastore/src/snapshot_reader.rs index c49cf16f..c386256d 100644 --- a/pbs-datastore/src/snapshot_reader.rs +++ b/pbs-datastore/src/snapshot_reader.rs @@ -107,7 +107,7 @@ impl <'a> Iterator for SnapshotChunkIterator<'a> { type Item = Result<[u8; 32], Error>; fn next(&mut self) -> Option { - proxmox::try_block!({ + proxmox_lang::try_block!({ loop { if self.current_index.is_none() { if let Some(filename) = self.todo_list.pop() { diff --git a/pbs-fuse-loop/Cargo.toml b/pbs-fuse-loop/Cargo.toml index b9e30d21..1da2aec8 100644 --- a/pbs-fuse-loop/Cargo.toml +++ b/pbs-fuse-loop/Cargo.toml @@ -14,7 +14,7 @@ nix = "0.19.1" regex = "1.2" tokio = { version = "1.6", features = [] } -proxmox = "0.14.0" +proxmox-time = "1" proxmox-fuse = "0.1.1" pbs-tools = { path = "../pbs-tools" } diff --git a/pbs-fuse-loop/src/fuse_loop.rs b/pbs-fuse-loop/src/fuse_loop.rs index 66937f07..fedb7dfd 100644 --- a/pbs-fuse-loop/src/fuse_loop.rs +++ b/pbs-fuse-loop/src/fuse_loop.rs @@ -1,29 +1,29 @@ //! Map a raw data reader as a loop device via FUSE -use anyhow::{Error, format_err, bail}; +use anyhow::{bail, format_err, Error}; +use std::collections::HashMap; use std::ffi::OsStr; -use std::path::{Path, PathBuf}; -use std::fs::{File, remove_file, read_to_string, OpenOptions}; -use std::io::SeekFrom; +use std::fs::{read_to_string, remove_file, File, OpenOptions}; use std::io::prelude::*; -use std::collections::HashMap; +use std::io::SeekFrom; +use std::path::{Path, PathBuf}; -use nix::unistd::Pid; use nix::sys::signal::{self, Signal}; +use nix::unistd::Pid; +use regex::Regex; -use tokio::io::{AsyncRead, AsyncSeek, AsyncReadExt, AsyncSeekExt}; +use futures::channel::mpsc::{Receiver, Sender}; use futures::stream::{StreamExt, TryStreamExt}; -use futures::channel::mpsc::{Sender, Receiver}; +use tokio::io::{AsyncRead, AsyncReadExt, AsyncSeek, AsyncSeekExt}; -use proxmox::const_regex; -use proxmox::tools::time; -use proxmox_fuse::{*, requests::FuseRequest}; use super::loopdev; +use proxmox_fuse::{requests::FuseRequest, *}; +use proxmox_time::epoch_i64; const RUN_DIR: &str = "/run/pbs-loopdev"; -const_regex! { - pub LOOPDEV_REGEX = r"^loop\d+$"; +lazy_static::lazy_static! { + static ref LOOPDEV_REGEX: Regex = Regex::new(r"^loop\d+$").unwrap(); } /// Represents an ongoing FUSE-session that has been mapped onto a loop device. @@ -40,12 +40,14 @@ pub struct FuseLoopSession { } impl FuseLoopSession { - /// Prepare for mapping the given reader as a block device node at /// /dev/loopN. Creates a temporary file for FUSE and a PID file for unmap. - pub async fn map_loop>(size: u64, mut reader: R, name: P, options: &OsStr) - -> Result - { + pub async fn map_loop>( + size: u64, + mut reader: R, + name: P, + options: &OsStr, + ) -> Result { // attempt a single read to check if the reader is configured correctly let _ = reader.read_u8().await?; @@ -61,14 +63,14 @@ impl FuseLoopSession { cleanup_unused_run_files(Some(name.as_ref().to_owned())); match OpenOptions::new().write(true).create_new(true).open(&path) { - Ok(_) => { /* file created, continue on */ }, + Ok(_) => { /* file created, continue on */ } Err(e) => { if e.kind() == std::io::ErrorKind::AlreadyExists { bail!("the given archive is already mapped, cannot map twice"); } else { bail!("error while creating backing file ({:?}) - {}", &path, e); } - }, + } } let session = Fuse::builder("pbs-block-dev")? @@ -77,9 +79,8 @@ impl FuseLoopSession { .build()? .mount(&path)?; - let loopdev_path = loopdev::get_or_create_free_dev().map_err(|err| { - format_err!("loop-control GET_FREE failed - {}", err) - })?; + let loopdev_path = loopdev::get_or_create_free_dev() + .map_err(|err| format_err!("loop-control GET_FREE failed - {}", err))?; // write pidfile so unmap can later send us a signal to exit Self::write_pidfile(&pid_path)?; @@ -111,7 +112,6 @@ impl FuseLoopSession { mut startup_chan: Sender>, abort_chan: Receiver<()>, ) -> Result<(), Error> { - if self.session.is_none() { panic!("internal error: fuse_loop::main called before ::map_loop"); } @@ -121,7 +121,10 @@ impl FuseLoopSession { let (loopdev_path, fuse_path) = (self.loopdev_path.clone(), self.fuse_path.clone()); tokio::task::spawn_blocking(move || { if let Err(err) = loopdev::assign(loopdev_path, fuse_path) { - let _ = startup_chan.try_send(Err(format_err!("error while assigning loop device - {}", err))); + let _ = startup_chan.try_send(Err(format_err!( + "error while assigning loop device - {}", + err + ))); } else { // device is assigned successfully, which means not only is the // loopdev ready, but FUSE is also okay, since the assignment @@ -130,16 +133,17 @@ impl FuseLoopSession { } }); - let (loopdev_path, fuse_path, pid_path) = - (self.loopdev_path.clone(), self.fuse_path.clone(), self.pid_path.clone()); + let (loopdev_path, fuse_path, pid_path) = ( + self.loopdev_path.clone(), + self.fuse_path.clone(), + self.pid_path.clone(), + ); let cleanup = |session: futures::stream::Fuse| { // only warn for errors on cleanup, if these fail nothing is lost if let Err(err) = loopdev::unassign(&loopdev_path) { eprintln!( "cleanup: warning: could not unassign file {} from loop device {} - {}", - &fuse_path, - &loopdev_path, - err, + &fuse_path, &loopdev_path, err, ); } @@ -149,21 +153,19 @@ impl FuseLoopSession { if let Err(err) = remove_file(&fuse_path) { eprintln!( "cleanup: warning: could not remove temporary file {} - {}", - &fuse_path, - err, + &fuse_path, err, ); } if let Err(err) = remove_file(&pid_path) { eprintln!( "cleanup: warning: could not remove PID file {} - {}", - &pid_path, - err, + &pid_path, err, ); } }; loop { - tokio::select!{ + tokio::select! { _ = abort_chan.next() => { // aborted, do cleanup and exit break; @@ -227,8 +229,8 @@ impl FuseLoopSession { pub fn cleanup_unused_run_files(filter_name: Option) { if let Ok(maps) = find_all_mappings() { for (name, loopdev) in maps { - if loopdev.is_none() && - (filter_name.is_none() || &name == filter_name.as_ref().unwrap()) + if loopdev.is_none() + && (filter_name.is_none() || &name == filter_name.as_ref().unwrap()) { let mut path = PathBuf::from(RUN_DIR); path.push(&name); @@ -254,10 +256,17 @@ pub fn cleanup_unused_run_files(filter_name: Option) { } fn get_backing_file(loopdev: &str) -> Result { - let num = loopdev.split_at(9).1.parse::().map_err(|err| - format_err!("malformed loopdev path, does not end with valid number - {}", err))?; + let num = loopdev.split_at(9).1.parse::().map_err(|err| { + format_err!( + "malformed loopdev path, does not end with valid number - {}", + err + ) + })?; - let block_path = PathBuf::from(format!("/sys/devices/virtual/block/loop{}/loop/backing_file", num)); + let block_path = PathBuf::from(format!( + "/sys/devices/virtual/block/loop{}/loop/backing_file", + num + )); let backing_file = read_to_string(block_path).map_err(|err| { if err.kind() == std::io::ErrorKind::NotFound { format_err!("nothing mapped to {}", loopdev) @@ -281,7 +290,7 @@ fn get_backing_file(loopdev: &str) -> Result { // call in broken state: we found the mapping, but the client is already dead, // only thing to do is clean up what we can -fn emerg_cleanup (loopdev: Option<&str>, mut backing_file: PathBuf) { +fn emerg_cleanup(loopdev: Option<&str>, mut backing_file: PathBuf) { eprintln!( "warning: found mapping with dead process ({:?}), attempting cleanup", &backing_file @@ -312,35 +321,36 @@ fn unmap_from_backing(backing_file: &Path, loopdev: Option<&str>) -> Result<(), } format_err!("error reading pidfile {:?}: {}", &pid_path, err) })?; - let pid = pid_str.parse::().map_err(|err| - format_err!("malformed PID ({}) in pidfile - {}", pid_str, err))?; + let pid = pid_str + .parse::() + .map_err(|err| format_err!("malformed PID ({}) in pidfile - {}", pid_str, err))?; let pid = Pid::from_raw(pid); // send SIGINT to trigger cleanup and exit in target process match signal::kill(pid, Signal::SIGINT) { - Ok(()) => {}, + Ok(()) => {} Err(nix::Error::Sys(nix::errno::Errno::ESRCH)) => { emerg_cleanup(loopdev, backing_file.to_owned()); return Ok(()); - }, + } Err(e) => return Err(e.into()), } // block until unmap is complete or timeout - let start = time::epoch_i64(); + let start = epoch_i64(); loop { match signal::kill(pid, None) { Ok(_) => { // 10 second timeout, then assume failure - if (time::epoch_i64() - start) > 10 { + if (epoch_i64() - start) > 10 { return Err(format_err!("timed out waiting for PID '{}' to exit", &pid)); } std::thread::sleep(std::time::Duration::from_millis(100)); - }, + } Err(nix::Error::Sys(nix::errno::Errno::ESRCH)) => { break; - }, + } Err(e) => return Err(e.into()), } } @@ -360,13 +370,13 @@ pub fn find_all_mappings() -> Result { let file = ent.file_name().to_string_lossy(); @@ -376,10 +386,11 @@ pub fn find_all_mappings() -> Result None, } - })) + }), + ) } /// Try and unmap a running proxmox-backup-client instance from the given diff --git a/pbs-tape/Cargo.toml b/pbs-tape/Cargo.toml index 461fbb93..94be071d 100644 --- a/pbs-tape/Cargo.toml +++ b/pbs-tape/Cargo.toml @@ -18,7 +18,16 @@ bitflags = "1.2.1" regex = "1.2" udev = ">= 0.3, <0.5" -proxmox = { version = "0.14.0", default-features = false, features = [] } +proxmox = "0.14.0" +proxmox-io = "1" +proxmox-lang = "1" +# api-macro is only used by the binaries, so maybe we should split them out +proxmox-schema = { version = "1", features = [ "api-macro" ] } +proxmox-time = "1" +proxmox-uuid = "1" + +# router::cli is only used by binaries, so maybe we should split them out +proxmox-router = "1" pbs-api-types = { path = "../pbs-api-types" } pbs-tools = { path = "../pbs-tools" } diff --git a/pbs-tape/src/bin/pmt.rs b/pbs-tape/src/bin/pmt.rs index d36de114..281c0df0 100644 --- a/pbs-tape/src/bin/pmt.rs +++ b/pbs-tape/src/bin/pmt.rs @@ -18,19 +18,9 @@ use std::convert::TryInto; use anyhow::{bail, Error}; use serde_json::Value; -use proxmox::{ - api::{ - api, - cli::*, - schema::{ - Schema, - IntegerSchema, - StringSchema, - ArraySchema, - }, - RpcEnvironment, - }, -}; +use proxmox_schema::{api, ArraySchema, IntegerSchema, Schema, StringSchema}; +use proxmox_router::cli::*; +use proxmox_router::RpcEnvironment; use pbs_api_types::{ LTO_DRIVE_PATH_SCHEMA, DRIVE_NAME_SCHEMA, LtoTapeDrive, diff --git a/pbs-tape/src/bin/pmtx.rs b/pbs-tape/src/bin/pmtx.rs index ea0478c7..7191060b 100644 --- a/pbs-tape/src/bin/pmtx.rs +++ b/pbs-tape/src/bin/pmtx.rs @@ -17,13 +17,9 @@ use std::fs::File; use anyhow::{bail, Error}; use serde_json::Value; -use proxmox::{ - api::{ - api, - cli::*, - RpcEnvironment, - }, -}; +use proxmox_schema::api; +use proxmox_router::cli::*; +use proxmox_router::RpcEnvironment; use pbs_config::drive::complete_changer_name; use pbs_api_types::{ @@ -93,7 +89,7 @@ fn inquiry( let output_format = get_output_format(¶m); - let result: Result<_, Error> = proxmox::try_block!({ + let result: Result<_, Error> = proxmox_lang::try_block!({ let mut file = get_changer_handle(¶m)?; let info = scsi_inquiry(&mut file)?; Ok(info) @@ -281,7 +277,7 @@ fn status( let output_format = get_output_format(¶m); - let result: Result<_, Error> = proxmox::try_block!({ + let result: Result<_, Error> = proxmox_lang::try_block!({ let mut file = get_changer_handle(¶m)?; let status = sg_pt_changer::read_element_status(&mut file)?; Ok(status) diff --git a/pbs-tape/src/blocked_writer.rs b/pbs-tape/src/blocked_writer.rs index 8220d3eb..91893e06 100644 --- a/pbs-tape/src/blocked_writer.rs +++ b/pbs-tape/src/blocked_writer.rs @@ -1,4 +1,4 @@ -use proxmox::tools::vec; +use proxmox_io::vec; use crate::{ TapeWrite, diff --git a/pbs-tape/src/emulate_tape_reader.rs b/pbs-tape/src/emulate_tape_reader.rs index 34d6606c..fe0a5fe4 100644 --- a/pbs-tape/src/emulate_tape_reader.rs +++ b/pbs-tape/src/emulate_tape_reader.rs @@ -1,6 +1,6 @@ use std::io::Read; -use proxmox::tools::io::ReadExt; +use proxmox_io::ReadExt; use crate::{BlockRead, BlockReadError, PROXMOX_TAPE_BLOCK_SIZE}; diff --git a/pbs-tape/src/lib.rs b/pbs-tape/src/lib.rs index 27f9b44e..27522002 100644 --- a/pbs-tape/src/lib.rs +++ b/pbs-tape/src/lib.rs @@ -6,8 +6,8 @@ use endian_trait::Endian; use serde::{Serialize, Deserialize}; use serde_json::Value; -use proxmox::tools::Uuid; -use proxmox::api::schema::parse_property_string; +use proxmox_schema::parse_property_string; +use proxmox_uuid::Uuid; use pbs_api_types::{ScsiTapeChanger, SLOT_ARRAY_SCHEMA}; @@ -119,13 +119,13 @@ impl MediaContentHeader { /// Create a new instance with autogenerated Uuid pub fn new(content_magic: [u8; 8], size: u32) -> Self { - let uuid = *proxmox::tools::uuid::Uuid::generate() + let uuid = *Uuid::generate() .into_inner(); Self { magic: PROXMOX_BACKUP_CONTENT_HEADER_MAGIC_1_0, content_magic, uuid, - ctime: proxmox::tools::time::epoch_i64(), + ctime: proxmox_time::epoch_i64(), size, part_number: 0, reserved_0: 0, diff --git a/pbs-tape/src/sg_pt_changer.rs b/pbs-tape/src/sg_pt_changer.rs index 223079d2..b73de930 100644 --- a/pbs-tape/src/sg_pt_changer.rs +++ b/pbs-tape/src/sg_pt_changer.rs @@ -8,7 +8,7 @@ use std::fs::{OpenOptions, File}; use anyhow::{bail, format_err, Error}; use endian_trait::Endian; -use proxmox::tools::io::ReadExt; +use proxmox_io::ReadExt; use pbs_api_types::ScsiTapeChanger; @@ -139,7 +139,7 @@ fn read_element_address_assignment( let data = execute_scsi_command(&mut sg_raw, &cmd, "read element address assignment", true)?; - proxmox::try_block!({ + proxmox_lang::try_block!({ let mut reader = &data[..]; let page: AddressAssignmentPage = unsafe { reader.read_be_value()? }; @@ -662,7 +662,7 @@ fn decode_element_status_page( start_element_address: u16, ) -> Result { - proxmox::try_block!({ + proxmox_lang::try_block!({ let mut result = DecodedStatusPage { last_element_address: None, diff --git a/pbs-tape/src/sg_tape.rs b/pbs-tape/src/sg_tape.rs index c41de85f..7d4ba84c 100644 --- a/pbs-tape/src/sg_tape.rs +++ b/pbs-tape/src/sg_tape.rs @@ -25,10 +25,8 @@ pub use mam::*; mod report_density; pub use report_density::*; -use proxmox::{ - sys::error::SysResult, - tools::io::{ReadExt, WriteExt}, -}; +use proxmox::sys::error::SysResult; +use proxmox_io::{ReadExt, WriteExt}; use pbs_api_types::{MamAttribute, Lp17VolumeStatistics, LtoDriveAndMediaStatus}; @@ -386,7 +384,7 @@ impl SgTape { let data = sg_raw.do_command(&cmd) .map_err(|err| format_err!("read position failed - {}", err))?; - let page = proxmox::try_block!({ + let page = proxmox_lang::try_block!({ if data.len() != expected_size { bail!("got unexpected data len ({} != {}", data.len(), expected_size); } @@ -793,7 +791,7 @@ impl SgTape { let (head, block_descriptor, page): (_,_, MediumConfigurationModePage) = scsi_mode_sense(&mut self.file, false, 0x1d, 0)?; - proxmox::try_block!({ + proxmox_lang::try_block!({ if (page.page_code & 0b0011_1111) != 0x1d { bail!("wrong page code {}", page.page_code); } @@ -817,7 +815,7 @@ impl SgTape { let (head, block_descriptor, page): (_,_, DataCompressionModePage) = scsi_mode_sense(&mut self.file, false, 0x0f, 0)?; - proxmox::try_block!({ + proxmox_lang::try_block!({ if (page.page_code & 0b0011_1111) != 0x0f { bail!("wrong page code {}", page.page_code); } diff --git a/pbs-tape/src/sg_tape/encryption.rs b/pbs-tape/src/sg_tape/encryption.rs index 6d99d317..def1fbff 100644 --- a/pbs-tape/src/sg_tape/encryption.rs +++ b/pbs-tape/src/sg_tape/encryption.rs @@ -4,7 +4,7 @@ use std::io::Write; use anyhow::{bail, format_err, Error}; use endian_trait::Endian; -use proxmox::tools::io::{ReadExt, WriteExt}; +use proxmox_io::{ReadExt, WriteExt}; use crate::sgutils2::{SgRaw, alloc_page_aligned_buffer}; @@ -216,7 +216,7 @@ struct SspDataEncryptionAlgorithmDescriptor { // Returns the algorythm_index for AES-CGM fn decode_spin_data_encryption_caps(data: &[u8]) -> Result { - proxmox::try_block!({ + proxmox_lang::try_block!({ let mut reader = &data[..]; let _page: SspDataEncryptionCapabilityPage = unsafe { reader.read_be_value()? }; @@ -267,7 +267,7 @@ struct SspDataEncryptionStatusPage { fn decode_spin_data_encryption_status(data: &[u8]) -> Result { - proxmox::try_block!({ + proxmox_lang::try_block!({ let mut reader = &data[..]; let page: SspDataEncryptionStatusPage = unsafe { reader.read_be_value()? }; diff --git a/pbs-tape/src/sg_tape/mam.rs b/pbs-tape/src/sg_tape/mam.rs index b9796940..e006ea43 100644 --- a/pbs-tape/src/sg_tape/mam.rs +++ b/pbs-tape/src/sg_tape/mam.rs @@ -5,7 +5,7 @@ use std::os::unix::io::AsRawFd; use anyhow::{bail, format_err, Error}; use endian_trait::Endian; -use proxmox::tools::io::ReadExt; +use proxmox_io::ReadExt; use pbs_api_types::MamAttribute; @@ -211,7 +211,7 @@ pub fn mam_extract_media_usage(mam: &[MamAttribute]) -> Result(file: &mut F) -> Result { let mut max_density = 0u8; - proxmox::try_block!({ + proxmox_lang::try_block!({ let mut reader = &data[..]; let page_len: u16 = unsafe { reader.read_be_value()? }; diff --git a/pbs-tape/src/sg_tape/tape_alert_flags.rs b/pbs-tape/src/sg_tape/tape_alert_flags.rs index 481618f4..afd26285 100644 --- a/pbs-tape/src/sg_tape/tape_alert_flags.rs +++ b/pbs-tape/src/sg_tape/tape_alert_flags.rs @@ -3,7 +3,7 @@ use std::os::unix::io::AsRawFd; use anyhow::{bail, format_err, Error}; -use proxmox::tools::io::ReadExt; +use proxmox_io::ReadExt; use crate::sgutils2::SgRaw; @@ -106,7 +106,7 @@ fn sg_read_tape_alert_flags(file: &mut F) -> Result, Error> fn decode_tape_alert_flags(data: &[u8]) -> Result { - proxmox::try_block!({ + proxmox_lang::try_block!({ if !((data[0] & 0x7f) == 0x12 && data[1] == 0) { bail!("invalid response"); } diff --git a/pbs-tape/src/sg_tape/volume_statistics.rs b/pbs-tape/src/sg_tape/volume_statistics.rs index cc60da10..e8790e3f 100644 --- a/pbs-tape/src/sg_tape/volume_statistics.rs +++ b/pbs-tape/src/sg_tape/volume_statistics.rs @@ -4,7 +4,7 @@ use std::os::unix::io::AsRawFd; use anyhow::{bail, format_err, Error}; use endian_trait::Endian; -use proxmox::tools::io::ReadExt; +use proxmox_io::ReadExt; use pbs_api_types::Lp17VolumeStatistics; @@ -71,7 +71,7 @@ fn decode_volume_statistics(data: &[u8]) -> Result Ok(value) }; - proxmox::try_block!({ + proxmox_lang::try_block!({ if !((data[0] & 0x7f) == 0x17 && data[1] == 0) { bail!("invalid response"); } diff --git a/pbs-tape/src/sgutils2.rs b/pbs-tape/src/sgutils2.rs index 78527554..8ba0ad29 100644 --- a/pbs-tape/src/sgutils2.rs +++ b/pbs-tape/src/sgutils2.rs @@ -6,16 +6,16 @@ //! //! The SCSI Commands Reference Manual also contains some useful information. +use std::ffi::CStr; use std::os::unix::io::AsRawFd; use std::ptr::NonNull; use anyhow::{bail, format_err, Error}; use endian_trait::Endian; -use serde::{Deserialize, Serialize}; use libc::{c_char, c_int}; -use std::ffi::CStr; +use serde::{Deserialize, Serialize}; -use proxmox::tools::io::ReadExt; +use proxmox_io::ReadExt; #[derive(thiserror::Error, Debug)] pub struct SenseInfo { @@ -379,7 +379,7 @@ pub fn get_asc_ascq_string(asc: u8, ascq: u8) -> String { ) }; - proxmox::try_block!({ + proxmox_lang::try_block!({ if res.is_null() { // just to be safe bail!("unexpected NULL ptr"); } @@ -675,7 +675,7 @@ pub fn scsi_inquiry( let data = sg_raw.do_command(&cmd) .map_err(|err| format_err!("SCSI inquiry failed - {}", err))?; - proxmox::try_block!({ + proxmox_lang::try_block!({ let mut reader = &data[..]; let page: InquiryPage = unsafe { reader.read_be_value()? }; @@ -724,7 +724,7 @@ pub fn scsi_mode_sense( let data = sg_raw.do_command(&cmd) .map_err(|err| format_err!("mode sense failed - {}", err))?; - proxmox::try_block!({ + proxmox_lang::try_block!({ let mut reader = &data[..]; let head: ModeParameterHeader = unsafe { reader.read_be_value()? }; @@ -777,7 +777,7 @@ pub fn scsi_request_sense( let data = sg_raw.do_command(&cmd) .map_err(|err| format_err!("request sense failed - {}", err))?; - let sense = proxmox::try_block!({ + let sense = proxmox_lang::try_block!({ let data_len = data.len(); if data_len < std::mem::size_of::() { diff --git a/pbs-tools/Cargo.toml b/pbs-tools/Cargo.toml index 0ff71545..5c87c065 100644 --- a/pbs-tools/Cargo.toml +++ b/pbs-tools/Cargo.toml @@ -15,7 +15,7 @@ endian_trait = { version = "0.6", features = ["arrays"] } flate2 = "1.0" foreign-types = "0.3" futures = "0.3" -hex = "0.4" +hex = "0.4.3" lazy_static = "1.4" libc = "0.2" log = "0.4" @@ -33,9 +33,9 @@ walkdir = "2" zstd = { version = "0.6", features = [ "bindgen" ] } proxmox = { version = "0.14.0", default-features = false, features = [ "tokio" ] } -proxmox-io = { version = "1.0.0" } -proxmox-lang = { version = "1.0.0" } -proxmox-time = { version = "1.0.0" } +proxmox-io = { version = "1", features = [ "tokio" ] } +proxmox-lang = { version = "1" } +proxmox-time = { version = "1" } pbs-buildcfg = { path = "../pbs-buildcfg" } pbs-runtime = { path = "../pbs-runtime" } diff --git a/pbs-tools/src/cert.rs b/pbs-tools/src/cert.rs index d24850a7..189d0757 100644 --- a/pbs-tools/src/cert.rs +++ b/pbs-tools/src/cert.rs @@ -24,7 +24,7 @@ fn asn1_time_to_unix(time: &openssl::asn1::Asn1TimeRef) -> Result { bail!("failed to parse ASN1 time"); } let mut c_tm = unsafe { c_tm.assume_init() }; - proxmox::tools::time::timegm(&mut c_tm) + Ok(proxmox_time::timegm(&mut c_tm)?) } pub struct CertInfo { @@ -66,10 +66,11 @@ impl CertInfo { pub fn fingerprint(&self) -> Result { let fp = self.x509.digest(openssl::hash::MessageDigest::sha256())?; - let fp_string = proxmox::tools::digest_to_hex(&fp); - let fp_string = fp_string.as_bytes().chunks(2).map(|v| std::str::from_utf8(v).unwrap()) - .collect::>().join(":"); - Ok(fp_string) + Ok(hex::encode(&fp) + .as_bytes() + .chunks(2) + .map(|v| std::str::from_utf8(v).unwrap()) + .collect::>().join(":")) } pub fn public_key(&self) -> Result, Error> { diff --git a/pbs-tools/src/compression.rs b/pbs-tools/src/compression.rs index e2b6d795..aa1b0b24 100644 --- a/pbs-tools/src/compression.rs +++ b/pbs-tools/src/compression.rs @@ -10,7 +10,7 @@ use futures::stream::Stream; use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; use proxmox::io_format_err; -use proxmox::tools::byte_buffer::ByteBuffer; +use proxmox_io::ByteBuffer; const BUFFER_SIZE: usize = 8192; diff --git a/pbs-tools/src/format.rs b/pbs-tools/src/format.rs index 88714003..0823ea29 100644 --- a/pbs-tools/src/format.rs +++ b/pbs-tools/src/format.rs @@ -25,7 +25,7 @@ pub fn render_epoch(value: &Value, _record: &Value) -> Result { if value.is_null() { return Ok(String::new()); } let text = match value.as_i64() { Some(epoch) => { - if let Ok(epoch_string) = proxmox::tools::time::strftime_local("%c", epoch as i64) { + if let Ok(epoch_string) = proxmox_time::strftime_local("%c", epoch as i64) { epoch_string } else { epoch.to_string() @@ -104,14 +104,16 @@ impl From for HumanByte { } pub fn as_fingerprint(bytes: &[u8]) -> String { - proxmox::tools::digest_to_hex(bytes) + hex::encode(bytes) .as_bytes() .chunks(2) - .map(|v| std::str::from_utf8(v).unwrap()) + .map(|v| unsafe { std::str::from_utf8_unchecked(v) }) // it's a hex string .collect::>().join(":") } pub mod bytes_as_fingerprint { + use std::mem::MaybeUninit; + use serde::{Deserialize, Serializer, Deserializer}; pub fn serialize( @@ -131,9 +133,14 @@ pub mod bytes_as_fingerprint { where D: Deserializer<'de>, { + // TODO: more efficiently implement with a Visitor implementing visit_str using split() and + // hex::decode by-byte let mut s = String::deserialize(deserializer)?; s.retain(|c| c != ':'); - proxmox::tools::hex_to_digest(&s).map_err(serde::de::Error::custom) + let mut out = MaybeUninit::<[u8; 32]>::uninit(); + hex::decode_to_slice(s.as_bytes(), unsafe { &mut (*out.as_mut_ptr())[..] }) + .map_err(serde::de::Error::custom)?; + Ok(unsafe { out.assume_init() }) } } diff --git a/pbs-tools/src/sha.rs b/pbs-tools/src/sha.rs index 56cdc683..7ec89eed 100644 --- a/pbs-tools/src/sha.rs +++ b/pbs-tools/src/sha.rs @@ -4,10 +4,12 @@ use std::io::Read; use anyhow::Error; +use proxmox_io::vec; + /// Calculate the sha256sum from a readable object. pub fn sha256(file: &mut dyn Read) -> Result<([u8; 32], u64), Error> { let mut hasher = openssl::sha::Sha256::new(); - let mut buffer = proxmox::tools::vec::undefined(256 * 1024); + let mut buffer = vec::undefined(256 * 1024); let mut size: u64 = 0; loop { diff --git a/pbs-tools/src/stream.rs b/pbs-tools/src/stream.rs index c00c1354..cfee01cc 100644 --- a/pbs-tools/src/stream.rs +++ b/pbs-tools/src/stream.rs @@ -13,8 +13,8 @@ use futures::future::FutureExt; use futures::stream::Stream; use proxmox::io_format_err; -use proxmox::tools::byte_buffer::ByteBuffer; use proxmox::sys::error::io_err_other; +use proxmox_io::ByteBuffer; use pbs_runtime::block_in_place; diff --git a/pbs-tools/src/ticket.rs b/pbs-tools/src/ticket.rs index b4e41619..dd928635 100644 --- a/pbs-tools/src/ticket.rs +++ b/pbs-tools/src/ticket.rs @@ -66,7 +66,7 @@ where Ok(Self { prefix: Cow::Borrowed(prefix), data: data.to_string(), - time: proxmox::tools::time::epoch_i64(), + time: proxmox_time::epoch_i64(), signature: None, _type_marker: PhantomData, }) @@ -171,7 +171,7 @@ where None => bail!("invalid ticket without signature"), }; - let age = proxmox::tools::time::epoch_i64() - self.time; + let age = proxmox_time::epoch_i64() - self.time; if age < time_frame.start { bail!("invalid ticket - timestamp newer than expected"); } @@ -325,7 +325,7 @@ mod test { false }); simple_test(&key, None, |t| { - t.change_time(proxmox::tools::time::epoch_i64() + 0x1000_0000); + t.change_time(proxmox_time::epoch_i64() + 0x1000_0000); false }); } diff --git a/pbs-tools/src/xattr.rs b/pbs-tools/src/xattr.rs index f088b12c..47637356 100644 --- a/pbs-tools/src/xattr.rs +++ b/pbs-tools/src/xattr.rs @@ -5,8 +5,8 @@ use std::os::unix::io::RawFd; use nix::errno::Errno; -use proxmox::c_str; -use proxmox::tools::vec; +use proxmox_io::vec; +use proxmox_lang::c_str; /// `"security.capability"` as a CStr to avoid typos. /// @@ -187,7 +187,7 @@ mod tests { use nix::errno::Errno; - use proxmox::c_str; + use proxmox_lang::c_str; #[test] fn test_fsetxattr_fgetxattr() { diff --git a/pbs-tools/src/zip.rs b/pbs-tools/src/zip.rs index 605480a8..0e85dd25 100644 --- a/pbs-tools/src/zip.rs +++ b/pbs-tools/src/zip.rs @@ -20,7 +20,7 @@ use futures::ready; use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, ReadBuf}; use crc32fast::Hasher; -use proxmox::tools::time::gmtime; +use proxmox_time::gmtime; use crate::compression::{DeflateEncoder, Level}; diff --git a/proxmox-backup-client/Cargo.toml b/proxmox-backup-client/Cargo.toml index 03d2c0ed..0b84e176 100644 --- a/proxmox-backup-client/Cargo.toml +++ b/proxmox-backup-client/Cargo.toml @@ -22,7 +22,10 @@ zstd = { version = "0.6", features = [ "bindgen" ] } pathpatterns = "0.1.2" pxar = { version = "0.10.1", features = [ "tokio-io" ] } -proxmox = { version = "0.14.0", features = [ "sortable-macro", "api-macro", "cli", "router" ] } +proxmox = { version = "0.14.0", features = [ "sortable-macro" ] } +proxmox-router = { version = "1", features = [ "cli" ] } +proxmox-schema = { version = "1", features = [ "api-macro" ] } +proxmox-time = "1" pbs-api-types = { path = "../pbs-api-types" } pbs-buildcfg = { path = "../pbs-buildcfg" } diff --git a/proxmox-backup-client/src/benchmark.rs b/proxmox-backup-client/src/benchmark.rs index e951b305..58cdb4ad 100644 --- a/proxmox-backup-client/src/benchmark.rs +++ b/proxmox-backup-client/src/benchmark.rs @@ -5,9 +5,8 @@ use anyhow::{Error}; use serde_json::Value; use serde::Serialize; -use proxmox::api::{ApiMethod, RpcEnvironment}; -use proxmox::api::{ - api, +use proxmox_schema::{api, ApiType, ReturnType}; +use proxmox_router::{ cli::{ OUTPUT_FORMAT, ColumnConfig, @@ -15,8 +14,8 @@ use proxmox::api::{ format_and_print_result_full, default_table_format_options, }, - router::ReturnType, - schema::ApiType, + ApiMethod, + RpcEnvironment, }; use pbs_tools::crypt_config::CryptConfig; @@ -222,7 +221,7 @@ async fn test_upload_speed( verbose: bool, ) -> Result<(), Error> { - let backup_time = proxmox::tools::time::epoch_i64(); + let backup_time = proxmox_time::epoch_i64(); let client = connect(&repo)?; record_repository(&repo); diff --git a/proxmox-backup-client/src/bin/dump-catalog-shell-cli.rs b/proxmox-backup-client/src/bin/dump-catalog-shell-cli.rs index 37ce36ea..4c538407 100644 --- a/proxmox-backup-client/src/bin/dump-catalog-shell-cli.rs +++ b/proxmox-backup-client/src/bin/dump-catalog-shell-cli.rs @@ -1,7 +1,7 @@ use anyhow::{Error}; -use proxmox::api::format::*; -use proxmox::api::cli::*; +use proxmox_router::cli::*; +use proxmox_schema::format::*; use pbs_client::catalog_shell::catalog_shell_cli; diff --git a/proxmox-backup-client/src/catalog.rs b/proxmox-backup-client/src/catalog.rs index 186de913..60b7c2e0 100644 --- a/proxmox-backup-client/src/catalog.rs +++ b/proxmox-backup-client/src/catalog.rs @@ -5,7 +5,8 @@ use std::sync::Arc; use anyhow::{bail, format_err, Error}; use serde_json::Value; -use proxmox::api::{api, cli::*}; +use proxmox_schema::api; +use proxmox_router::cli::*; use pbs_client::tools::key_source::get_encryption_key_password; use pbs_client::{BackupReader, RemoteChunkReader}; diff --git a/proxmox-backup-client/src/key.rs b/proxmox-backup-client/src/key.rs index 79b70fae..89bbed50 100644 --- a/proxmox-backup-client/src/key.rs +++ b/proxmox-backup-client/src/key.rs @@ -4,15 +4,13 @@ use std::path::PathBuf; use anyhow::{bail, format_err, Error}; use serde_json::Value; -use proxmox::api::api; -use proxmox::api::cli::{ +use proxmox::sys::linux::tty; +use proxmox::tools::fs::{file_get_contents, replace_file, CreateOptions}; +use proxmox_router::cli::{ format_and_print_result_full, get_output_format, CliCommand, CliCommandMap, ColumnConfig, OUTPUT_FORMAT, }; -use proxmox::api::router::ReturnType; -use proxmox::api::schema::ApiType; -use proxmox::sys::linux::tty; -use proxmox::tools::fs::{file_get_contents, replace_file, CreateOptions}; +use proxmox_schema::{api, ApiType, ReturnType}; use pbs_api_types::{RsaPubKeyInfo, PASSWORD_HINT_SCHEMA, Kdf, KeyInfo}; use pbs_config::key_config::{KeyConfig, rsa_decrypt_key_config}; @@ -266,7 +264,7 @@ fn show_key(path: Option, param: Value) -> Result<(), Error> { let mut info: KeyInfo = (&config).into(); info.path = Some(format!("{:?}", path)); - let options = proxmox::api::cli::default_table_format_options() + let options = proxmox_router::cli::default_table_format_options() .column(ColumnConfig::new("path")) .column(ColumnConfig::new("kdf")) .column(ColumnConfig::new("created").renderer(pbs_tools::format::render_epoch)) @@ -394,7 +392,7 @@ fn show_master_pubkey(path: Option, param: Value) -> Result<(), Error> { let mut info = RsaPubKeyInfo::try_from(rsa)?; info.path = Some(path.display().to_string()); - let options = proxmox::api::cli::default_table_format_options() + let options = proxmox_router::cli::default_table_format_options() .column(ColumnConfig::new("path")) .column(ColumnConfig::new("modulus")) .column(ColumnConfig::new("exponent")) diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs index 52cff217..12deb43c 100644 --- a/proxmox-backup-client/src/main.rs +++ b/proxmox-backup-client/src/main.rs @@ -13,18 +13,10 @@ use tokio_stream::wrappers::ReceiverStream; use xdg::BaseDirectories; use pathpatterns::{MatchEntry, MatchType, PatternFlag}; -use proxmox::{ - tools::{ - time::{strftime_local, epoch_i64}, - fs::{file_get_json, replace_file, CreateOptions, image_size}, - }, - api::{ - api, - ApiMethod, - RpcEnvironment, - cli::*, - }, -}; +use proxmox::tools::fs::{file_get_json, replace_file, CreateOptions, image_size}; +use proxmox_router::{ApiMethod, RpcEnvironment, cli::*}; +use proxmox_schema::api; +use proxmox_time::{strftime_local, epoch_i64}; use pxar::accessor::{MaybeReady, ReadAt, ReadAtOperation}; use pbs_api_types::{ diff --git a/proxmox-backup-client/src/mount.rs b/proxmox-backup-client/src/mount.rs index 7c977864..1971eb12 100644 --- a/proxmox-backup-client/src/mount.rs +++ b/proxmox-backup-client/src/mount.rs @@ -14,8 +14,9 @@ use serde_json::Value; use tokio::signal::unix::{signal, SignalKind}; use proxmox::{sortable, identity}; -use proxmox::api::{ApiHandler, ApiMethod, RpcEnvironment, schema::*, cli::*}; use proxmox::tools::fd::Fd; +use proxmox_router::{ApiHandler, ApiMethod, RpcEnvironment, cli::*}; +use proxmox_schema::*; use pbs_tools::crypt_config::CryptConfig; use pbs_config::key_config::load_and_decrypt_key; diff --git a/proxmox-backup-client/src/snapshot.rs b/proxmox-backup-client/src/snapshot.rs index 4465f69a..1e809d3f 100644 --- a/proxmox-backup-client/src/snapshot.rs +++ b/proxmox-backup-client/src/snapshot.rs @@ -3,10 +3,9 @@ use std::sync::Arc; use anyhow::Error; use serde_json::{json, Value}; -use proxmox::{ - api::{api, cli::*}, - tools::fs::file_get_contents, -}; +use proxmox::tools::fs::file_get_contents; +use proxmox_router::cli::*; +use proxmox_schema::api; use pbs_tools::crypt_config::CryptConfig; use pbs_config::key_config::decrypt_key; diff --git a/proxmox-backup-client/src/task.rs b/proxmox-backup-client/src/task.rs index 92d0d69f..5d83a988 100644 --- a/proxmox-backup-client/src/task.rs +++ b/proxmox-backup-client/src/task.rs @@ -1,7 +1,8 @@ use anyhow::{Error}; use serde_json::{json, Value}; -use proxmox::api::{api, cli::*}; +use proxmox_schema::api; +use proxmox_router::cli::*; use pbs_client::display_task_log; use pbs_tools::percent_encoding::percent_encode_component; diff --git a/proxmox-file-restore/Cargo.toml b/proxmox-file-restore/Cargo.toml index a9256a29..2d075e4c 100644 --- a/proxmox-file-restore/Cargo.toml +++ b/proxmox-file-restore/Cargo.toml @@ -16,7 +16,12 @@ tokio = { version = "1.6", features = [ "io-std", "rt", "rt-multi-thread", "time pxar = { version = "0.10.1", features = [ "tokio-io" ] } -proxmox = { version = "0.14.0", features = [ "api-macro", "cli" ] } +proxmox = { version = "0.14.0" } +proxmox-lang = "1" +proxmox-router = { version = "1", features = [ "cli" ] } +proxmox-schema = { version = "1", features = [ "api-macro" ] } +proxmox-time = "1" +proxmox-uuid = "1" pbs-api-types = { path = "../pbs-api-types" } pbs-buildcfg = { path = "../pbs-buildcfg" } diff --git a/proxmox-file-restore/src/block_driver.rs b/proxmox-file-restore/src/block_driver.rs index 14c572fb..f6739690 100644 --- a/proxmox-file-restore/src/block_driver.rs +++ b/proxmox-file-restore/src/block_driver.rs @@ -8,7 +8,8 @@ use anyhow::{bail, Error}; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; -use proxmox::api::{api, cli::*}; +use proxmox_router::cli::*; +use proxmox_schema::api; use pbs_client::BackupRepository; use pbs_datastore::backup_info::BackupDir; diff --git a/proxmox-file-restore/src/block_driver_qemu.rs b/proxmox-file-restore/src/block_driver_qemu.rs index b6eaf83a..74296ab6 100644 --- a/proxmox-file-restore/src/block_driver_qemu.rs +++ b/proxmox-file-restore/src/block_driver_qemu.rs @@ -110,7 +110,7 @@ async fn cleanup_map(map: &mut HashMap) -> bool { } fn new_ticket() -> String { - proxmox::tools::Uuid::generate().to_string() + proxmox_uuid::Uuid::generate().to_string() } async fn ensure_running(details: &SnapRestoreDetails) -> Result { diff --git a/proxmox-file-restore/src/main.rs b/proxmox-file-restore/src/main.rs index 957ce3f0..044bd2bd 100644 --- a/proxmox-file-restore/src/main.rs +++ b/proxmox-file-restore/src/main.rs @@ -6,14 +6,12 @@ use std::sync::Arc; use anyhow::{bail, format_err, Error}; use serde_json::{json, Value}; -use proxmox::api::{ - api, - cli::{ - default_table_format_options, format_and_print_result_full, get_output_format, - run_cli_command, CliCommand, CliCommandMap, CliEnvironment, ColumnConfig, OUTPUT_FORMAT, - }, -}; use proxmox::tools::fs::{create_path, CreateOptions}; +use proxmox_router::cli::{ + default_table_format_options, format_and_print_result_full, get_output_format, + run_cli_command, CliCommand, CliCommandMap, CliEnvironment, ColumnConfig, OUTPUT_FORMAT, +}; +use proxmox_schema::api; use pxar::accessor::aio::Accessor; use pxar::decoder::aio::Decoder; diff --git a/proxmox-file-restore/src/qemu_helper.rs b/proxmox-file-restore/src/qemu_helper.rs index b88e7ed3..377788d9 100644 --- a/proxmox-file-restore/src/qemu_helper.rs +++ b/proxmox-file-restore/src/qemu_helper.rs @@ -24,7 +24,7 @@ const MAX_CID_TRIES: u64 = 32; fn create_restore_log_dir() -> Result { let logpath = format!("{}/file-restore", pbs_buildcfg::PROXMOX_BACKUP_LOG_DIR); - proxmox::try_block!({ + proxmox_lang::try_block!({ let backup_user = backup_user()?; let opts = CreateOptions::new() .owner(backup_user.uid) @@ -163,8 +163,8 @@ pub async fn start_vm( // preface log file with start timestamp so one can see how long QEMU took to start writeln!(logfd, "[{}] PBS file restore VM log", { - let now = proxmox::tools::time::epoch_i64(); - proxmox::tools::time::epoch_to_rfc3339(now)? + let now = proxmox_time::epoch_i64(); + proxmox_time::epoch_to_rfc3339(now)? },)?; let base_args = [ diff --git a/proxmox-rest-server/Cargo.toml b/proxmox-rest-server/Cargo.toml index 2af3ba35..a00986cf 100644 --- a/proxmox-rest-server/Cargo.toml +++ b/proxmox-rest-server/Cargo.toml @@ -7,7 +7,7 @@ description = "REST server implementation" # for example [dev-dependencies] -proxmox = { version = "0.14.0", features = ["router","api-macro"] } +proxmox-schema = { version = "1", features = [ "api-macro" ] } tokio = { version = "1.6", features = [ "rt-multi-thread", "signal", "process" ] } [dependencies] @@ -30,7 +30,12 @@ tokio-openssl = "0.6.1" tower-service = "0.3.0" url = "2.1" -proxmox = { version = "0.14.0", features = [ "router"] } +proxmox = "0.14.0" +proxmox-io = "1" +proxmox-lang = "1" +proxmox-router = "1" +proxmox-schema = { version = "1", features = [ "api-macro", "upid-api-impl" ] } +proxmox-time = "1" # fixme: remove this dependency (pbs_tools::broadcast_future) pbs-tools = { path = "../pbs-tools" } diff --git a/proxmox-rest-server/examples/minimal-rest-server.rs b/proxmox-rest-server/examples/minimal-rest-server.rs index 6400fdbf..1ddcfeb8 100644 --- a/proxmox-rest-server/examples/minimal-rest-server.rs +++ b/proxmox-rest-server/examples/minimal-rest-server.rs @@ -9,8 +9,9 @@ use hyper::{Body, Response, Method}; use http::request::Parts; use http::HeaderMap; -use proxmox::api::{api, router::SubdirMap, Router, RpcEnvironmentType, UserInformation}; -use proxmox::list_subdirs_api_method; +use proxmox_schema::api; +use proxmox_router::{list_subdirs_api_method, SubdirMap, Router, RpcEnvironmentType, UserInformation}; + use proxmox_rest_server::{ServerAdapter, ApiConfig, AuthError, RestServer, RestEnvironment}; // Create a Dummy User information system diff --git a/proxmox-rest-server/src/api_config.rs b/proxmox-rest-server/src/api_config.rs index 99990114..990315dd 100644 --- a/proxmox-rest-server/src/api_config.rs +++ b/proxmox-rest-server/src/api_config.rs @@ -12,8 +12,8 @@ use hyper::http::request::Parts; use handlebars::Handlebars; use serde::Serialize; -use proxmox::api::{ApiMethod, Router, RpcEnvironmentType, UserInformation}; use proxmox::tools::fs::{create_path, CreateOptions}; +use proxmox_router::{ApiMethod, Router, RpcEnvironmentType, UserInformation}; use crate::{ServerAdapter, AuthError, FileLogger, FileLogOptions, CommandSocket, RestEnvironment}; diff --git a/proxmox-rest-server/src/daemon.rs b/proxmox-rest-server/src/daemon.rs index d5ed86b1..cbaaaa7b 100644 --- a/proxmox-rest-server/src/daemon.rs +++ b/proxmox-rest-server/src/daemon.rs @@ -13,8 +13,8 @@ use anyhow::{bail, format_err, Error}; use futures::future::{self, Either}; use nix::unistd::{fork, ForkResult}; -use proxmox::tools::io::{ReadExt, WriteExt}; use proxmox::tools::fd::Fd; +use proxmox_io::{ReadExt, WriteExt}; use pbs_tools::fd::fd_change_cloexec; diff --git a/proxmox-rest-server/src/environment.rs b/proxmox-rest-server/src/environment.rs index 57d0d7d5..3c77d145 100644 --- a/proxmox-rest-server/src/environment.rs +++ b/proxmox-rest-server/src/environment.rs @@ -3,7 +3,7 @@ use std::net::SocketAddr; use serde_json::{json, Value}; -use proxmox::api::{RpcEnvironment, RpcEnvironmentType}; +use proxmox_router::{RpcEnvironment, RpcEnvironmentType}; use crate::ApiConfig; diff --git a/proxmox-rest-server/src/file_logger.rs b/proxmox-rest-server/src/file_logger.rs index b3d5eb20..79972d32 100644 --- a/proxmox-rest-server/src/file_logger.rs +++ b/proxmox-rest-server/src/file_logger.rs @@ -110,8 +110,8 @@ impl FileLogger { } let line = if self.options.prefix_time { - let now = proxmox::tools::time::epoch_i64(); - let rfc3339 = match proxmox::tools::time::epoch_to_rfc3339(now) { + let now = proxmox_time::epoch_i64(); + let rfc3339 = match proxmox_time::epoch_to_rfc3339(now) { Ok(rfc3339) => rfc3339, Err(_) => "1970-01-01T00:00:00Z".into(), // for safety, should really not happen! }; diff --git a/proxmox-rest-server/src/formatter.rs b/proxmox-rest-server/src/formatter.rs index 601a7561..6d050997 100644 --- a/proxmox-rest-server/src/formatter.rs +++ b/proxmox-rest-server/src/formatter.rs @@ -6,7 +6,8 @@ use serde_json::{json, Value}; use hyper::{Body, Response, StatusCode}; use hyper::header; -use proxmox::api::{HttpError, schema::ParameterError, RpcEnvironment}; +use proxmox_router::{HttpError, RpcEnvironment}; +use proxmox_schema::ParameterError; /// Extension to set error message for server side logging pub(crate) struct ErrorMessageExtension(pub String); diff --git a/proxmox-rest-server/src/h2service.rs b/proxmox-rest-server/src/h2service.rs index f7c7b978..f5fcdeea 100644 --- a/proxmox-rest-server/src/h2service.rs +++ b/proxmox-rest-server/src/h2service.rs @@ -8,8 +8,8 @@ use std::task::{Context, Poll}; use futures::*; use hyper::{Body, Request, Response, StatusCode}; -use proxmox::api::{ApiResponseFuture, HttpError, Router, RpcEnvironment}; -use proxmox::http_err; +use proxmox_router::{ApiResponseFuture, HttpError, Router, RpcEnvironment}; +use proxmox_router::http_err; use crate::{normalize_uri_path, WorkerTask}; use crate::formatter::*; diff --git a/proxmox-rest-server/src/lib.rs b/proxmox-rest-server/src/lib.rs index d72936c2..6e7c94f2 100644 --- a/proxmox-rest-server/src/lib.rs +++ b/proxmox-rest-server/src/lib.rs @@ -27,8 +27,8 @@ use http::HeaderMap; use proxmox::tools::fd::Fd; use proxmox::sys::linux::procfs::PidStat; -use proxmox::api::UserInformation; use proxmox::tools::fs::CreateOptions; +use proxmox_router::UserInformation; mod compression; pub use compression::*; diff --git a/proxmox-rest-server/src/rest.rs b/proxmox-rest-server/src/rest.rs index 063b797f..74bc8bb1 100644 --- a/proxmox-rest-server/src/rest.rs +++ b/proxmox-rest-server/src/rest.rs @@ -21,15 +21,15 @@ use tokio::time::Instant; use url::form_urlencoded; use tower_service::Service; -use proxmox::api::schema::{ - parse_parameter_strings, parse_simple_value, verify_json_object, ObjectSchemaType, - ParameterSchema, -}; -use proxmox::api::{ +use proxmox_router::{ check_api_permission, ApiHandler, ApiMethod, HttpError, Permission, RpcEnvironment, RpcEnvironmentType, UserInformation, }; -use proxmox::http_err; +use proxmox_router::http_err; +use proxmox_schema::{ + parse_parameter_strings, parse_simple_value, verify_json_object, ObjectSchemaType, + ParameterSchema, +}; use pbs_tools::compression::{DeflateEncoder, Level}; use pbs_tools::stream::AsyncReaderStream; @@ -192,9 +192,9 @@ fn log_response( Some(AuthStringExtension(auth_id)) => auth_id.clone(), None => "-".to_string(), }; - let now = proxmox::tools::time::epoch_i64(); + let now = proxmox_time::epoch_i64(); // time format which apache/nginx use (by default), copied from pve-http-server - let datetime = proxmox::tools::time::strftime_local("%d/%m/%Y:%H:%M:%S %z", now) + let datetime = proxmox_time::strftime_local("%d/%m/%Y:%H:%M:%S %z", now) .unwrap_or_else(|_| "-".to_string()); logfile.lock().unwrap().log(format!( diff --git a/proxmox-rest-server/src/worker_task.rs b/proxmox-rest-server/src/worker_task.rs index 51394549..fb0dea9b 100644 --- a/proxmox-rest-server/src/worker_task.rs +++ b/proxmox-rest-server/src/worker_task.rs @@ -17,9 +17,9 @@ use nix::fcntl::OFlag; use once_cell::sync::OnceCell; use proxmox::sys::linux::procfs; -use proxmox::try_block; use proxmox::tools::fs::{create_path, replace_file, atomic_open_or_create_file, CreateOptions}; -use proxmox::api::upid::UPID; +use proxmox_lang::try_block; +use proxmox_schema::upid::UPID; use pbs_tools::task::WorkerTaskContext; use pbs_tools::logrotate::{LogRotate, LogRotateFiles}; @@ -120,7 +120,7 @@ impl WorkerTaskSetup { if !worker_is_active_local(&info.upid) { // println!("Detected stopped task '{}'", &info.upid_str); - let now = proxmox::tools::time::epoch_i64(); + let now = proxmox_time::epoch_i64(); let status = upid_read_status(&info.upid).unwrap_or(TaskState::Unknown { endtime: now }); finish_list.push(TaskListInfo { upid: info.upid, @@ -320,7 +320,7 @@ pub fn upid_read_status(upid: &UPID) -> Result { let mut iter = last_line.splitn(2, ": "); if let Some(time_str) = iter.next() { - if let Ok(endtime) = proxmox::tools::time::parse_rfc3339(time_str) { + if let Ok(endtime) = proxmox_time::parse_rfc3339(time_str) { // set the endtime even if we cannot parse the state status = TaskState::Unknown { endtime }; if let Some(rest) = iter.next().and_then(|rest| rest.strip_prefix("TASK ")) { @@ -839,7 +839,7 @@ impl WorkerTask { pub fn create_state(&self, result: &Result<(), Error>) -> TaskState { let warn_count = self.data.lock().unwrap().warn_count; - let endtime = proxmox::tools::time::epoch_i64(); + let endtime = proxmox_time::epoch_i64(); if let Err(err) = result { TaskState::Error { message: err.to_string(), endtime } diff --git a/proxmox-restore-daemon/Cargo.toml b/proxmox-restore-daemon/Cargo.toml index e44717da..54ab9f3a 100644 --- a/proxmox-restore-daemon/Cargo.toml +++ b/proxmox-restore-daemon/Cargo.toml @@ -26,7 +26,10 @@ tokio-util = { version = "0.6", features = [ "codec", "io" ] } pathpatterns = "0.1.2" pxar = { version = "0.10.1", features = [ "tokio-io" ] } -proxmox = { version = "0.14.0", features = [ "router", "sortable-macro" ] } +proxmox = { version = "0.14.0", features = [ "sortable-macro" ] } +proxmox-router = { version = "1", features = [ "cli" ] } +proxmox-schema = { version = "1", features = [ "api-macro" ] } +proxmox-time = "1" pbs-api-types = { path = "../pbs-api-types" } pbs-runtime = { path = "../pbs-runtime" } diff --git a/proxmox-restore-daemon/src/main.rs b/proxmox-restore-daemon/src/main.rs index 6dd25ff5..a1ad6005 100644 --- a/proxmox-restore-daemon/src/main.rs +++ b/proxmox-restore-daemon/src/main.rs @@ -14,7 +14,7 @@ use log::{error, info}; use tokio::sync::mpsc; use tokio_stream::wrappers::ReceiverStream; -use proxmox::api::RpcEnvironmentType; +use proxmox_router::RpcEnvironmentType; use pbs_client::DEFAULT_VSOCK_PORT; use proxmox_rest_server::{ApiConfig, RestServer}; diff --git a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs index 15fe5f00..429ba359 100644 --- a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs +++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs @@ -13,11 +13,12 @@ use serde_json::Value; use tokio::sync::Semaphore; use pathpatterns::{MatchEntry, MatchPattern, MatchType, Pattern}; -use proxmox::api::{ - api, schema::*, ApiHandler, ApiMethod, ApiResponseFuture, Permission, Router, RpcEnvironment, - SubdirMap, +use proxmox::{identity, sortable}; +use proxmox_router::{ + list_subdirs_api_method, + ApiHandler, ApiMethod, ApiResponseFuture, Permission, Router, RpcEnvironment, SubdirMap, }; -use proxmox::{identity, list_subdirs_api_method, sortable}; +use proxmox_schema::*; use pbs_api_types::file_restore::RestoreDaemonStatus; use pbs_client::pxar::{create_archive, Flags, PxarCreateOptions, ENCODER_MAX_ENTRIES}; diff --git a/proxmox-restore-daemon/src/proxmox_restore_daemon/auth.rs b/proxmox-restore-daemon/src/proxmox_restore_daemon/auth.rs index b57552e1..119149d0 100644 --- a/proxmox-restore-daemon/src/proxmox_restore_daemon/auth.rs +++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/auth.rs @@ -9,7 +9,7 @@ use hyper::{Body, Response, Method, StatusCode}; use http::request::Parts; use http::HeaderMap; -use proxmox::api::UserInformation; +use proxmox_router::UserInformation; use proxmox_rest_server::{ServerAdapter, AuthError, RestEnvironment}; diff --git a/proxmox-restore-daemon/src/proxmox_restore_daemon/disk.rs b/proxmox-restore-daemon/src/proxmox_restore_daemon/disk.rs index dea8fbf9..b1b247aa 100644 --- a/proxmox-restore-daemon/src/proxmox_restore_daemon/disk.rs +++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/disk.rs @@ -9,8 +9,8 @@ use anyhow::{bail, format_err, Error}; use lazy_static::lazy_static; use log::{info, warn}; -use proxmox::const_regex; use proxmox::tools::fs; +use proxmox_schema::const_regex; use pbs_api_types::BLOCKDEVICE_NAME_REGEX; use pbs_tools::run_command; diff --git a/proxmox-restore-daemon/src/proxmox_restore_daemon/watchdog.rs b/proxmox-restore-daemon/src/proxmox_restore_daemon/watchdog.rs index 294c7510..9d813b6c 100644 --- a/proxmox-restore-daemon/src/proxmox_restore_daemon/watchdog.rs +++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/watchdog.rs @@ -1,7 +1,7 @@ //! Tokio-based watchdog that shuts down the VM if not pinged for TIMEOUT use std::sync::atomic::{AtomicI64, Ordering}; -use proxmox::tools::time::epoch_i64; +use proxmox_time::epoch_i64; const TIMEOUT: i64 = 600; // seconds static TRIGGERED: AtomicI64 = AtomicI64::new(0); diff --git a/proxmox-rrd-api-types/Cargo.toml b/proxmox-rrd-api-types/Cargo.toml index 0eec1c49..816f7fde 100644 --- a/proxmox-rrd-api-types/Cargo.toml +++ b/proxmox-rrd-api-types/Cargo.toml @@ -7,5 +7,5 @@ description = "API type definitions for proxmox-rrd crate." [dependencies] -serde = { version = "1.0", features = [] } -proxmox = { version = "0.14.0", features = ["api-macro"] } +serde = { version = "1.0", features = ["derive"] } +proxmox-schema = { version = "1", features = ["api-macro"] } diff --git a/proxmox-rrd-api-types/src/lib.rs b/proxmox-rrd-api-types/src/lib.rs index 4a0165ff..b5e62e73 100644 --- a/proxmox-rrd-api-types/src/lib.rs +++ b/proxmox-rrd-api-types/src/lib.rs @@ -1,5 +1,6 @@ use serde::{Deserialize, Serialize}; -use proxmox::api::api; + +use proxmox_schema::api; #[api()] #[derive(Copy, Clone, Serialize, Deserialize)] diff --git a/proxmox-rrd/Cargo.toml b/proxmox-rrd/Cargo.toml index de9dcfe3..7225be8e 100644 --- a/proxmox-rrd/Cargo.toml +++ b/proxmox-rrd/Cargo.toml @@ -10,6 +10,7 @@ anyhow = "1.0" bitflags = "1.2.1" log = "0.4" -proxmox = { version = "0.14.0", features = ["api-macro"] } +proxmox = { version = "0.14.0" } +proxmox-time = "1" proxmox-rrd-api-types = { path = "../proxmox-rrd-api-types" } diff --git a/proxmox-rrd/src/cache.rs b/proxmox-rrd/src/cache.rs index 1084a037..fe28aeda 100644 --- a/proxmox-rrd/src/cache.rs +++ b/proxmox-rrd/src/cache.rs @@ -62,7 +62,7 @@ impl RRDCache { create_path(path.parent().unwrap(), Some(self.dir_options.clone()), Some(self.file_options.clone()))?; let mut map = self.cache.write().unwrap(); - let now = proxmox::tools::time::epoch_f64(); + let now = proxmox_time::epoch_f64(); if let Some(rrd) = map.get_mut(rel_path) { rrd.update(now, value); diff --git a/proxmox-systemd/Cargo.toml b/proxmox-systemd/Cargo.toml index 236b237f..415305ad 100644 --- a/proxmox-systemd/Cargo.toml +++ b/proxmox-systemd/Cargo.toml @@ -11,6 +11,8 @@ bitflags = "1.2.1" lazy_static = "1.4" nom = "5.1" -proxmox = { version = "0.14.0", default-features = false } +proxmox-time = "1" +proxmox-lang = "1" -#pbs-tools = { path = "../pbs-tools" } +[dev-dependencies] +proxmox = "0.14.0" diff --git a/proxmox-systemd/src/time.rs b/proxmox-systemd/src/time.rs index 7cf2e29f..b81e970e 100644 --- a/proxmox-systemd/src/time.rs +++ b/proxmox-systemd/src/time.rs @@ -3,7 +3,7 @@ use std::convert::TryInto; use anyhow::Error; use bitflags::bitflags; -use proxmox::tools::time::TmEditor; +use proxmox_time::TmEditor; pub use super::parse_time::*; @@ -368,7 +368,7 @@ mod test { use anyhow::bail; use super::*; - use proxmox::tools::time::*; + //use proxmox_time::*; fn test_event(v: &'static str) -> Result<(), Error> { match parse_calendar_event(v) { @@ -397,8 +397,12 @@ mod test { if next == expect { println!("next {:?} => {}", event, next); } else { - bail!("next {:?} failed\nnext: {:?}\nexpect: {:?}", - event, gmtime(next), gmtime(expect)); + bail!( + "next {:?} failed\nnext: {:?}\nexpect: {:?}", + event, + proxmox_time::gmtime(next), + proxmox_time::gmtime(expect), + ); } } Ok(None) => bail!("next {:?} failed to find a timestamp", event), diff --git a/proxmox-systemd/src/unit.rs b/proxmox-systemd/src/unit.rs index 15be61fd..b31f2c3f 100644 --- a/proxmox-systemd/src/unit.rs +++ b/proxmox-systemd/src/unit.rs @@ -7,7 +7,7 @@ fn run_command(mut command: Command) -> Result<(), Error> { .output() .map_err(|err| format_err!("failed to execute {:?} - {}", command, err))?; - proxmox::try_block!({ + proxmox_lang::try_block!({ if !output.status.success() { match output.status.code() { Some(code) => { diff --git a/pxar-bin/Cargo.toml b/pxar-bin/Cargo.toml index 6b77fd11..f1fca565 100644 --- a/pxar-bin/Cargo.toml +++ b/pxar-bin/Cargo.toml @@ -16,7 +16,9 @@ serde_json = "1.0" tokio = { version = "1.6", features = [ "rt", "rt-multi-thread" ] } pathpatterns = "0.1.2" -proxmox = { version = "0.14.0", default-features = false, features = [] } +proxmox = "0.14.0" +proxmox-schema = { version = "1", features = [ "api-macro" ] } +proxmox-router = "1" pxar = { version = "0.10.1", features = [ "tokio-io" ] } pbs-client = { path = "../pbs-client" } diff --git a/pxar-bin/src/main.rs b/pxar-bin/src/main.rs index abc949e2..3bc82008 100644 --- a/pxar-bin/src/main.rs +++ b/pxar-bin/src/main.rs @@ -14,8 +14,8 @@ use tokio::signal::unix::{signal, SignalKind}; use pathpatterns::{MatchEntry, MatchType, PatternFlag}; use pbs_client::pxar::{fuse, format_single_line_entry, ENCODER_MAX_ENTRIES, Flags, PxarExtractOptions}; -use proxmox::api::cli::*; -use proxmox::api::api; +use proxmox_schema::api; +use proxmox_router::cli::*; fn extract_archive_from_reader( reader: &mut R, diff --git a/src/api2/access/acl.rs b/src/api2/access/acl.rs index 764bd46f..8562b735 100644 --- a/src/api2/access/acl.rs +++ b/src/api2/access/acl.rs @@ -2,7 +2,8 @@ use anyhow::{bail, Error}; -use proxmox::api::{api, Router, RpcEnvironment, Permission}; +use proxmox_router::{Router, RpcEnvironment, Permission}; +use proxmox_schema::api; use pbs_api_types::{ Authid, AclListItem, Role, diff --git a/src/api2/access/domain.rs b/src/api2/access/domain.rs index aeff387f..0d95a65d 100644 --- a/src/api2/access/domain.rs +++ b/src/api2/access/domain.rs @@ -5,7 +5,8 @@ use anyhow::{Error}; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; -use proxmox::api::{api, Permission, Router, RpcEnvironment}; +use proxmox_router::{Router, RpcEnvironment, Permission}; +use proxmox_schema::api; use pbs_api_types::{REALM_ID_SCHEMA, SINGLE_LINE_COMMENT_SCHEMA}; diff --git a/src/api2/access/mod.rs b/src/api2/access/mod.rs index 7e11edaa..71eb760e 100644 --- a/src/api2/access/mod.rs +++ b/src/api2/access/mod.rs @@ -6,10 +6,11 @@ use serde_json::{json, Value}; use std::collections::HashMap; use std::collections::HashSet; -use proxmox::api::router::{Router, SubdirMap}; -use proxmox::api::{api, Permission, RpcEnvironment}; -use proxmox::{http_err, list_subdirs_api_method}; use proxmox::{identity, sortable}; +use proxmox_router::{ + http_err, list_subdirs_api_method, Router, RpcEnvironment, SubdirMap, Permission, +}; +use proxmox_schema::api; use pbs_api_types::{ Userid, Authid, PASSWORD_SCHEMA, ACL_PATH_SCHEMA, diff --git a/src/api2/access/openid.rs b/src/api2/access/openid.rs index 4da1ff04..5d7fe1ae 100644 --- a/src/api2/access/openid.rs +++ b/src/api2/access/openid.rs @@ -5,9 +5,11 @@ use anyhow::{bail, format_err, Error}; use serde_json::{json, Value}; -use proxmox::api::router::{Router, SubdirMap}; -use proxmox::api::{api, Permission, RpcEnvironment}; -use proxmox::{http_err, list_subdirs_api_method, identity, sortable}; +use proxmox::{identity, sortable}; +use proxmox_router::{ + http_err, list_subdirs_api_method, Router, RpcEnvironment, SubdirMap, Permission, +}; +use proxmox_schema::api; use proxmox_openid::{OpenIdAuthenticator, OpenIdConfig}; @@ -88,7 +90,7 @@ pub fn openid_login( let mut tested_username = None; - let result = proxmox::try_block!({ + let result = proxmox_lang::try_block!({ let (realm, private_auth_state) = OpenIdAuthenticator::verify_public_auth_state(PROXMOX_BACKUP_RUN_DIR_M!(), &state)?; diff --git a/src/api2/access/role.rs b/src/api2/access/role.rs index af48734e..7239b060 100644 --- a/src/api2/access/role.rs +++ b/src/api2/access/role.rs @@ -4,8 +4,8 @@ use anyhow::Error; use serde_json::{json, Value}; -use proxmox::api::{api, Permission}; -use proxmox::api::router::Router; +use proxmox_router::{Permission, Router}; +use proxmox_schema::api; use pbs_api_types::{Role, SINGLE_LINE_COMMENT_SCHEMA, PRIVILEGES}; use pbs_config::acl::ROLE_NAMES; diff --git a/src/api2/access/tfa.rs b/src/api2/access/tfa.rs index 0426fcd4..096226e8 100644 --- a/src/api2/access/tfa.rs +++ b/src/api2/access/tfa.rs @@ -3,9 +3,9 @@ use anyhow::{bail, format_err, Error}; use serde::{Deserialize, Serialize}; -use proxmox::api::{api, Permission, Router, RpcEnvironment}; -use proxmox::tools::tfa::totp::Totp; -use proxmox::{http_bail, http_err}; +use proxmox_router::{http_bail, http_err, Router, RpcEnvironment, Permission}; +use proxmox_schema::api; +use proxmox_tfa::totp::Totp; use pbs_api_types::{Authid, Userid, User, PASSWORD_SCHEMA, PRIV_PERMISSIONS_MODIFY, PRIV_SYS_AUDIT}; diff --git a/src/api2/access/user.rs b/src/api2/access/user.rs index 1d866214..7901ab96 100644 --- a/src/api2/access/user.rs +++ b/src/api2/access/user.rs @@ -5,8 +5,8 @@ use serde::{Serialize, Deserialize}; use serde_json::{json, Value}; use std::collections::HashMap; -use proxmox::api::{api, ApiMethod, Router, RpcEnvironment, Permission}; -use proxmox::api::router::SubdirMap; +use proxmox_router::{ApiMethod, Router, RpcEnvironment, SubdirMap, Permission}; +use proxmox_schema::api; use pbs_api_types::{ PROXMOX_CONFIG_DIGEST_SCHEMA, SINGLE_LINE_COMMENT_SCHEMA, Authid, @@ -498,7 +498,7 @@ pub fn generate_token( bail!("token '{}' for user '{}' already exists.", token_name.as_str(), userid); } - let secret = format!("{:x}", proxmox::tools::uuid::Uuid::generate()); + let secret = format!("{:x}", proxmox_uuid::Uuid::generate()); token_shadow::set_secret(&tokenid, &secret)?; let token = ApiToken { diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index 7e9a0ee0..7e98b4a9 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -12,16 +12,15 @@ use hyper::{header, Body, Response, StatusCode}; use serde_json::{json, Value}; use tokio_stream::wrappers::ReceiverStream; -use proxmox::api::{ - api, ApiResponseFuture, ApiHandler, ApiMethod, Router, - RpcEnvironment, RpcEnvironmentType, Permission -}; -use proxmox::api::router::SubdirMap; -use proxmox::api::schema::*; +use proxmox::{identity, sortable}; use proxmox::tools::fs::{ file_read_firstline, file_read_optional_string, replace_file, CreateOptions, }; -use proxmox::{http_err, identity, list_subdirs_api_method, sortable}; +use proxmox_router::{ + list_subdirs_api_method, http_err, ApiResponseFuture, ApiHandler, ApiMethod, Router, + RpcEnvironment, RpcEnvironmentType, SubdirMap, Permission, +}; +use proxmox_schema::*; use pxar::accessor::aio::Accessor; use pxar::EntryKind; diff --git a/src/api2/admin/mod.rs b/src/api2/admin/mod.rs index 365d5a61..b5214c21 100644 --- a/src/api2/admin/mod.rs +++ b/src/api2/admin/mod.rs @@ -1,7 +1,7 @@ //! Backup Server Administration -use proxmox::api::router::{Router, SubdirMap}; -use proxmox::list_subdirs_api_method; +use proxmox_router::{Router, SubdirMap}; +use proxmox_router::list_subdirs_api_method; pub mod datastore; pub mod sync; diff --git a/src/api2/admin/sync.rs b/src/api2/admin/sync.rs index 94990adb..12a358d1 100644 --- a/src/api2/admin/sync.rs +++ b/src/api2/admin/sync.rs @@ -3,9 +3,12 @@ use anyhow::{bail, format_err, Error}; use serde_json::Value; -use proxmox::api::{api, ApiMethod, Permission, Router, RpcEnvironment, RpcEnvironmentType}; -use proxmox::api::router::SubdirMap; -use proxmox::{list_subdirs_api_method, sortable}; +use proxmox::sortable; +use proxmox_router::{ + list_subdirs_api_method, ApiMethod, Router, RpcEnvironment, RpcEnvironmentType, SubdirMap, + Permission, +}; +use proxmox_schema::api; use pbs_api_types::{DATASTORE_SCHEMA, JOB_ID_SCHEMA, Authid, SyncJobConfig, SyncJobStatus}; use pbs_config::sync; diff --git a/src/api2/admin/verify.rs b/src/api2/admin/verify.rs index 6bdfdede..2a217b65 100644 --- a/src/api2/admin/verify.rs +++ b/src/api2/admin/verify.rs @@ -3,9 +3,12 @@ use anyhow::{format_err, Error}; use serde_json::Value; -use proxmox::api::router::SubdirMap; -use proxmox::{list_subdirs_api_method, sortable}; -use proxmox::api::{api, ApiMethod, Permission, Router, RpcEnvironment, RpcEnvironmentType}; +use proxmox::sortable; +use proxmox_router::{ + list_subdirs_api_method, ApiMethod, Router, RpcEnvironment, RpcEnvironmentType, SubdirMap, + Permission, +}; +use proxmox_schema::api; use pbs_api_types::{ VerificationJobConfig, VerificationJobStatus, JOB_ID_SCHEMA, Authid, diff --git a/src/api2/backup/environment.rs b/src/api2/backup/environment.rs index a2e34b3e..5906cb57 100644 --- a/src/api2/backup/environment.rs +++ b/src/api2/backup/environment.rs @@ -8,7 +8,7 @@ use serde_json::{json, Value}; use proxmox::tools::digest_to_hex; use proxmox::tools::fs::{replace_file, CreateOptions}; -use proxmox::api::{RpcEnvironment, RpcEnvironmentType}; +use proxmox_router::{RpcEnvironment, RpcEnvironmentType}; use pbs_datastore::{DataStore, DataBlob}; use pbs_datastore::backup_info::{BackupDir, BackupInfo}; diff --git a/src/api2/backup/mod.rs b/src/api2/backup/mod.rs index 4432c8d5..eea62500 100644 --- a/src/api2/backup/mod.rs +++ b/src/api2/backup/mod.rs @@ -7,10 +7,12 @@ use hyper::http::request::Parts; use hyper::{Body, Response, Request, StatusCode}; use serde_json::{json, Value}; -use proxmox::{sortable, identity, list_subdirs_api_method}; -use proxmox::api::{ApiResponseFuture, ApiHandler, ApiMethod, Router, RpcEnvironment, Permission}; -use proxmox::api::router::SubdirMap; -use proxmox::api::schema::*; +use proxmox::{sortable, identity}; +use proxmox_router::list_subdirs_api_method; +use proxmox_router::{ + ApiResponseFuture, ApiHandler, ApiMethod, Router, RpcEnvironment, SubdirMap, Permission, +}; +use proxmox_schema::*; use pbs_api_types::{ Authid, VerifyState, SnapshotVerifyState, diff --git a/src/api2/backup/upload_chunk.rs b/src/api2/backup/upload_chunk.rs index abf20888..75cb44e1 100644 --- a/src/api2/backup/upload_chunk.rs +++ b/src/api2/backup/upload_chunk.rs @@ -9,8 +9,8 @@ use hyper::http::request::Parts; use serde_json::{json, Value}; use proxmox::{sortable, identity}; -use proxmox::api::{ApiResponseFuture, ApiHandler, ApiMethod, RpcEnvironment}; -use proxmox::api::schema::*; +use proxmox_router::{ApiResponseFuture, ApiHandler, ApiMethod, RpcEnvironment}; +use proxmox_schema::*; use pbs_datastore::{DataStore, DataBlob}; use pbs_datastore::file_formats::{DataBlobHeader, EncryptedDataBlobHeader}; @@ -59,7 +59,7 @@ impl Future for UploadChunk { break format_err!("uploaded chunk has unexpected size."); } - let (is_duplicate, compressed_size) = match proxmox::try_block! { + let (is_duplicate, compressed_size) = match proxmox_lang::try_block! { let mut chunk = DataBlob::from_raw(raw_data)?; pbs_runtime::block_in_place(|| { diff --git a/src/api2/config/access/mod.rs b/src/api2/config/access/mod.rs index 6e7d98be..6b9a12b5 100644 --- a/src/api2/config/access/mod.rs +++ b/src/api2/config/access/mod.rs @@ -1,5 +1,5 @@ -use proxmox::api::{Router, SubdirMap}; -use proxmox::list_subdirs_api_method; +use proxmox_router::{Router, SubdirMap}; +use proxmox_router::list_subdirs_api_method; use proxmox::{identity, sortable}; pub mod tfa; diff --git a/src/api2/config/access/openid.rs b/src/api2/config/access/openid.rs index 3dfa8de4..027d5b91 100644 --- a/src/api2/config/access/openid.rs +++ b/src/api2/config/access/openid.rs @@ -4,7 +4,8 @@ use anyhow::{bail, Error}; use serde_json::Value; use ::serde::{Deserialize, Serialize}; -use proxmox::api::{api, Permission, Router, RpcEnvironment}; +use proxmox_router::{Router, RpcEnvironment, Permission}; +use proxmox_schema::api; use pbs_api_types::{ PROXMOX_CONFIG_DIGEST_SCHEMA, REALM_ID_SCHEMA, PRIV_SYS_AUDIT, PRIV_REALM_ALLOCATE, diff --git a/src/api2/config/access/tfa.rs b/src/api2/config/access/tfa.rs index a7234638..ec15446e 100644 --- a/src/api2/config/access/tfa.rs +++ b/src/api2/config/access/tfa.rs @@ -3,8 +3,9 @@ use anyhow::Error; -use proxmox::api::{api, Permission, Router, RpcEnvironment, SubdirMap}; -use proxmox::list_subdirs_api_method; +use proxmox_router::{Router, RpcEnvironment, Permission, SubdirMap}; +use proxmox_schema::api; +use proxmox_router::list_subdirs_api_method; use pbs_api_types::PROXMOX_CONFIG_DIGEST_SCHEMA; diff --git a/src/api2/config/acme.rs b/src/api2/config/acme.rs index e8fa0798..efa0b57b 100644 --- a/src/api2/config/acme.rs +++ b/src/api2/config/acme.rs @@ -8,10 +8,10 @@ use lazy_static::lazy_static; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; -use proxmox::api::router::SubdirMap; -use proxmox::api::{api, Permission, Router, RpcEnvironment}; -use proxmox::http_bail; -use proxmox::list_subdirs_api_method; +use proxmox_router::{ + http_bail, list_subdirs_api_method, Permission, Router, SubdirMap, RpcEnvironment, +}; +use proxmox_schema::api; use proxmox_acme_rs::account::AccountData as AcmeAccountData; use proxmox_acme_rs::Account; diff --git a/src/api2/config/changer.rs b/src/api2/config/changer.rs index a9f7622f..b9526ed3 100644 --- a/src/api2/config/changer.rs +++ b/src/api2/config/changer.rs @@ -2,13 +2,8 @@ use anyhow::{bail, Error}; use ::serde::{Deserialize, Serialize}; use serde_json::Value; -use proxmox::api::{ - api, - Router, - RpcEnvironment, - Permission, - schema::parse_property_string, -}; +use proxmox_router::{Router, RpcEnvironment, Permission}; +use proxmox_schema::{api, parse_property_string}; use pbs_api_types::{ Authid, ScsiTapeChanger, ScsiTapeChangerUpdater, LtoTapeDrive, diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index 0819d5ec..b9367469 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -4,9 +4,9 @@ use anyhow::{bail, Error}; use serde_json::Value; use ::serde::{Deserialize, Serialize}; -use proxmox::api::{api, Router, RpcEnvironment, RpcEnvironmentType, Permission}; -use proxmox::api::section_config::SectionConfigData; -use proxmox::api::schema::{ApiType, parse_property_string}; +use proxmox_router::{Router, RpcEnvironment, RpcEnvironmentType, Permission}; +use proxmox_schema::{api, ApiType, parse_property_string}; +use proxmox_section_config::SectionConfigData; use pbs_datastore::chunk_store::ChunkStore; use pbs_config::BackupLockGuard; diff --git a/src/api2/config/drive.rs b/src/api2/config/drive.rs index 26b4ddd5..2840fe8f 100644 --- a/src/api2/config/drive.rs +++ b/src/api2/config/drive.rs @@ -2,7 +2,8 @@ use anyhow::{bail, Error}; use ::serde::{Deserialize, Serialize}; use serde_json::Value; -use proxmox::api::{api, Router, RpcEnvironment, Permission}; +use proxmox_router::{Router, RpcEnvironment, Permission}; +use proxmox_schema::api; use pbs_api_types::{ Authid, LtoTapeDrive, LtoTapeDriveUpdater, ScsiTapeChanger, diff --git a/src/api2/config/media_pool.rs b/src/api2/config/media_pool.rs index 6782e56c..6f72ac42 100644 --- a/src/api2/config/media_pool.rs +++ b/src/api2/config/media_pool.rs @@ -1,14 +1,8 @@ use anyhow::{bail, Error}; use ::serde::{Deserialize, Serialize}; -use proxmox::{ - api::{ - api, - Router, - RpcEnvironment, - Permission, - }, -}; +use proxmox_router::{Router, RpcEnvironment, Permission}; +use proxmox_schema::api; use pbs_api_types::{ Authid, MediaPoolConfig, MediaPoolConfigUpdater, MEDIA_POOL_NAME_SCHEMA, diff --git a/src/api2/config/mod.rs b/src/api2/config/mod.rs index 9befa0e5..473337f5 100644 --- a/src/api2/config/mod.rs +++ b/src/api2/config/mod.rs @@ -1,7 +1,7 @@ //! Backup Server Configuration -use proxmox::api::router::{Router, SubdirMap}; -use proxmox::list_subdirs_api_method; +use proxmox_router::{Router, SubdirMap}; +use proxmox_router::list_subdirs_api_method; pub mod access; pub mod acme; diff --git a/src/api2/config/remote.rs b/src/api2/config/remote.rs index acf7cfcf..29e638d7 100644 --- a/src/api2/config/remote.rs +++ b/src/api2/config/remote.rs @@ -2,8 +2,8 @@ use anyhow::{bail, format_err, Error}; use serde_json::Value; use ::serde::{Deserialize, Serialize}; -use proxmox::api::{api, ApiMethod, Router, RpcEnvironment, Permission}; -use proxmox::http_err; +use proxmox_router::{http_err, ApiMethod, Router, RpcEnvironment, Permission}; +use proxmox_schema::api; use pbs_client::{HttpClient, HttpClientOptions}; use pbs_api_types::{ diff --git a/src/api2/config/sync.rs b/src/api2/config/sync.rs index 3c2bfd78..fba476da 100644 --- a/src/api2/config/sync.rs +++ b/src/api2/config/sync.rs @@ -2,7 +2,8 @@ use anyhow::{bail, Error}; use serde_json::Value; use ::serde::{Deserialize, Serialize}; -use proxmox::api::{api, Permission, Router, RpcEnvironment}; +use proxmox_router::{Router, RpcEnvironment, Permission}; +use proxmox_schema::api; use pbs_api_types::{ Authid, SyncJobConfig, SyncJobConfigUpdater, JOB_ID_SCHEMA, PROXMOX_CONFIG_DIGEST_SCHEMA, diff --git a/src/api2/config/tape_backup_job.rs b/src/api2/config/tape_backup_job.rs index 92135804..6c5680d3 100644 --- a/src/api2/config/tape_backup_job.rs +++ b/src/api2/config/tape_backup_job.rs @@ -2,7 +2,8 @@ use anyhow::{bail, Error}; use serde_json::Value; use ::serde::{Deserialize, Serialize}; -use proxmox::api::{api, Router, RpcEnvironment, Permission}; +use proxmox_router::{Router, RpcEnvironment, Permission}; +use proxmox_schema::api; use pbs_api_types::{ Authid, TapeBackupJobConfig, TapeBackupJobConfigUpdater, diff --git a/src/api2/config/tape_encryption_keys.rs b/src/api2/config/tape_encryption_keys.rs index ba66b6f6..03c39c58 100644 --- a/src/api2/config/tape_encryption_keys.rs +++ b/src/api2/config/tape_encryption_keys.rs @@ -1,15 +1,8 @@ use anyhow::{bail, Error}; use serde_json::Value; -use proxmox::{ - api::{ - api, - ApiMethod, - Router, - RpcEnvironment, - Permission, - }, -}; +use proxmox_router::{ApiMethod, Router, RpcEnvironment, Permission}; +use proxmox_schema::api; use pbs_api_types::{ Fingerprint, KeyInfo, Kdf, diff --git a/src/api2/config/verify.rs b/src/api2/config/verify.rs index 7958646a..d1a28322 100644 --- a/src/api2/config/verify.rs +++ b/src/api2/config/verify.rs @@ -2,7 +2,8 @@ use anyhow::{bail, Error}; use serde_json::Value; use ::serde::{Deserialize, Serialize}; -use proxmox::api::{api, Permission, Router, RpcEnvironment}; +use proxmox_router::{Router, RpcEnvironment, Permission}; +use proxmox_schema::api; use pbs_api_types::{ Authid, VerificationJobConfig, VerificationJobConfigUpdater, JOB_ID_SCHEMA, diff --git a/src/api2/helpers.rs b/src/api2/helpers.rs index 2a822654..750e4fac 100644 --- a/src/api2/helpers.rs +++ b/src/api2/helpers.rs @@ -4,7 +4,7 @@ use anyhow::Error; use futures::stream::TryStreamExt; use hyper::{Body, Response, StatusCode, header}; -use proxmox::http_bail; +use proxmox_router::http_bail; pub async fn create_download_response(path: PathBuf) -> Result, Error> { let file = match tokio::fs::File::open(path.clone()).await { diff --git a/src/api2/mod.rs b/src/api2/mod.rs index 0ede4165..dd517df4 100644 --- a/src/api2/mod.rs +++ b/src/api2/mod.rs @@ -14,9 +14,7 @@ pub mod pull; pub mod tape; pub mod helpers; -use proxmox::api::router::SubdirMap; -use proxmox::api::Router; -use proxmox::list_subdirs_api_method; +use proxmox_router::{list_subdirs_api_method, Router, SubdirMap}; const SUBDIRS: SubdirMap = &[ ("access", &access::ROUTER), diff --git a/src/api2/node/apt.rs b/src/api2/node/apt.rs index efc9538b..46d015b9 100644 --- a/src/api2/node/apt.rs +++ b/src/api2/node/apt.rs @@ -2,10 +2,11 @@ use anyhow::{Error, bail, format_err}; use serde_json::{json, Value}; use std::collections::HashMap; -use proxmox::list_subdirs_api_method; -use proxmox::api::{api, RpcEnvironment, RpcEnvironmentType, Permission}; -use proxmox::api::router::{Router, SubdirMap}; use proxmox::tools::fs::{replace_file, CreateOptions}; +use proxmox_router::{ + list_subdirs_api_method, RpcEnvironment, RpcEnvironmentType, Permission, Router, SubdirMap +}; +use proxmox_schema::api; use proxmox_apt::repositories::{ APTRepositoryFile, APTRepositoryFileError, APTRepositoryHandle, APTRepositoryInfo, diff --git a/src/api2/node/certificates.rs b/src/api2/node/certificates.rs index 80419a4f..4d26b29f 100644 --- a/src/api2/node/certificates.rs +++ b/src/api2/node/certificates.rs @@ -7,9 +7,10 @@ use openssl::pkey::PKey; use openssl::x509::X509; use serde::{Deserialize, Serialize}; -use proxmox::api::router::SubdirMap; -use proxmox::api::{api, Permission, Router, RpcEnvironment}; -use proxmox::list_subdirs_api_method; +use proxmox_router::SubdirMap; +use proxmox_router::{Permission, Router, RpcEnvironment}; +use proxmox_router::list_subdirs_api_method; +use proxmox_schema::api; use pbs_api_types::{NODE_SCHEMA, PRIV_SYS_MODIFY}; use pbs_buildcfg::configdir; @@ -516,7 +517,7 @@ pub fn renew_acme_cert(force: bool, rpcenv: &mut dyn RpcEnvironment) -> Result Result { let cert = pem_to_cert_info(get_certificate_pem()?.as_bytes())?; - cert.is_expired_after_epoch(proxmox::tools::time::epoch_i64() + 30 * 24 * 60 * 60) + cert.is_expired_after_epoch(proxmox_time::epoch_i64() + 30 * 24 * 60 * 60) .map_err(|err| format_err!("Failed to check certificate expiration date: {}", err)) } diff --git a/src/api2/node/config.rs b/src/api2/node/config.rs index 88ec3955..fe99bad9 100644 --- a/src/api2/node/config.rs +++ b/src/api2/node/config.rs @@ -1,7 +1,8 @@ use anyhow::Error; use ::serde::{Deserialize, Serialize}; -use proxmox::api::{api, Permission, Router, RpcEnvironment}; +use proxmox_router::{Permission, Router, RpcEnvironment}; +use proxmox_schema::api; use pbs_api_types::{NODE_SCHEMA, PRIV_SYS_AUDIT, PRIV_SYS_MODIFY}; diff --git a/src/api2/node/disks/directory.rs b/src/api2/node/disks/directory.rs index 7f1ae1a2..e36d4d82 100644 --- a/src/api2/node/disks/directory.rs +++ b/src/api2/node/disks/directory.rs @@ -2,9 +2,9 @@ use anyhow::{bail, Error}; use serde_json::json; use ::serde::{Deserialize, Serialize}; -use proxmox::api::{api, Permission, RpcEnvironment, RpcEnvironmentType}; -use proxmox::api::section_config::SectionConfigData; -use proxmox::api::router::Router; +use proxmox_router::{Router, RpcEnvironment, RpcEnvironmentType, Permission}; +use proxmox_schema::api; +use proxmox_section_config::SectionConfigData; use pbs_api_types::{ DataStoreConfig, NODE_SCHEMA, BLOCKDEVICE_NAME_SCHEMA, diff --git a/src/api2/node/disks/mod.rs b/src/api2/node/disks/mod.rs index c66b83cd..27bb455c 100644 --- a/src/api2/node/disks/mod.rs +++ b/src/api2/node/disks/mod.rs @@ -1,10 +1,11 @@ use anyhow::{bail, Error}; use serde_json::{json, Value}; -use proxmox::api::{api, Permission, RpcEnvironment, RpcEnvironmentType}; -use proxmox::api::router::{Router, SubdirMap}; use proxmox::{sortable, identity}; -use proxmox::{list_subdirs_api_method}; +use proxmox_router::{ + list_subdirs_api_method, Router, RpcEnvironment, RpcEnvironmentType, SubdirMap, Permission, +}; +use proxmox_schema::api; use pbs_api_types::{ UPID_SCHEMA, NODE_SCHEMA, BLOCKDEVICE_NAME_SCHEMA, diff --git a/src/api2/node/disks/zfs.rs b/src/api2/node/disks/zfs.rs index 190a761d..9c3a0958 100644 --- a/src/api2/node/disks/zfs.rs +++ b/src/api2/node/disks/zfs.rs @@ -1,11 +1,8 @@ use anyhow::{bail, Error}; use serde_json::{json, Value}; -use proxmox::api::{ - api, Permission, RpcEnvironment, RpcEnvironmentType, - schema::parse_property_string, -}; -use proxmox::api::router::Router; +use proxmox_router::{Router, RpcEnvironment, RpcEnvironmentType, Permission}; +use proxmox_schema::{api, parse_property_string}; use pbs_api_types::{ ZpoolListItem, ZfsRaidLevel, ZfsCompressionType, DataStoreConfig, diff --git a/src/api2/node/dns.rs b/src/api2/node/dns.rs index ff5b5f14..34a42a65 100644 --- a/src/api2/node/dns.rs +++ b/src/api2/node/dns.rs @@ -7,7 +7,8 @@ use regex::Regex; use serde_json::{json, Value}; use ::serde::{Deserialize, Serialize}; -use proxmox::api::{api, ApiMethod, Router, RpcEnvironment, Permission}; +use proxmox_router::{ApiMethod, Router, RpcEnvironment, Permission}; +use proxmox_schema::api; use proxmox::tools::fs::{file_get_contents, replace_file, CreateOptions}; use proxmox::{IPRE, IPV4RE, IPV6RE, IPV4OCTET, IPV6H16, IPV6LS32}; diff --git a/src/api2/node/journal.rs b/src/api2/node/journal.rs index aa708a82..8a4a832c 100644 --- a/src/api2/node/journal.rs +++ b/src/api2/node/journal.rs @@ -4,7 +4,8 @@ use anyhow::{Error}; use serde_json::{json, Value}; use std::io::{BufRead,BufReader}; -use proxmox::api::{api, ApiMethod, Router, RpcEnvironment, Permission}; +use proxmox_router::{ApiMethod, Router, RpcEnvironment, Permission}; +use proxmox_schema::api; use pbs_api_types::{NODE_SCHEMA, PRIV_SYS_AUDIT}; diff --git a/src/api2/node/mod.rs b/src/api2/node/mod.rs index b101040b..5e7a09e2 100644 --- a/src/api2/node/mod.rs +++ b/src/api2/node/mod.rs @@ -12,12 +12,12 @@ use hyper::Request; use serde_json::{json, Value}; use tokio::io::{AsyncBufReadExt, BufReader}; -use proxmox::api::router::{Router, SubdirMap}; -use proxmox::api::{ - api, schema::*, ApiHandler, ApiMethod, ApiResponseFuture, Permission, RpcEnvironment, -}; -use proxmox::list_subdirs_api_method; use proxmox::{identity, sortable}; +use proxmox_router::{ + ApiHandler, ApiMethod, ApiResponseFuture, Permission, RpcEnvironment, Router, SubdirMap, +}; +use proxmox_schema::*; +use proxmox_router::list_subdirs_api_method; use proxmox_http::websocket::WebSocket; use proxmox_rest_server::WorkerTask; diff --git a/src/api2/node/network.rs b/src/api2/node/network.rs index d496b5f8..1becf107 100644 --- a/src/api2/node/network.rs +++ b/src/api2/node/network.rs @@ -2,8 +2,8 @@ use anyhow::{Error, bail}; use serde_json::{Value, to_value}; use ::serde::{Deserialize, Serialize}; -use proxmox::api::{api, ApiMethod, Router, RpcEnvironment, Permission}; -use proxmox::api::schema::parse_property_string; +use proxmox_router::{ApiMethod, Router, RpcEnvironment, Permission}; +use proxmox_schema::{api, parse_property_string}; use pbs_api_types::{ Authid, Interface, NetworkInterfaceType, LinuxBondMode, NetworkConfigMethod, BondXmitHashPolicy, diff --git a/src/api2/node/report.rs b/src/api2/node/report.rs index 54d87dc4..bfea0586 100644 --- a/src/api2/node/report.rs +++ b/src/api2/node/report.rs @@ -1,7 +1,9 @@ use anyhow::Error; -use proxmox::api::{api, ApiMethod, Permission, Router, RpcEnvironment}; use serde_json::{json, Value}; +use proxmox_router::{ApiMethod, Permission, Router, RpcEnvironment}; +use proxmox_schema::api; + use pbs_api_types::{NODE_SCHEMA, PRIV_SYS_AUDIT}; use crate::server::generate_report; diff --git a/src/api2/node/rrd.rs b/src/api2/node/rrd.rs index 00555030..c59a35a4 100644 --- a/src/api2/node/rrd.rs +++ b/src/api2/node/rrd.rs @@ -1,7 +1,8 @@ use anyhow::Error; use serde_json::{Value, json}; -use proxmox::api::{api, Permission, Router}; +use proxmox_router::{Permission, Router}; +use proxmox_schema::api; use pbs_api_types::{ NODE_SCHEMA, RRDMode, RRDTimeFrameResolution, PRIV_SYS_AUDIT, @@ -19,7 +20,7 @@ pub fn create_value_from_rrd( ) -> Result { let mut result = Vec::new(); - let now = proxmox::tools::time::epoch_f64(); + let now = proxmox_time::epoch_f64(); for name in list { let (start, reso, list) = match RRD_CACHE.extract_cached_data(basedir, name, now, timeframe, cf) { diff --git a/src/api2/node/services.rs b/src/api2/node/services.rs index 8df0fb24..19a1d8a1 100644 --- a/src/api2/node/services.rs +++ b/src/api2/node/services.rs @@ -3,9 +3,9 @@ use std::process::{Command, Stdio}; use anyhow::{bail, Error}; use serde_json::{json, Value}; -use proxmox::{sortable, identity, list_subdirs_api_method}; -use proxmox::api::{api, Router, Permission, RpcEnvironment}; -use proxmox::api::router::SubdirMap; +use proxmox::{sortable, identity}; +use proxmox_router::{list_subdirs_api_method, Router, Permission, RpcEnvironment, SubdirMap}; +use proxmox_schema::api; use pbs_api_types::{Authid, NODE_SCHEMA, SERVICE_ID_SCHEMA, PRIV_SYS_AUDIT, PRIV_SYS_MODIFY}; diff --git a/src/api2/node/status.rs b/src/api2/node/status.rs index f430c28c..f9b1ca72 100644 --- a/src/api2/node/status.rs +++ b/src/api2/node/status.rs @@ -6,7 +6,8 @@ use serde_json::Value; use proxmox::sys::linux::procfs; -use proxmox::api::{api, ApiMethod, Router, RpcEnvironment, Permission}; +use proxmox_router::{ApiMethod, Router, RpcEnvironment, Permission}; +use proxmox_schema::api; use pbs_api_types::{NODE_SCHEMA, NodePowerCommand, PRIV_SYS_AUDIT, PRIV_SYS_POWER_MANAGEMENT}; diff --git a/src/api2/node/subscription.rs b/src/api2/node/subscription.rs index 721ef40a..5fa38033 100644 --- a/src/api2/node/subscription.rs +++ b/src/api2/node/subscription.rs @@ -1,7 +1,8 @@ use anyhow::{Error, format_err, bail}; use serde_json::Value; -use proxmox::api::{api, Router, RpcEnvironment, Permission}; +use proxmox_router::{Router, RpcEnvironment, Permission}; +use proxmox_schema::api; use pbs_api_types::{ NODE_SCHEMA, SUBSCRIPTION_KEY_SCHEMA, Authid, @@ -51,7 +52,7 @@ pub fn check_subscription( }; if !force && info.status == SubscriptionStatus::ACTIVE { - let age = proxmox::tools::time::epoch_i64() - info.checktime.unwrap_or(i64::MAX); + let age = proxmox_time::epoch_i64() - info.checktime.unwrap_or(i64::MAX); if age < subscription::MAX_LOCAL_KEY_AGE { return Ok(()); } diff --git a/src/api2/node/syslog.rs b/src/api2/node/syslog.rs index 4c956f09..08dc5edb 100644 --- a/src/api2/node/syslog.rs +++ b/src/api2/node/syslog.rs @@ -3,7 +3,8 @@ use std::process::{Command, Stdio}; use anyhow::{Error}; use serde_json::{json, Value}; -use proxmox::api::{api, ApiMethod, Router, RpcEnvironment, Permission}; +use proxmox_router::{ApiMethod, Router, RpcEnvironment, Permission}; +use proxmox_schema::api; use pbs_api_types::{NODE_SCHEMA, SYSTEMD_DATETIME_FORMAT, PRIV_SYS_AUDIT}; diff --git a/src/api2/node/tasks.rs b/src/api2/node/tasks.rs index 0a7fa218..7689ef21 100644 --- a/src/api2/node/tasks.rs +++ b/src/api2/node/tasks.rs @@ -4,9 +4,9 @@ use std::io::{BufRead, BufReader}; use anyhow::{bail, Error}; use serde_json::{json, Value}; -use proxmox::api::{api, Router, RpcEnvironment, Permission}; -use proxmox::api::router::SubdirMap; -use proxmox::{identity, list_subdirs_api_method, sortable}; +use proxmox::{identity, sortable}; +use proxmox_router::{list_subdirs_api_method, Router, RpcEnvironment, Permission, SubdirMap}; +use proxmox_schema::api; use pbs_api_types::{ Userid, Authid, Tokenname, TaskListItem, TaskStateType, UPID, diff --git a/src/api2/node/time.rs b/src/api2/node/time.rs index bf82c25a..d17c7f72 100644 --- a/src/api2/node/time.rs +++ b/src/api2/node/time.rs @@ -1,8 +1,9 @@ use anyhow::{bail, format_err, Error}; use serde_json::{json, Value}; -use proxmox::api::{api, Router, Permission}; use proxmox::tools::fs::{file_read_firstline, replace_file, CreateOptions}; +use proxmox_router::{Router, Permission}; +use proxmox_schema::api; use pbs_api_types::{NODE_SCHEMA, TIME_ZONE_SCHEMA, PRIV_SYS_MODIFY}; @@ -55,8 +56,8 @@ fn read_etc_localtime() -> Result { )] /// Read server time and time zone settings. fn get_time(_param: Value) -> Result { - let time = proxmox::tools::time::epoch_i64(); - let tm = proxmox::tools::time::localtime(time)?; + let time = proxmox_time::epoch_i64(); + let tm = proxmox_time::localtime(time)?; let offset = tm.tm_gmtoff; let localtime = time + offset; diff --git a/src/api2/ping.rs b/src/api2/ping.rs index dfbe05c6..7e4d152d 100644 --- a/src/api2/ping.rs +++ b/src/api2/ping.rs @@ -3,7 +3,8 @@ use anyhow::{Error}; use serde_json::{json, Value}; -use proxmox::api::{api, Router, Permission}; +use proxmox_router::{Router, Permission}; +use proxmox_schema::api; #[api( returns: { diff --git a/src/api2/pull.rs b/src/api2/pull.rs index ea8faab8..4280d922 100644 --- a/src/api2/pull.rs +++ b/src/api2/pull.rs @@ -4,8 +4,8 @@ use std::sync::{Arc}; use anyhow::{format_err, Error}; use futures::{select, future::FutureExt}; -use proxmox::api::api; -use proxmox::api::{ApiMethod, Router, RpcEnvironment, Permission}; +use proxmox_schema::api; +use proxmox_router::{ApiMethod, Router, RpcEnvironment, Permission}; use pbs_client::{HttpClient, BackupRepository}; use pbs_api_types::{ diff --git a/src/api2/reader/environment.rs b/src/api2/reader/environment.rs index 379b3ce2..b4aaa614 100644 --- a/src/api2/reader/environment.rs +++ b/src/api2/reader/environment.rs @@ -3,7 +3,7 @@ use std::collections::HashSet; use serde_json::{json, Value}; -use proxmox::api::{RpcEnvironment, RpcEnvironmentType}; +use proxmox_router::{RpcEnvironment, RpcEnvironmentType}; use pbs_datastore::backup_info::BackupDir; use pbs_datastore::DataStore; diff --git a/src/api2/reader/mod.rs b/src/api2/reader/mod.rs index 1fd25a5c..f418f50f 100644 --- a/src/api2/reader/mod.rs +++ b/src/api2/reader/mod.rs @@ -7,25 +7,12 @@ use hyper::http::request::Parts; use hyper::{Body, Response, Request, StatusCode}; use serde_json::Value; -use proxmox::{ - http_err, - sortable, - identity, - list_subdirs_api_method, - api::{ - ApiResponseFuture, - ApiHandler, - ApiMethod, - Router, - RpcEnvironment, - Permission, - router::SubdirMap, - schema::{ - ObjectSchema, - BooleanSchema, - }, - }, +use proxmox::{identity, sortable}; +use proxmox_router::{ + http_err, list_subdirs_api_method, ApiHandler, ApiMethod, ApiResponseFuture, Permission, + Router, RpcEnvironment, SubdirMap, }; +use proxmox_schema::{BooleanSchema, ObjectSchema}; use pbs_api_types::{ Authid, DATASTORE_SCHEMA, BACKUP_TYPE_SCHEMA, BACKUP_TIME_SCHEMA, BACKUP_ID_SCHEMA, diff --git a/src/api2/status.rs b/src/api2/status.rs index 548e5319..9c7d4f7d 100644 --- a/src/api2/status.rs +++ b/src/api2/status.rs @@ -1,18 +1,17 @@ //! Datastote status -use proxmox::list_subdirs_api_method; - use anyhow::{Error}; use serde_json::{json, Value}; -use proxmox::api::{ - api, +use proxmox_schema::api; +use proxmox_router::{ ApiMethod, Permission, Router, RpcEnvironment, SubdirMap, }; +use proxmox_router::list_subdirs_api_method; use pbs_api_types::{ Authid, DATASTORE_SCHEMA, RRDMode, RRDTimeFrameResolution, @@ -122,7 +121,7 @@ pub fn datastore_status( }); let rrd_dir = format!("datastore/{}", store); - let now = proxmox::tools::time::epoch_f64(); + let now = proxmox_time::epoch_f64(); let get_rrd = |what: &str| RRD_CACHE.extract_cached_data( &rrd_dir, diff --git a/src/api2/tape/backup.rs b/src/api2/tape/backup.rs index 7627e35b..a0578391 100644 --- a/src/api2/tape/backup.rs +++ b/src/api2/tape/backup.rs @@ -4,16 +4,9 @@ use std::sync::{Mutex, Arc}; use anyhow::{bail, format_err, Error}; use serde_json::Value; -use proxmox::{ - try_block, - api::{ - api, - RpcEnvironment, - RpcEnvironmentType, - Router, - Permission, - }, -}; +use proxmox_lang::try_block; +use proxmox_router::{Permission, Router, RpcEnvironment, RpcEnvironmentType}; +use proxmox_schema::api; use pbs_api_types::{ Authid, Userid, TapeBackupJobConfig, TapeBackupJobSetup, TapeBackupJobStatus, MediaPoolConfig, @@ -119,7 +112,7 @@ pub fn list_tape_backup_jobs( let mut list = Vec::new(); let status_path = Path::new(TAPE_STATUS_DIR); - let current_time = proxmox::tools::time::epoch_i64(); + let current_time = proxmox_time::epoch_i64(); for job in job_list_iter { let privs = user_info.lookup_privs(&auth_id, &["tape", "job", &job.id]); diff --git a/src/api2/tape/changer.rs b/src/api2/tape/changer.rs index 3d9dcb70..6a99ca37 100644 --- a/src/api2/tape/changer.rs +++ b/src/api2/tape/changer.rs @@ -4,8 +4,8 @@ use std::path::Path; use anyhow::Error; use serde_json::Value; -use proxmox::api::{api, Router, SubdirMap, RpcEnvironment, Permission}; -use proxmox::list_subdirs_api_method; +use proxmox_schema::api; +use proxmox_router::{list_subdirs_api_method, Permission, Router, RpcEnvironment, SubdirMap}; use pbs_api_types::{ Authid, ChangerListEntry, LtoTapeDrive, MtxEntryKind, MtxStatusEntry, ScsiTapeChanger, diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs index 6564d0fe..f3bd8c63 100644 --- a/src/api2/tape/drive.rs +++ b/src/api2/tape/drive.rs @@ -6,21 +6,13 @@ use std::collections::HashMap; use anyhow::{bail, format_err, Error}; use serde_json::Value; -use proxmox::{ - sortable, - identity, - list_subdirs_api_method, - tools::Uuid, - api::{ - api, - section_config::SectionConfigData, - RpcEnvironment, - RpcEnvironmentType, - Permission, - Router, - SubdirMap, - }, +use proxmox::{sortable, identity}; +use proxmox_router::{ + list_subdirs_api_method, Permission, Router, RpcEnvironment, RpcEnvironmentType, SubdirMap, }; +use proxmox_schema::api; +use proxmox_section_config::SectionConfigData; +use proxmox_uuid::Uuid; use pbs_api_types::{ UPID_SCHEMA, CHANGER_NAME_SCHEMA, DRIVE_NAME_SCHEMA, MEDIA_LABEL_SCHEMA, MEDIA_POOL_NAME_SCHEMA, @@ -521,7 +513,7 @@ pub fn label_media( } } - let ctime = proxmox::tools::time::epoch_i64(); + let ctime = proxmox_time::epoch_i64(); let label = MediaLabel { label_text: label_text.to_string(), uuid: Uuid::generate(), @@ -1084,7 +1076,7 @@ fn barcode_label_media_worker( } } - let ctime = proxmox::tools::time::epoch_i64(); + let ctime = proxmox_time::epoch_i64(); let label = MediaLabel { label_text: label_text.to_string(), uuid: Uuid::generate(), diff --git a/src/api2/tape/media.rs b/src/api2/tape/media.rs index 72948f52..ed99374d 100644 --- a/src/api2/tape/media.rs +++ b/src/api2/tape/media.rs @@ -3,11 +3,9 @@ use std::collections::HashSet; use anyhow::{bail, format_err, Error}; -use proxmox::{ - api::{api, Router, SubdirMap, RpcEnvironment, Permission}, - list_subdirs_api_method, - tools::Uuid, -}; +use proxmox_router::{list_subdirs_api_method, Router, SubdirMap, RpcEnvironment, Permission}; +use proxmox_schema::api; +use proxmox_uuid::Uuid; use pbs_datastore::backup_info::BackupDir; use pbs_api_types::{ @@ -177,7 +175,7 @@ pub async fn list_media( let changer_name = None; // assume standalone drive let mut pool = MediaPool::with_config(status_path, &config, changer_name, true)?; - let current_time = proxmox::tools::time::epoch_i64(); + let current_time = proxmox_time::epoch_i64(); // Call start_write_session, so that we show the same status a // backup job would see. diff --git a/src/api2/tape/mod.rs b/src/api2/tape/mod.rs index 049bb936..9b569fd5 100644 --- a/src/api2/tape/mod.rs +++ b/src/api2/tape/mod.rs @@ -3,14 +3,8 @@ use anyhow::Error; use serde_json::Value; -use proxmox::{ - api::{ - api, - router::SubdirMap, - Router, - }, - list_subdirs_api_method, -}; +use proxmox_schema::api; +use proxmox_router::{list_subdirs_api_method, Router, SubdirMap}; use pbs_api_types::TapeDeviceInfo; use pbs_tape::linux_list_drives::{lto_tape_device_list, linux_tape_changer_list}; diff --git a/src/api2/tape/restore.rs b/src/api2/tape/restore.rs index 61e17d1b..30e99343 100644 --- a/src/api2/tape/restore.rs +++ b/src/api2/tape/restore.rs @@ -8,25 +8,12 @@ use std::sync::Arc; use anyhow::{bail, format_err, Error}; use serde_json::Value; -use proxmox::{ - api::{ - api, - RpcEnvironment, - RpcEnvironmentType, - Router, - Permission, - schema::parse_property_string, - section_config::SectionConfigData, - }, - tools::{ - Uuid, - io::ReadExt, - fs::{ - replace_file, - CreateOptions, - }, - }, -}; +use proxmox::tools::fs::{replace_file, CreateOptions}; +use proxmox_io::ReadExt; +use proxmox_router::{Permission, Router, RpcEnvironment, RpcEnvironmentType}; +use proxmox_schema::{api, parse_property_string}; +use proxmox_section_config::SectionConfigData; +use proxmox_uuid::Uuid; use pbs_api_types::{ Authid, Userid, CryptMode, @@ -441,7 +428,7 @@ fn restore_list_worker( let mut snapshot_file_hash: BTreeMap> = BTreeMap::new(); let mut snapshot_locks = HashMap::new(); - let res = proxmox::try_block!({ + let res = proxmox_lang::try_block!({ // assemble snapshot files/locks for store_snapshot in snapshots.iter() { let mut split = store_snapshot.splitn(2, ':'); @@ -593,7 +580,7 @@ fn restore_list_worker( "Phase 3: copy snapshots from temp dir to datastores" ); for (store_snapshot, _lock) in snapshot_locks.into_iter() { - proxmox::try_block!({ + proxmox_lang::try_block!({ let mut split = store_snapshot.splitn(2, ':'); let source_datastore = split .next() diff --git a/src/api2/types/acme.rs b/src/api2/types/acme.rs index 78c80949..21e953bb 100644 --- a/src/api2/types/acme.rs +++ b/src/api2/types/acme.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; -use proxmox::api::{api, schema::{ApiType, Schema, StringSchema, ApiStringFormat}}; +use proxmox_schema::{api, ApiType, Schema, StringSchema, ApiStringFormat}; use pbs_api_types::{ DNS_ALIAS_FORMAT, DNS_NAME_FORMAT, PROXMOX_SAFE_ID_FORMAT, @@ -62,7 +62,7 @@ pub struct KnownAcmeDirectory { pub url: &'static str, } -proxmox::api_string_type! { +proxmox_schema::api_string_type! { #[api(format: &PROXMOX_SAFE_ID_FORMAT)] /// ACME account name. #[derive(Clone, Eq, PartialEq, Hash, Deserialize, Serialize)] diff --git a/src/api2/types/mod.rs b/src/api2/types/mod.rs index 50b928ed..28bea293 100644 --- a/src/api2/types/mod.rs +++ b/src/api2/types/mod.rs @@ -3,7 +3,7 @@ use anyhow::bail; use serde::{Deserialize, Serialize}; -use proxmox::api::{api, schema::*}; +use proxmox_schema::*; use pbs_api_types::StorageStatus; diff --git a/src/api2/version.rs b/src/api2/version.rs index 1a4c5b85..4ea85708 100644 --- a/src/api2/version.rs +++ b/src/api2/version.rs @@ -3,8 +3,8 @@ use anyhow::{Error}; use serde_json::{json, Value}; -use proxmox::api::{ApiHandler, ApiMethod, Router, RpcEnvironment, Permission}; -use proxmox::api::schema::ObjectSchema; +use proxmox_router::{ApiHandler, ApiMethod, Router, RpcEnvironment, Permission}; +use proxmox_schema::ObjectSchema; fn get_version( _param: Value, diff --git a/src/auth_helpers.rs b/src/auth_helpers.rs index d88bf8cc..a4ac956e 100644 --- a/src/auth_helpers.rs +++ b/src/auth_helpers.rs @@ -7,7 +7,7 @@ use openssl::rsa::Rsa; use openssl::sha; use proxmox::tools::fs::{file_get_contents, replace_file, CreateOptions}; -use proxmox::try_block; +use proxmox_lang::try_block; use pbs_buildcfg::configdir; use pbs_api_types::Userid; @@ -31,7 +31,7 @@ pub fn assemble_csrf_prevention_token( userid: &Userid, ) -> String { - let epoch = proxmox::tools::time::epoch_i64(); + let epoch = proxmox_time::epoch_i64(); let digest = compute_csrf_secret_digest(epoch, secret, userid); @@ -68,7 +68,7 @@ pub fn verify_csrf_prevention_token( bail!("invalid signature."); } - let now = proxmox::tools::time::epoch_i64(); + let now = proxmox_time::epoch_i64(); let age = now - ttime; if age < min_age { diff --git a/src/backup/verify.rs b/src/backup/verify.rs index 17179c13..9fbd5135 100644 --- a/src/backup/verify.rs +++ b/src/backup/verify.rs @@ -361,7 +361,7 @@ pub fn verify_backup_dir_with_lock( let mut verify_result = VerifyState::Ok; for info in manifest.files() { - let result = proxmox::try_block!({ + let result = proxmox_lang::try_block!({ task_log!(verify_worker.worker, " check {}", info.filename); match archive_type(&info.filename)? { ArchiveType::FixedIndex => verify_fixed_index(verify_worker, &backup_dir, info), @@ -556,7 +556,7 @@ pub fn verify_filter( match outdated_after { None => false, // never re-verify if ignored and no max age Some(max_age) => { - let now = proxmox::tools::time::epoch_i64(); + let now = proxmox_time::epoch_i64(); let days_since_last_verify = (now - last_verify.upid.starttime) / 86400; days_since_last_verify > max_age diff --git a/src/bin/docgen.rs b/src/bin/docgen.rs index 84ce53e9..4be4f1f2 100644 --- a/src/bin/docgen.rs +++ b/src/bin/docgen.rs @@ -1,29 +1,10 @@ use anyhow::{bail, Error}; use serde_json::{json, Value}; -use proxmox::{ - api::{ - schema::{ - ApiType, - Schema, - ObjectSchemaType, - ApiStringFormat, - }, - router::{ - ApiAccess, - }, - format::{ - dump_enum_properties, - dump_section_config, - get_property_string_type_text, - }, - ApiMethod, - ApiHandler, - Router, - SubRoute, - Permission, - }, -}; +use proxmox_router::{ApiAccess, ApiHandler, ApiMethod, Permission, Router, SubRoute}; +use proxmox_schema::format::{dump_enum_properties, get_property_string_type_text}; +use proxmox_schema::{ApiStringFormat, ApiType, ObjectSchemaType, Schema}; +use proxmox_section_config::dump_section_config; use pbs_api_types::PRIVILEGES; diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs index da9ae5dd..c98fba25 100644 --- a/src/bin/proxmox-backup-api.rs +++ b/src/bin/proxmox-backup-api.rs @@ -8,10 +8,9 @@ use http::Response; use hyper::{Body, Method, StatusCode}; use http::HeaderMap; -use proxmox::try_block; -use proxmox::api::RpcEnvironmentType; +use proxmox_lang::try_block; +use proxmox_router::{RpcEnvironmentType, UserInformation}; use proxmox::tools::fs::CreateOptions; -use proxmox::api::UserInformation; use proxmox_rest_server::{daemon, AuthError, ApiConfig, RestServer, RestEnvironment, ServerAdapter}; diff --git a/src/bin/proxmox-backup-debug.rs b/src/bin/proxmox-backup-debug.rs index 0ef37525..35ef320a 100644 --- a/src/bin/proxmox-backup-debug.rs +++ b/src/bin/proxmox-backup-debug.rs @@ -1,4 +1,4 @@ -use proxmox::api::{ +use proxmox_router::{ cli::{run_cli_command, CliCommandMap, CliEnvironment}, RpcEnvironment, }; diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index eca1540e..92e6bb2a 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -4,8 +4,9 @@ use std::io::{self, Write}; use anyhow::{format_err, Error}; use serde_json::{json, Value}; -use proxmox::api::{api, cli::*, RpcEnvironment}; use proxmox::tools::fs::CreateOptions; +use proxmox_router::{cli::*, RpcEnvironment}; +use proxmox_schema::api; use pbs_client::{display_task_log, view_task_result}; use pbs_tools::percent_encoding::percent_encode_component; @@ -434,7 +435,7 @@ pub fn complete_remote_datastore_name(_arg: &str, param: &HashMap now { continue; } @@ -1021,7 +1021,7 @@ fn check_schedule(worker_type: &str, event_str: &str, id: &str) -> bool { } }; - let now = proxmox::tools::time::epoch_i64(); + let now = proxmox_time::epoch_i64(); next <= now } diff --git a/src/bin/proxmox-daily-update.rs b/src/bin/proxmox-daily-update.rs index 17f79247..20745375 100644 --- a/src/bin/proxmox-daily-update.rs +++ b/src/bin/proxmox-daily-update.rs @@ -1,8 +1,8 @@ use anyhow::Error; use serde_json::json; -use proxmox::api::{cli::*, RpcEnvironment, ApiHandler}; use proxmox::tools::fs::CreateOptions; +use proxmox_router::{cli::*, RpcEnvironment, ApiHandler}; use proxmox_backup::api2; use proxmox_backup::tools::subscription; diff --git a/src/bin/proxmox-tape.rs b/src/bin/proxmox-tape.rs index 98d28c95..5de727c1 100644 --- a/src/bin/proxmox-tape.rs +++ b/src/bin/proxmox-tape.rs @@ -1,18 +1,12 @@ use anyhow::{format_err, Error}; use serde_json::{json, Value}; -use proxmox::{ - api::{ - api, - cli::*, - RpcEnvironment, - section_config::SectionConfigData, - }, - tools::{ - time::strftime_local, - io::ReadExt, - }, -}; +use proxmox_io::ReadExt; +use proxmox_router::RpcEnvironment; +use proxmox_router::cli::*; +use proxmox_schema::api; +use proxmox_section_config::SectionConfigData; +use proxmox_time::strftime_local; use pbs_client::view_task_result; use pbs_tools::format::{ diff --git a/src/bin/proxmox_backup_debug/api.rs b/src/bin/proxmox_backup_debug/api.rs index 141c0579..5b9594f3 100644 --- a/src/bin/proxmox_backup_debug/api.rs +++ b/src/bin/proxmox_backup_debug/api.rs @@ -7,13 +7,9 @@ use tokio::signal::unix::{signal, SignalKind}; use std::collections::HashMap; -use proxmox::api::{ - api, - cli::*, - format::DocumentationFormat, - schema::{parse_parameter_strings, ApiType, ParameterSchema, Schema}, - ApiHandler, ApiMethod, RpcEnvironment, SubRoute, -}; +use proxmox_router::{cli::*, ApiHandler, ApiMethod, RpcEnvironment, SubRoute}; +use proxmox_schema::{api, parse_parameter_strings, ApiType, ParameterSchema, Schema}; +use proxmox_schema::format::DocumentationFormat; use pbs_api_types::{PROXMOX_UPID_REGEX, UPID}; use pbs_client::view_task_result; @@ -381,8 +377,8 @@ struct ApiDirEntry { capabilities: String, } -const LS_SCHEMA: &proxmox::api::schema::Schema = - &proxmox::api::schema::ArraySchema::new("List of child links", &ApiDirEntry::API_SCHEMA) +const LS_SCHEMA: &proxmox_schema::Schema = + &proxmox_schema::ArraySchema::new("List of child links", &ApiDirEntry::API_SCHEMA) .schema(); async fn get_api_children( @@ -448,7 +444,7 @@ async fn ls(path: Option, mut param: Value, rpcenv: &mut dyn RpcEnvironm format_and_print_result_full( &mut serde_json::to_value(res)?, - &proxmox::api::schema::ReturnType { + &proxmox_schema::ReturnType { optional: false, schema: &LS_SCHEMA, }, diff --git a/src/bin/proxmox_backup_debug/inspect.rs b/src/bin/proxmox_backup_debug/inspect.rs index 9fe2ac1a..43e30c23 100644 --- a/src/bin/proxmox_backup_debug/inspect.rs +++ b/src/bin/proxmox_backup_debug/inspect.rs @@ -7,10 +7,11 @@ use anyhow::{bail, format_err, Error}; use serde_json::{json, Value}; use walkdir::WalkDir; -use proxmox::api::cli::{ +use proxmox_router::cli::{ format_and_print_result, get_output_format, CliCommand, CliCommandMap, CommandLineInterface, + OUTPUT_FORMAT, }; -use proxmox::api::{api, cli::*}; +use proxmox_schema::api; use pbs_tools::cli::outfile_or_stdout; use pbs_tools::crypt_config::CryptConfig; @@ -282,7 +283,7 @@ fn inspect_file( }; let mut ctime_str = index.index_ctime().to_string(); - if let Ok(s) = proxmox::tools::time::strftime_local("%c", index.index_ctime()) { + if let Ok(s) = proxmox_time::strftime_local("%c", index.index_ctime()) { ctime_str = s; } diff --git a/src/bin/proxmox_backup_debug/recover.rs b/src/bin/proxmox_backup_debug/recover.rs index 098dea09..a8665cd1 100644 --- a/src/bin/proxmox_backup_debug/recover.rs +++ b/src/bin/proxmox_backup_debug/recover.rs @@ -5,9 +5,9 @@ use std::path::Path; use anyhow::{bail, format_err, Error}; use serde_json::Value; -use proxmox::api::api; -use proxmox::api::cli::{CliCommand, CliCommandMap, CommandLineInterface}; use proxmox::tools::digest_to_hex; +use proxmox_router::cli::{CliCommand, CliCommandMap, CommandLineInterface}; +use proxmox_schema::api; use pbs_tools::crypt_config::CryptConfig; use pbs_datastore::dynamic_index::DynamicIndexReader; diff --git a/src/bin/proxmox_backup_manager/acl.rs b/src/bin/proxmox_backup_manager/acl.rs index 6cdddb13..8180631b 100644 --- a/src/bin/proxmox_backup_manager/acl.rs +++ b/src/bin/proxmox_backup_manager/acl.rs @@ -1,7 +1,8 @@ use anyhow::{bail, Error}; use serde_json::Value; -use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; use proxmox_backup::api2; diff --git a/src/bin/proxmox_backup_manager/acme.rs b/src/bin/proxmox_backup_manager/acme.rs index b1baeda7..8d929d38 100644 --- a/src/bin/proxmox_backup_manager/acme.rs +++ b/src/bin/proxmox_backup_manager/acme.rs @@ -3,8 +3,9 @@ use std::io::Write; use anyhow::{bail, Error}; use serde_json::Value; -use proxmox::api::{api, cli::*, ApiHandler, RpcEnvironment}; use proxmox::tools::fs::file_get_contents; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; use proxmox_backup::acme::AcmeClient; use proxmox_backup::api2; diff --git a/src/bin/proxmox_backup_manager/cert.rs b/src/bin/proxmox_backup_manager/cert.rs index 24bd9cc6..10632b50 100644 --- a/src/bin/proxmox_backup_manager/cert.rs +++ b/src/bin/proxmox_backup_manager/cert.rs @@ -1,6 +1,7 @@ use anyhow::{bail, Error}; -use proxmox::api::{api, cli::*}; +use proxmox_router::cli::*; +use proxmox_schema::api; use proxmox_backup::config; use proxmox_backup::auth_helpers::*; diff --git a/src/bin/proxmox_backup_manager/datastore.rs b/src/bin/proxmox_backup_manager/datastore.rs index e5ef2660..4409be9f 100644 --- a/src/bin/proxmox_backup_manager/datastore.rs +++ b/src/bin/proxmox_backup_manager/datastore.rs @@ -1,7 +1,8 @@ use anyhow::Error; use serde_json::Value; -use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; use pbs_client::view_task_result; use pbs_api_types::{DataStoreConfig, DATASTORE_SCHEMA}; diff --git a/src/bin/proxmox_backup_manager/disk.rs b/src/bin/proxmox_backup_manager/disk.rs index 668c6f16..fd9bc7de 100644 --- a/src/bin/proxmox_backup_manager/disk.rs +++ b/src/bin/proxmox_backup_manager/disk.rs @@ -1,7 +1,8 @@ use anyhow::{bail, Error}; use serde_json::Value; -use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; use pbs_api_types::{ DISK_LIST_SCHEMA, ZFS_ASHIFT_SCHEMA, ZfsRaidLevel, ZfsCompressionType, diff --git a/src/bin/proxmox_backup_manager/dns.rs b/src/bin/proxmox_backup_manager/dns.rs index 9a91cb06..e4350fb7 100644 --- a/src/bin/proxmox_backup_manager/dns.rs +++ b/src/bin/proxmox_backup_manager/dns.rs @@ -1,7 +1,8 @@ use anyhow::Error; use serde_json::Value; -use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; use proxmox_backup::api2; diff --git a/src/bin/proxmox_backup_manager/network.rs b/src/bin/proxmox_backup_manager/network.rs index 001c905d..f445c630 100644 --- a/src/bin/proxmox_backup_manager/network.rs +++ b/src/bin/proxmox_backup_manager/network.rs @@ -1,7 +1,8 @@ use anyhow::Error; use serde_json::Value; -use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; use proxmox_backup::api2; diff --git a/src/bin/proxmox_backup_manager/node.rs b/src/bin/proxmox_backup_manager/node.rs index 42109960..a3438f21 100644 --- a/src/bin/proxmox_backup_manager/node.rs +++ b/src/bin/proxmox_backup_manager/node.rs @@ -1,7 +1,9 @@ -use proxmox::api::{api, cli::*, ApiHandler, RpcEnvironment}; use anyhow::Error; use serde_json::Value; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; + use proxmox_backup::api2; #[api( diff --git a/src/bin/proxmox_backup_manager/openid.rs b/src/bin/proxmox_backup_manager/openid.rs index 24264996..1a746457 100644 --- a/src/bin/proxmox_backup_manager/openid.rs +++ b/src/bin/proxmox_backup_manager/openid.rs @@ -1,7 +1,8 @@ use anyhow::Error; use serde_json::Value; -use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; use pbs_api_types::REALM_ID_SCHEMA; diff --git a/src/bin/proxmox_backup_manager/remote.rs b/src/bin/proxmox_backup_manager/remote.rs index 4f55ceb5..c83ec1e2 100644 --- a/src/bin/proxmox_backup_manager/remote.rs +++ b/src/bin/proxmox_backup_manager/remote.rs @@ -1,7 +1,8 @@ use anyhow::Error; use serde_json::Value; -use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; use pbs_api_types::REMOTE_ID_SCHEMA; diff --git a/src/bin/proxmox_backup_manager/subscription.rs b/src/bin/proxmox_backup_manager/subscription.rs index cd69d8d3..0e626b88 100644 --- a/src/bin/proxmox_backup_manager/subscription.rs +++ b/src/bin/proxmox_backup_manager/subscription.rs @@ -1,7 +1,8 @@ use anyhow::Error; use serde_json::Value; -use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; use proxmox_backup::api2; diff --git a/src/bin/proxmox_backup_manager/sync.rs b/src/bin/proxmox_backup_manager/sync.rs index 7a1e8718..dfd8688d 100644 --- a/src/bin/proxmox_backup_manager/sync.rs +++ b/src/bin/proxmox_backup_manager/sync.rs @@ -1,7 +1,8 @@ use anyhow::Error; use serde_json::Value; -use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; use pbs_api_types::JOB_ID_SCHEMA; diff --git a/src/bin/proxmox_backup_manager/user.rs b/src/bin/proxmox_backup_manager/user.rs index cff66ce7..950601d7 100644 --- a/src/bin/proxmox_backup_manager/user.rs +++ b/src/bin/proxmox_backup_manager/user.rs @@ -3,7 +3,8 @@ use serde_json::Value; use std::collections::HashMap; -use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; use pbs_api_types::{ACL_PATH_SCHEMA, Authid, Userid}; @@ -15,7 +16,7 @@ fn render_expire(value: &Value, _record: &Value) -> Result { let text = match value.as_i64() { Some(epoch) if epoch == 0 => never, Some(epoch) => { - if let Ok(epoch_string) = proxmox::tools::time::strftime_local("%c", epoch as i64) { + if let Ok(epoch_string) = proxmox_time::strftime_local("%c", epoch as i64) { epoch_string } else { epoch.to_string() diff --git a/src/bin/proxmox_backup_manager/verify.rs b/src/bin/proxmox_backup_manager/verify.rs index 192b1bd1..6258de74 100644 --- a/src/bin/proxmox_backup_manager/verify.rs +++ b/src/bin/proxmox_backup_manager/verify.rs @@ -1,7 +1,8 @@ use anyhow::Error; use serde_json::Value; -use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; use pbs_api_types::JOB_ID_SCHEMA; diff --git a/src/bin/proxmox_tape/backup_job.rs b/src/bin/proxmox_tape/backup_job.rs index b5662f16..54f9ddd2 100644 --- a/src/bin/proxmox_tape/backup_job.rs +++ b/src/bin/proxmox_tape/backup_job.rs @@ -1,7 +1,8 @@ use anyhow::Error; use serde_json::Value; -use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; use pbs_api_types::JOB_ID_SCHEMA; use pbs_client::view_task_result; diff --git a/src/bin/proxmox_tape/changer.rs b/src/bin/proxmox_tape/changer.rs index 4c62218e..ed8ce340 100644 --- a/src/bin/proxmox_tape/changer.rs +++ b/src/bin/proxmox_tape/changer.rs @@ -1,15 +1,9 @@ use anyhow::{bail, Error}; use serde_json::Value; -use proxmox::{ - api::{ - api, - cli::*, - RpcEnvironment, - ApiHandler, - section_config::SectionConfigData, - }, -}; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; +use proxmox_section_config::SectionConfigData; use pbs_config::drive::{ complete_drive_name, diff --git a/src/bin/proxmox_tape/drive.rs b/src/bin/proxmox_tape/drive.rs index 7972ed2a..bebf645e 100644 --- a/src/bin/proxmox_tape/drive.rs +++ b/src/bin/proxmox_tape/drive.rs @@ -1,14 +1,8 @@ use anyhow::Error; use serde_json::Value; -use proxmox::{ - api::{ - api, - cli::*, - RpcEnvironment, - ApiHandler, - }, -}; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; use pbs_api_types::DRIVE_NAME_SCHEMA; diff --git a/src/bin/proxmox_tape/encryption_key.rs b/src/bin/proxmox_tape/encryption_key.rs index 06c62f4d..3feb72ff 100644 --- a/src/bin/proxmox_tape/encryption_key.rs +++ b/src/bin/proxmox_tape/encryption_key.rs @@ -1,15 +1,9 @@ use anyhow::{bail, Error}; use serde_json::Value; -use proxmox::{ - api::{ - api, - cli::*, - RpcEnvironment, - ApiHandler, - }, - sys::linux::tty, -}; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; +use proxmox::sys::linux::tty; use pbs_api_types::{ Fingerprint, Kdf, DRIVE_NAME_SCHEMA, TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA, @@ -127,7 +121,7 @@ fn show_key( _ => unreachable!(), }; - let options = proxmox::api::cli::default_table_format_options() + let options = proxmox_router::cli::default_table_format_options() .column(ColumnConfig::new("kdf")) .column(ColumnConfig::new("created").renderer(pbs_tools::format::render_epoch)) .column(ColumnConfig::new("modified").renderer(pbs_tools::format::render_epoch)) diff --git a/src/bin/proxmox_tape/media.rs b/src/bin/proxmox_tape/media.rs index e65108ec..e305a9fa 100644 --- a/src/bin/proxmox_tape/media.rs +++ b/src/bin/proxmox_tape/media.rs @@ -1,14 +1,8 @@ use anyhow::{Error}; use serde_json::Value; -use proxmox::{ - api::{ - api, - cli::*, - RpcEnvironment, - ApiHandler, - }, -}; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; use pbs_api_types::{ MEDIA_POOL_NAME_SCHEMA, CHANGER_NAME_SCHEMA, MediaStatus, MediaListEntry, diff --git a/src/bin/proxmox_tape/pool.rs b/src/bin/proxmox_tape/pool.rs index 6fe9a63c..2a4f96b5 100644 --- a/src/bin/proxmox_tape/pool.rs +++ b/src/bin/proxmox_tape/pool.rs @@ -1,14 +1,8 @@ use anyhow::{Error}; use serde_json::Value; -use proxmox::{ - api::{ - api, - cli::*, - RpcEnvironment, - ApiHandler, - }, -}; +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; use pbs_api_types::MEDIA_POOL_NAME_SCHEMA; use pbs_config::media_pool::complete_pool_name; diff --git a/src/bin/sg-tape-cmd.rs b/src/bin/sg-tape-cmd.rs index ee4c32c2..10966d90 100644 --- a/src/bin/sg-tape-cmd.rs +++ b/src/bin/sg-tape-cmd.rs @@ -9,14 +9,9 @@ use std::os::unix::io::{AsRawFd, FromRawFd}; use anyhow::{bail, Error}; use serde_json::Value; -use proxmox::{ - api::{ - api, - cli::*, - RpcEnvironment, - }, - tools::Uuid, -}; +use proxmox_router::{cli::*, RpcEnvironment}; +use proxmox_schema::api; +use proxmox_uuid::Uuid; use pbs_api_types::{ Fingerprint, LTO_DRIVE_PATH_SCHEMA, DRIVE_NAME_SCHEMA, TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA, @@ -112,7 +107,7 @@ fn set_encryption( param: Value, ) -> Result<(), Error> { - let result = proxmox::try_block!({ + let result = proxmox_lang::try_block!({ let mut handle = get_tape_handle(¶m)?; match (fingerprint, uuid) { diff --git a/src/config/acme/plugin.rs b/src/config/acme/plugin.rs index e0e3db48..f90de70e 100644 --- a/src/config/acme/plugin.rs +++ b/src/config/acme/plugin.rs @@ -3,11 +3,8 @@ use lazy_static::lazy_static; use serde::{Deserialize, Serialize}; use serde_json::Value; -use proxmox::api::{ - api, - schema::*, - section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}, -}; +use proxmox_schema::{api, ApiType, Schema, StringSchema, Updater}; +use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use pbs_config::{open_backup_lockfile, BackupLockGuard}; use pbs_api_types::PROXMOX_SAFE_ID_FORMAT; diff --git a/src/config/mod.rs b/src/config/mod.rs index 0f4119d2..f93dd143 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -10,7 +10,7 @@ use openssl::rsa::{Rsa}; use openssl::x509::{X509Builder}; use openssl::pkey::PKey; -use proxmox::try_block; +use proxmox_lang::try_block; use pbs_buildcfg::{self, configdir}; @@ -115,7 +115,7 @@ pub fn update_self_signed_cert(force: bool) -> Result<(), Error> { // we try to generate an unique 'subject' to avoid browser problems //(reused serial numbers, ..) - let uuid = proxmox::tools::uuid::Uuid::generate(); + let uuid = proxmox_uuid::Uuid::generate(); let mut subject_name = openssl::x509::X509NameBuilder::new()?; subject_name.append_entry_by_text("O", "Proxmox Backup Server")?; diff --git a/src/config/node.rs b/src/config/node.rs index 15b153a1..93444216 100644 --- a/src/config/node.rs +++ b/src/config/node.rs @@ -3,8 +3,7 @@ use std::collections::HashSet; use anyhow::{bail, Error}; use serde::{Deserialize, Serialize}; -use proxmox::api::api; -use proxmox::api::schema::{ApiStringFormat, ApiType, Updater}; +use proxmox_schema::{api, ApiStringFormat, ApiType, Updater}; use proxmox_http::ProxyConfig; diff --git a/src/config/tfa.rs b/src/config/tfa.rs index 4cd57d64..2a41cbdf 100644 --- a/src/config/tfa.rs +++ b/src/config/tfa.rs @@ -16,14 +16,11 @@ use webauthn_rs::{proto::UserVerificationPolicy, Webauthn}; use webauthn_rs::proto::Credential as WebauthnCredential; -use proxmox::api::api; -use proxmox::api::schema::Updater; use proxmox::sys::error::SysError; use proxmox::tools::fs::CreateOptions; -use proxmox::tools::tfa::totp::Totp; -use proxmox::tools::tfa::u2f; -use proxmox::tools::uuid::Uuid; -use proxmox::tools::AsHex; +use proxmox_schema::{api, Updater}; +use proxmox_tfa::{totp::Totp, u2f}; +use proxmox_uuid::Uuid; use pbs_buildcfg::configdir; use pbs_config::{open_backup_lockfile, BackupLockGuard}; @@ -276,7 +273,7 @@ impl TfaConfig { } /// Remove non-existent users. - pub fn cleanup_users(&mut self, config: &proxmox::api::section_config::SectionConfigData) { + pub fn cleanup_users(&mut self, config: &proxmox_section_config::SectionConfigData) { self.users .retain(|user, _| config.lookup::("user", user.as_str()).is_ok()); } @@ -341,7 +338,7 @@ impl TfaEntry { id: Uuid::generate().to_string(), enable: true, description, - created: proxmox::tools::time::epoch_i64(), + created: proxmox_time::epoch_i64(), }, entry, } @@ -371,7 +368,7 @@ impl U2fRegistrationChallenge { Self { challenge, description, - created: proxmox::tools::time::epoch_i64(), + created: proxmox_time::epoch_i64(), } } } @@ -410,7 +407,7 @@ impl WebauthnRegistrationChallenge { state, challenge, description, - created: proxmox::tools::time::epoch_i64(), + created: proxmox_time::epoch_i64(), } } } @@ -441,7 +438,7 @@ impl WebauthnAuthChallenge { Self { state, challenge, - created: proxmox::tools::time::epoch_i64(), + created: proxmox_time::epoch_i64(), } } } @@ -614,7 +611,7 @@ impl TfaUserChallengeData { challenge: &str, response: &str, ) -> Result, Error> { - let expire_before = proxmox::tools::time::epoch_i64() - CHALLENGE_TIMEOUT; + let expire_before = proxmox_time::epoch_i64() - CHALLENGE_TIMEOUT; let index = self .inner @@ -659,7 +656,7 @@ impl TfaUserChallengeData { response: webauthn_rs::proto::RegisterPublicKeyCredential, existing_registrations: &[TfaEntry], ) -> Result, Error> { - let expire_before = proxmox::tools::time::epoch_i64() - CHALLENGE_TIMEOUT; + let expire_before = proxmox_time::epoch_i64() - CHALLENGE_TIMEOUT; let index = self .inner @@ -991,7 +988,7 @@ impl TfaUserData { mut webauthn: Webauthn, mut response: Value, ) -> Result<(), Error> { - let expire_before = proxmox::tools::time::epoch_i64() - CHALLENGE_TIMEOUT; + let expire_before = proxmox_time::epoch_i64() - CHALLENGE_TIMEOUT; let challenge = match response .as_object_mut() @@ -1083,9 +1080,9 @@ impl Recovery { proxmox::sys::linux::fill_with_random_data(&mut secret)?; let mut this = Self { - secret: AsHex(&secret).to_string(), + secret: hex::encode(&secret).to_string(), entries: Vec::with_capacity(10), - created: proxmox::tools::time::epoch_i64(), + created: proxmox_time::epoch_i64(), }; let mut original = Vec::new(); @@ -1093,14 +1090,11 @@ impl Recovery { let mut key_data = [0u8; 80]; // 10 keys of 12 bytes proxmox::sys::linux::fill_with_random_data(&mut key_data)?; for b in key_data.chunks(8) { + // unwrap: encoding hex bytes to fixed sized arrays let entry = format!( - "{}-{}-{}-{}", - AsHex(&b[0..2]), - AsHex(&b[2..4]), - AsHex(&b[4..6]), - AsHex(&b[6..8]), + "{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}", + b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], ); - this.entries.push(Some(this.hash(entry.as_bytes())?)); original.push(entry); } @@ -1120,7 +1114,7 @@ impl Recovery { .sign_oneshot_to_vec(data) .map_err(|err| format_err!("error calculating hmac: {}", err))?; - Ok(AsHex(&hmac).to_string()) + Ok(hex::encode(&hmac)) } /// Iterator over available keys. @@ -1159,7 +1153,7 @@ where D: Deserializer<'de>, T: Deserialize<'de> + IsExpired, { - let expire_before = proxmox::tools::time::epoch_i64() - CHALLENGE_TIMEOUT; + let expire_before = proxmox_time::epoch_i64() - CHALLENGE_TIMEOUT; Ok( deserializer.deserialize_seq(crate::tools::serde_filter::FilteredVecVisitor::new( "a challenge entry", diff --git a/src/server/auth.rs b/src/server/auth.rs index 2e6beac7..33d655d4 100644 --- a/src/server/auth.rs +++ b/src/server/auth.rs @@ -2,7 +2,7 @@ use anyhow::format_err; -use proxmox::api::UserInformation; +use proxmox_router::UserInformation; use pbs_tools::ticket::{self, Ticket}; use pbs_config::{token_shadow, CachedUserInfo}; diff --git a/src/server/email_notifications.rs b/src/server/email_notifications.rs index a70f2d1b..db93fea2 100644 --- a/src/server/email_notifications.rs +++ b/src/server/email_notifications.rs @@ -4,8 +4,8 @@ use serde_json::json; use handlebars::{Handlebars, Helper, Context, RenderError, RenderContext, Output, HelperResult, TemplateError}; use proxmox::tools::email::sendmail; -use proxmox::api::schema::{ApiType, parse_property_string}; -use proxmox::try_block; +use proxmox_lang::try_block; +use proxmox_schema::{parse_property_string, ApiType}; use pbs_tools::format::HumanByte; use pbs_api_types::{ diff --git a/src/server/jobstate.rs b/src/server/jobstate.rs index 64feb878..1377470d 100644 --- a/src/server/jobstate.rs +++ b/src/server/jobstate.rs @@ -147,7 +147,7 @@ pub fn update_job_last_run_time(jobtype: &str, jobname: &str) -> Result<(), Erro Ok(job) => job, Err(_) => return Ok(()), // was locked (running), so do not update }; - let time = proxmox::tools::time::epoch_i64(); + let time = proxmox_time::epoch_i64(); job.state = match JobState::load(jobtype, jobname)? { JobState::Created { .. } => JobState::Created { time }, @@ -220,7 +220,7 @@ impl JobState { } } else { Ok(JobState::Created { - time: proxmox::tools::time::epoch_i64() - 30, + time: proxmox_time::epoch_i64() - 30, }) } } @@ -241,7 +241,7 @@ impl Job { jobtype: jobtype.to_string(), jobname: jobname.to_string(), state: JobState::Created { - time: proxmox::tools::time::epoch_i64(), + time: proxmox_time::epoch_i64(), }, _lock, }) diff --git a/src/server/pull.rs b/src/server/pull.rs index 61337038..a15d3bb5 100644 --- a/src/server/pull.rs +++ b/src/server/pull.rs @@ -9,8 +9,9 @@ use std::time::SystemTime; use anyhow::{bail, format_err, Error}; use serde_json::json; +use http::StatusCode; -use proxmox::api::error::{HttpError, StatusCode}; +use proxmox_router::HttpError; use pbs_api_types::{Authid, SnapshotListItem, GroupListItem}; use pbs_datastore::{DataStore, BackupInfo, BackupDir, BackupGroup, StoreProgress}; @@ -306,7 +307,7 @@ async fn pull_snapshot( let tmp_manifest_blob = DataBlob::load_from_reader(&mut tmp_manifest_file)?; if manifest_name.exists() { - let manifest_blob = proxmox::try_block!({ + let manifest_blob = proxmox_lang::try_block!({ let mut manifest_file = std::fs::File::open(&manifest_name).map_err(|err| { format_err!( "unable to open local manifest {:?} - {}", @@ -476,12 +477,12 @@ impl SkipInfo { fn affected(&self) -> Result { match self.count { 0 => Ok(String::new()), - 1 => proxmox::tools::time::epoch_to_rfc3339_utc(self.oldest), + 1 => Ok(proxmox_time::epoch_to_rfc3339_utc(self.oldest)?), _ => { Ok(format!( "{} .. {}", - proxmox::tools::time::epoch_to_rfc3339_utc(self.oldest)?, - proxmox::tools::time::epoch_to_rfc3339_utc(self.newest)?, + proxmox_time::epoch_to_rfc3339_utc(self.oldest)?, + proxmox_time::epoch_to_rfc3339_utc(self.newest)?, )) } } @@ -706,7 +707,7 @@ pub async fn pull_store( } if delete { - let result: Result<(), Error> = proxmox::try_block!({ + let result: Result<(), Error> = proxmox_lang::try_block!({ let local_groups = BackupInfo::list_backup_groups(&tgt_store.base_path())?; for local_group in local_groups { if new_groups.contains(&local_group) { diff --git a/src/tape/changer/online_status_map.rs b/src/tape/changer/online_status_map.rs index 43760663..e86181b3 100644 --- a/src/tape/changer/online_status_map.rs +++ b/src/tape/changer/online_status_map.rs @@ -3,8 +3,8 @@ use std::collections::{HashMap, HashSet}; use anyhow::{bail, Error}; -use proxmox::tools::Uuid; -use proxmox::api::section_config::SectionConfigData; +use proxmox_section_config::SectionConfigData; +use proxmox_uuid::Uuid; use pbs_api_types::{VirtualTapeDrive, ScsiTapeChanger}; use pbs_tape::{ElementStatus, MtxStatus}; diff --git a/src/tape/drive/lto/mod.rs b/src/tape/drive/lto/mod.rs index 7dcd2809..8b87ca4f 100644 --- a/src/tape/drive/lto/mod.rs +++ b/src/tape/drive/lto/mod.rs @@ -17,7 +17,7 @@ use std::convert::TryInto; use anyhow::{bail, format_err, Error}; -use proxmox::tools::Uuid; +use proxmox_uuid::Uuid; use pbs_api_types::{ Fingerprint, MamAttribute, LtoDriveAndMediaStatus, LtoTapeDrive, Lp17VolumeStatistics, @@ -47,7 +47,7 @@ use crate::{ /// - for autoloader only, try to reload ejected tapes pub fn open_lto_tape_drive(config: &LtoTapeDrive) -> Result { - proxmox::try_block!({ + proxmox_lang::try_block!({ let file = open_lto_tape_device(&config.path)?; let mut handle = LtoTapeHandle::new(file)?; diff --git a/src/tape/drive/mod.rs b/src/tape/drive/mod.rs index 1780fe2d..16845973 100644 --- a/src/tape/drive/mod.rs +++ b/src/tape/drive/mod.rs @@ -8,15 +8,13 @@ pub use lto::*; use std::path::PathBuf; use anyhow::{bail, format_err, Error}; -use ::serde::{Deserialize}; +use serde::Deserialize; use serde_json::Value; use nix::fcntl::OFlag; use nix::sys::stat::Mode; use proxmox::{ tools::{ - Uuid, - io::ReadExt, fs::{ lock_file, atomic_open_or_create_file, @@ -25,8 +23,10 @@ use proxmox::{ CreateOptions, } }, - api::section_config::SectionConfigData, }; +use proxmox_io::ReadExt; +use proxmox_section_config::SectionConfigData; +use proxmox_uuid::Uuid; use pbs_api_types::{VirtualTapeDrive, LtoTapeDrive, Fingerprint}; use pbs_config::key_config::KeyConfig; @@ -364,7 +364,7 @@ pub fn request_and_load_media( MediaId, ), Error> { - let check_label = |handle: &mut dyn TapeDriver, uuid: &proxmox::tools::Uuid| { + let check_label = |handle: &mut dyn TapeDriver, uuid: &proxmox_uuid::Uuid| { if let Ok((Some(media_id), _)) = handle.read_label() { task_log!( worker, diff --git a/src/tape/drive/virtual_tape.rs b/src/tape/drive/virtual_tape.rs index 8038231c..0cc8ae70 100644 --- a/src/tape/drive/virtual_tape.rs +++ b/src/tape/drive/virtual_tape.rs @@ -42,7 +42,7 @@ use crate::{ /// This needs to lock the drive pub fn open_virtual_tape_drive(config: &VirtualTapeDrive) -> Result { - proxmox::try_block!({ + proxmox_lang::try_block!({ let mut lock_path = std::path::PathBuf::from(&config.path); lock_path.push(".drive.lck"); diff --git a/src/tape/file_formats/catalog_archive.rs b/src/tape/file_formats/catalog_archive.rs index 0b58958f..b27adff0 100644 --- a/src/tape/file_formats/catalog_archive.rs +++ b/src/tape/file_formats/catalog_archive.rs @@ -1,10 +1,8 @@ use std::fs::File; use std::io::Read; -use proxmox::{ - sys::error::SysError, - tools::Uuid, -}; +use proxmox::sys::error::SysError; +use proxmox_uuid::Uuid; use pbs_tape::{ PROXMOX_TAPE_BLOCK_SIZE, @@ -53,9 +51,9 @@ pub fn tape_write_catalog<'a>( return Ok(None); } - let mut file_copy_buffer = proxmox::tools::vec::undefined(PROXMOX_TAPE_BLOCK_SIZE); + let mut file_copy_buffer = proxmox_io::vec::undefined(PROXMOX_TAPE_BLOCK_SIZE); - let result: Result<(), std::io::Error> = proxmox::try_block!({ + let result: Result<(), std::io::Error> = proxmox_lang::try_block!({ let file_size = file.metadata()?.len(); let mut remaining = file_size; diff --git a/src/tape/file_formats/chunk_archive.rs b/src/tape/file_formats/chunk_archive.rs index c9d8524b..9bd5c814 100644 --- a/src/tape/file_formats/chunk_archive.rs +++ b/src/tape/file_formats/chunk_archive.rs @@ -3,10 +3,8 @@ use std::io::Read; use anyhow::{bail, Error}; use endian_trait::Endian; -use proxmox::tools::{ - Uuid, - io::ReadExt, -}; +use proxmox_io::ReadExt; +use proxmox_uuid::Uuid; use pbs_datastore::DataBlob; use pbs_tape::{ diff --git a/src/tape/file_formats/mod.rs b/src/tape/file_formats/mod.rs index de43d6bc..9a76646e 100644 --- a/src/tape/file_formats/mod.rs +++ b/src/tape/file_formats/mod.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; use endian_trait::Endian; use serde::{Deserialize, Serialize}; -use proxmox::tools::Uuid; +use proxmox_uuid::Uuid; use pbs_api_types::Fingerprint; diff --git a/src/tape/file_formats/multi_volume_reader.rs b/src/tape/file_formats/multi_volume_reader.rs index 84f861b5..83d19e79 100644 --- a/src/tape/file_formats/multi_volume_reader.rs +++ b/src/tape/file_formats/multi_volume_reader.rs @@ -2,7 +2,7 @@ use std::io::{Read}; use anyhow::{bail, Error}; -use proxmox::tools::io::ReadExt; +use proxmox_io::ReadExt; use pbs_tape::{TapeRead, MediaContentHeader}; @@ -50,7 +50,7 @@ impl <'a> Read for MultiVolumeReader<'a> { let mut reader = (self.next_reader_fn)() .map_err(|err| proxmox::io_format_err!("multi-volume next failed: {}", err))?; - proxmox::try_block!({ + proxmox_lang::try_block!({ let part_header: MediaContentHeader = unsafe { reader.read_le_value()? }; self.reader = Some(reader); diff --git a/src/tape/file_formats/multi_volume_writer.rs b/src/tape/file_formats/multi_volume_writer.rs index 6f2de9f0..aef34ec5 100644 --- a/src/tape/file_formats/multi_volume_writer.rs +++ b/src/tape/file_formats/multi_volume_writer.rs @@ -1,6 +1,6 @@ use anyhow::Error; -use proxmox::tools::Uuid; +use proxmox_uuid::Uuid; use pbs_tape::{TapeWrite, MediaContentHeader}; diff --git a/src/tape/file_formats/snapshot_archive.rs b/src/tape/file_formats/snapshot_archive.rs index c2f289d2..502b3cbb 100644 --- a/src/tape/file_formats/snapshot_archive.rs +++ b/src/tape/file_formats/snapshot_archive.rs @@ -2,10 +2,8 @@ use std::io::{Read, Write}; use std::pin::Pin; use std::task::{Context, Poll}; -use proxmox::{ - sys::error::SysError, - tools::Uuid, -}; +use proxmox::sys::error::SysError; +use proxmox_uuid::Uuid; use pbs_tape::{ PROXMOX_TAPE_BLOCK_SIZE, @@ -46,9 +44,9 @@ pub fn tape_write_snapshot_archive<'a>( let root_metadata = pxar::Metadata::dir_builder(0o0664).build(); - let mut file_copy_buffer = proxmox::tools::vec::undefined(PROXMOX_TAPE_BLOCK_SIZE); + let mut file_copy_buffer = proxmox_io::vec::undefined(PROXMOX_TAPE_BLOCK_SIZE); - let result: Result<(), std::io::Error> = proxmox::try_block!({ + let result: Result<(), std::io::Error> = proxmox_lang::try_block!({ let leom = writer.write_header(&header, &header_data)?; if leom { diff --git a/src/tape/inventory.rs b/src/tape/inventory.rs index 2b96da74..593985ed 100644 --- a/src/tape/inventory.rs +++ b/src/tape/inventory.rs @@ -30,14 +30,8 @@ use anyhow::{bail, Error}; use serde::{Serialize, Deserialize}; use serde_json::json; -use proxmox::tools::{ - Uuid, - fs::{ - replace_file, - file_get_json, - CreateOptions, - }, -}; +use proxmox::tools::fs::{replace_file, file_get_json, CreateOptions}; +use proxmox_uuid::Uuid; use proxmox_systemd::time::compute_next_event; use pbs_config::BackupLockGuard; @@ -571,7 +565,7 @@ impl Inventory { if let Some(ctime) = self.media_set_start_time(media_set_uuid) { let mut template = template.unwrap_or_else(|| String::from("%c")); template = template.replace("%id%", &media_set_uuid.to_string()); - proxmox::tools::time::strftime_local(&template, ctime) + Ok(proxmox_time::strftime_local(&template, ctime)?) } else { // We don't know the set start time, so we cannot use the template Ok(media_set_uuid.to_string()) diff --git a/src/tape/media_catalog.rs b/src/tape/media_catalog.rs index f5169d4c..8fff17f1 100644 --- a/src/tape/media_catalog.rs +++ b/src/tape/media_catalog.rs @@ -11,18 +11,13 @@ use endian_trait::Endian; use pbs_tools::fs::read_subdir; use pbs_datastore::backup_info::BackupDir; -use proxmox::tools::{ - Uuid, - fs::{ - fchown, - create_path, - CreateOptions, - }, - io::{ - WriteExt, - ReadExt, - }, +use proxmox::tools::fs::{ + fchown, + create_path, + CreateOptions, }; +use proxmox_io::{WriteExt, ReadExt}; +use proxmox_uuid::Uuid; use crate::{ tape::{ @@ -207,7 +202,7 @@ impl MediaCatalog { let path = Self::catalog_path(base_path, uuid); - let me = proxmox::try_block!({ + let me = proxmox_lang::try_block!({ Self::create_basedir(base_path)?; @@ -295,7 +290,7 @@ impl MediaCatalog { let tmp_path = Self::tmp_catalog_path(base_path, uuid); - let me = proxmox::try_block!({ + let me = proxmox_lang::try_block!({ let file = Self::create_temporary_database_file(base_path, uuid)?; @@ -380,7 +375,7 @@ impl MediaCatalog { let pending = &self.pending; // Note: lock file, to get a consistent view with load_catalog nix::fcntl::flock(file.as_raw_fd(), nix::fcntl::FlockArg::LockExclusive)?; - let result: Result<(), Error> = proxmox::try_block!({ + let result: Result<(), Error> = proxmox_lang::try_block!({ file.write_all(pending)?; file.flush()?; file.sync_data()?; diff --git a/src/tape/media_pool.rs b/src/tape/media_pool.rs index 5ae2f9dc..2989a1c2 100644 --- a/src/tape/media_pool.rs +++ b/src/tape/media_pool.rs @@ -12,7 +12,7 @@ use std::path::{PathBuf, Path}; use anyhow::{bail, Error}; use serde::{Deserialize, Serialize}; -use proxmox::tools::Uuid; +use proxmox_uuid::Uuid; use pbs_api_types::{ Fingerprint, MediaStatus, MediaLocation, MediaSetPolicy, RetentionPolicy, diff --git a/src/tape/media_set.rs b/src/tape/media_set.rs index 5568e7f6..2c766339 100644 --- a/src/tape/media_set.rs +++ b/src/tape/media_set.rs @@ -1,7 +1,7 @@ use anyhow::{bail, Error}; use serde::{Serialize, Deserialize}; -use proxmox::tools::Uuid; +use proxmox_uuid::Uuid; /// MediaSet - Ordered group of media #[derive(Debug, Serialize, Deserialize)] diff --git a/src/tape/pool_writer/catalog_set.rs b/src/tape/pool_writer/catalog_set.rs index d5903413..7f42703d 100644 --- a/src/tape/pool_writer/catalog_set.rs +++ b/src/tape/pool_writer/catalog_set.rs @@ -1,6 +1,6 @@ use anyhow::{bail, Error}; -use proxmox::tools::Uuid; +use proxmox_uuid::Uuid; use crate::{ tape::{ diff --git a/src/tape/pool_writer/mod.rs b/src/tape/pool_writer/mod.rs index eed0d61e..cc069ff5 100644 --- a/src/tape/pool_writer/mod.rs +++ b/src/tape/pool_writer/mod.rs @@ -11,7 +11,7 @@ use std::sync::{Arc, Mutex}; use anyhow::{bail, Error}; -use proxmox::tools::Uuid; +use proxmox_uuid::Uuid; use pbs_tools::{task_log, task_warn}; use pbs_config::tape_encryption_keys::load_key_configs; @@ -74,7 +74,7 @@ impl PoolWriter { force_media_set: bool, ) -> Result { - let current_time = proxmox::tools::time::epoch_i64(); + let current_time = proxmox_time::epoch_i64(); let new_media_set_reason = pool.start_write_session(current_time, force_media_set)?; if let Some(reason) = new_media_set_reason { @@ -202,7 +202,7 @@ impl PoolWriter { None => None, }; - let current_time = proxmox::tools::time::epoch_i64(); + let current_time = proxmox_time::epoch_i64(); let media_uuid = self.pool.alloc_writable_media(current_time)?; let media = self.pool.lookup_media(&media_uuid).unwrap(); diff --git a/src/tape/pool_writer/new_chunks_iterator.rs b/src/tape/pool_writer/new_chunks_iterator.rs index 4adf67f9..71810a83 100644 --- a/src/tape/pool_writer/new_chunks_iterator.rs +++ b/src/tape/pool_writer/new_chunks_iterator.rs @@ -36,7 +36,7 @@ impl NewChunksIterator { let datastore_name = snapshot_reader.datastore_name(); - let result: Result<(), Error> = proxmox::try_block!({ + let result: Result<(), Error> = proxmox_lang::try_block!({ let mut chunk_iter = snapshot_reader.chunk_iterator()?; diff --git a/src/tape/test/compute_media_state.rs b/src/tape/test/compute_media_state.rs index 6dbfaf4f..e7e1c34f 100644 --- a/src/tape/test/compute_media_state.rs +++ b/src/tape/test/compute_media_state.rs @@ -5,9 +5,7 @@ use std::path::PathBuf; use anyhow::Error; -use proxmox::tools::{ - Uuid, -}; +use proxmox_uuid::Uuid; use pbs_api_types::{MediaStatus, MediaSetPolicy, RetentionPolicy}; diff --git a/src/tape/test/current_set_usable.rs b/src/tape/test/current_set_usable.rs index 2f3063be..822ef77e 100644 --- a/src/tape/test/current_set_usable.rs +++ b/src/tape/test/current_set_usable.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; use anyhow::Error; -use proxmox::tools::Uuid; +use proxmox_uuid::Uuid; use pbs_api_types::{RetentionPolicy, MediaSetPolicy}; diff --git a/src/tape/test/inventory.rs b/src/tape/test/inventory.rs index 8c74ac1c..10179d5d 100644 --- a/src/tape/test/inventory.rs +++ b/src/tape/test/inventory.rs @@ -5,9 +5,7 @@ use std::path::PathBuf; use anyhow::{bail, Error}; -use proxmox::tools::{ - Uuid, -}; +use proxmox_uuid::Uuid; use pbs_api_types::{MediaLocation, MediaStatus}; diff --git a/src/tools/apt.rs b/src/tools/apt.rs index 754b325f..209274a8 100644 --- a/src/tools/apt.rs +++ b/src/tools/apt.rs @@ -4,8 +4,8 @@ use std::collections::HashMap; use anyhow::{Error, bail, format_err}; use apt_pkg_native::Cache; -use proxmox::const_regex; use proxmox::tools::fs::{file_read_optional_string, replace_file, CreateOptions}; +use proxmox_schema::const_regex; use pbs_api_types::APTUpdateInfo; diff --git a/src/tools/config.rs b/src/tools/config.rs index f908d67c..ec8f3f86 100644 --- a/src/tools/config.rs +++ b/src/tools/config.rs @@ -6,7 +6,7 @@ use anyhow::{bail, format_err, Error}; use serde::{Deserialize, Serialize}; use serde_json::Value; -use proxmox::api::schema::{ +use proxmox_schema::{ parse_property_string, parse_simple_value, verify_json_object, ObjectSchemaType, Schema, }; @@ -152,7 +152,7 @@ fn object_to_writer(output: &mut dyn Write, object: &Object) -> Result<(), Error #[test] fn test() { - use proxmox::api::schema::ApiType; + use proxmox_schema::ApiType; // let's just reuse some schema we actually have available: use crate::config::node::NodeConfig; diff --git a/src/tools/disks/mod.rs b/src/tools/disks/mod.rs index 115653af..d3e69c6d 100644 --- a/src/tools/disks/mod.rs +++ b/src/tools/disks/mod.rs @@ -17,7 +17,7 @@ use ::serde::{Deserialize, Serialize}; use proxmox::sys::error::io_err_other; use proxmox::sys::linux::procfs::{MountInfo, mountinfo::Device}; use proxmox::{io_bail, io_format_err}; -use proxmox::api::api; +use proxmox_schema::api; use pbs_api_types::{BLOCKDEVICE_NAME_REGEX, StorageStatus}; diff --git a/src/tools/disks/smart.rs b/src/tools/disks/smart.rs index fb85f667..20d9ceaa 100644 --- a/src/tools/disks/smart.rs +++ b/src/tools/disks/smart.rs @@ -4,7 +4,7 @@ use lazy_static::lazy_static; use anyhow::{bail, Error}; use ::serde::{Deserialize, Serialize}; -use proxmox::api::api; +use proxmox_schema::api; #[api()] #[derive(Debug, Serialize, Deserialize)] diff --git a/src/tools/serde_filter.rs b/src/tools/serde_filter.rs index b8402696..dc579e4e 100644 --- a/src/tools/serde_filter.rs +++ b/src/tools/serde_filter.rs @@ -34,7 +34,7 @@ use serde::Deserialize; /// where /// D: Deserializer<'de>, /// { -/// let expire_before = proxmox::tools::time::epoch_i64() - CHALLENGE_TIMEOUT; +/// let expire_before = proxmox_time::epoch_i64() - CHALLENGE_TIMEOUT; /// /// Ok(deserializer.deserialize_seq( /// FilteredVecVisitor::new( diff --git a/src/tools/subscription.rs b/src/tools/subscription.rs index c6cf5381..1a9ada66 100644 --- a/src/tools/subscription.rs +++ b/src/tools/subscription.rs @@ -4,7 +4,7 @@ use regex::Regex; use serde::{Deserialize, Serialize}; use serde_json::json; -use proxmox::api::api; +use proxmox_schema::api; use proxmox::tools::fs::{replace_file, CreateOptions}; use proxmox_http::client::SimpleHttp; @@ -229,7 +229,7 @@ fn test_parse_register_response() -> Result<(), Error> { /// queries the up to date subscription status and parses the response pub fn check_subscription(key: String, server_id: String) -> Result { - let now = proxmox::tools::time::epoch_i64(); + let now = proxmox_time::epoch_i64(); let (response, challenge) = pbs_runtime::block_on(register_subscription(&key, &server_id, now)) .map_err(|err| format_err!("Error checking subscription: {}", err))?; @@ -268,7 +268,7 @@ pub fn read_subscription() -> Result, Error> { })); } - let age = proxmox::tools::time::epoch_i64() - info.checktime.unwrap_or(0); + let age = proxmox_time::epoch_i64() - info.checktime.unwrap_or(0); if age < -5400 { // allow some delta for DST changes or time syncs, 1.5h return Ok(Some( SubscriptionInfo { status: SubscriptionStatus::INVALID, diff --git a/src/tools/systemd/config.rs b/src/tools/systemd/config.rs index 9526a525..ed95bcff 100644 --- a/src/tools/systemd/config.rs +++ b/src/tools/systemd/config.rs @@ -3,14 +3,8 @@ use lazy_static::lazy_static; use super::types::*; -use proxmox::api::{ - schema::*, - section_config::{ - SectionConfig, - SectionConfigData, - SectionConfigPlugin, - } -}; +use proxmox_schema::*; +use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use proxmox::tools::{fs::replace_file, fs::CreateOptions}; diff --git a/src/tools/systemd/types.rs b/src/tools/systemd/types.rs index d44af70e..d36ea437 100644 --- a/src/tools/systemd/types.rs +++ b/src/tools/systemd/types.rs @@ -1,6 +1,6 @@ use serde::{Serialize, Deserialize}; -use proxmox::api::{ api, schema::* }; +use proxmox_schema::*; use pbs_api_types::SINGLE_LINE_COMMENT_FORMAT; pub const SYSTEMD_SECTION_NAME_SCHEMA: Schema = StringSchema::new( diff --git a/tests/blob_writer.rs b/tests/blob_writer.rs index a20c0972..344d9808 100644 --- a/tests/blob_writer.rs +++ b/tests/blob_writer.rs @@ -1,7 +1,8 @@ -use anyhow::{bail, Error}; use std::sync::Arc; use std::io::Cursor; use std::io::{Read, Write, Seek, SeekFrom }; + +use anyhow::{bail, Error}; use lazy_static::lazy_static; use pbs_tools::crypt_config::CryptConfig; diff --git a/tests/catar.rs b/tests/catar.rs index 0eea3945..15182f7d 100644 --- a/tests/catar.rs +++ b/tests/catar.rs @@ -1,6 +1,6 @@ use std::process::Command; -use anyhow::{Error}; +use anyhow::Error; use pbs_client::pxar::*; diff --git a/tests/prune.rs b/tests/prune.rs index 35b40ad7..4853ee49 100644 --- a/tests/prune.rs +++ b/tests/prune.rs @@ -1,6 +1,7 @@ -use anyhow::{Error}; use std::path::PathBuf; +use anyhow::Error; + use pbs_api_types::PruneOptions; use pbs_datastore::manifest::MANIFEST_BLOB_NAME; use pbs_datastore::prune::compute_prune_info; diff --git a/tests/verify-api.rs b/tests/verify-api.rs index 2d282e03..0df148b8 100644 --- a/tests/verify-api.rs +++ b/tests/verify-api.rs @@ -2,9 +2,10 @@ use std::collections::HashSet; use anyhow::{bail, format_err, Error}; +use proxmox_schema::*; +use proxmox_router::{ApiMethod, Permission, Router, SubdirMap, SubRoute}; + use proxmox_backup::api2; -use proxmox::api::*; -use proxmox::api::schema::*; // Simply test if api lookup tables inside Routers and Schemas are // correctly sorted. diff --git a/tests/worker-task-abort.rs b/tests/worker-task-abort.rs index 1fdea606..c3278c4b 100644 --- a/tests/worker-task-abort.rs +++ b/tests/worker-task-abort.rs @@ -5,8 +5,8 @@ extern crate proxmox_backup; extern crate tokio; extern crate nix; -use proxmox::try_block; use proxmox::tools::fs::CreateOptions; +use proxmox_lang::try_block; use pbs_api_types::{Authid, UPID}; use pbs_tools::{task_log, task::WorkerTaskContext};