]> git.proxmox.com Git - proxmox-backup.git/commitdiff
move some API return types to pbs-api-types
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 26 Aug 2021 11:17:55 +0000 (13:17 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 30 Aug 2021 09:39:01 +0000 (11:39 +0200)
they'll be required by the api client

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
pbs-api-types/src/lib.rs
src/api2/admin/datastore.rs
src/api2/node/tasks.rs
src/api2/types/mod.rs
src/server/worker_task.rs

index 576099eb5ca289a1d9c27d94493f991792129d6c..1c9063bff0493d6b71af5e1f00428f6299ea45e7 100644 (file)
@@ -3,7 +3,10 @@
 use serde::{Deserialize, Serialize};
 
 use proxmox::api::api;
-use proxmox::api::schema::{ApiStringFormat, EnumEntry, IntegerSchema, Schema, StringSchema};
+use proxmox::api::schema::{
+    ApiStringFormat, ApiType, ArraySchema, EnumEntry, IntegerSchema, ReturnType, Schema,
+    StringSchema,
+};
 use proxmox::const_regex;
 use proxmox::{IPRE, IPRE_BRACKET, IPV4OCTET, IPV4RE, IPV6H16, IPV6LS32, IPV6RE};
 
@@ -564,3 +567,74 @@ impl std::convert::TryFrom<openssl::rsa::Rsa<openssl::pkey::Public>> for RsaPubK
         })
     }
 }
+
+#[api(
+    properties: {
+        upid: { schema: UPID::API_SCHEMA },
+    },
+)]
+#[derive(Serialize, Deserialize)]
+/// Task properties.
+pub struct TaskListItem {
+    pub upid: String,
+    /// The node name where the task is running on.
+    pub node: String,
+    /// The Unix PID
+    pub pid: i64,
+    /// The task start time (Epoch)
+    pub pstart: u64,
+    /// The task start time (Epoch)
+    pub starttime: i64,
+    /// Worker type (arbitrary ASCII string)
+    pub worker_type: String,
+    /// Worker ID (arbitrary ASCII string)
+    pub worker_id: Option<String>,
+    /// The authenticated entity who started the task
+    pub user: Authid,
+    /// The task end time (Epoch)
+    #[serde(skip_serializing_if="Option::is_none")]
+    pub endtime: Option<i64>,
+    /// Task end status
+    #[serde(skip_serializing_if="Option::is_none")]
+    pub status: Option<String>,
+}
+
+pub const ADMIN_DATASTORE_LIST_SNAPSHOTS_RETURN_TYPE: ReturnType = ReturnType {
+    optional: false,
+    schema: &ArraySchema::new(
+        "Returns the list of snapshots.",
+        &SnapshotListItem::API_SCHEMA,
+    ).schema(),
+};
+
+pub const ADMIN_DATASTORE_LIST_SNAPSHOT_FILES_RETURN_TYPE: ReturnType = ReturnType {
+    optional: false,
+    schema: &ArraySchema::new(
+        "Returns the list of archive files inside a backup snapshots.",
+        &BackupContent::API_SCHEMA,
+    ).schema(),
+};
+
+pub const ADMIN_DATASTORE_LIST_GROUPS_RETURN_TYPE: ReturnType = ReturnType {
+    optional: false,
+    schema: &ArraySchema::new(
+        "Returns the list of backup groups.",
+        &GroupListItem::API_SCHEMA,
+    ).schema(),
+};
+
+pub const ADMIN_DATASTORE_PRUNE_RETURN_TYPE: ReturnType = ReturnType {
+    optional: false,
+    schema: &ArraySchema::new(
+        "Returns the list of snapshots and a flag indicating if there are kept or removed.",
+        &PruneListItem::API_SCHEMA,
+    ).schema(),
+};
+
+pub const NODE_TASKS_LIST_TASKS_RETURN_TYPE: ReturnType = ReturnType {
+    optional: false,
+    schema: &ArraySchema::new(
+        "A list of tasks.",
+        &TaskListItem::API_SCHEMA,
+    ).schema(),
+};
index f3c52413210d773e7e3f7e8c6bc233d83921b6b2..0998d659f421c34d78150f73587c121452e43a9a 100644 (file)
@@ -134,13 +134,7 @@ fn get_all_snapshot_files(
             },
         },
     },
-    returns: {
-        type: Array,
-        description: "Returns the list of backup groups.",
-        items: {
-            type: GroupListItem,
-        }
-    },
+    returns: pbs_api_types::ADMIN_DATASTORE_LIST_GROUPS_RETURN_TYPE,
     access: {
         permission: &Permission::Privilege(
             &["datastore", "{store}"],
@@ -282,13 +276,7 @@ pub fn delete_group(
             },
         },
     },
-    returns: {
-        type: Array,
-        description: "Returns the list of archive files inside a backup snapshots.",
-        items: {
-            type: BackupContent,
-        }
-    },
+    returns: pbs_api_types::ADMIN_DATASTORE_LIST_SNAPSHOT_FILES_RETURN_TYPE,
     access: {
         permission: &Permission::Privilege(
             &["datastore", "{store}"],
@@ -382,13 +370,7 @@ pub fn delete_snapshot(
             },
         },
     },
-    returns: {
-        type: Array,
-        description: "Returns the list of snapshots.",
-        items: {
-            type: SnapshotListItem,
-        }
-    },
+    returns: pbs_api_types::ADMIN_DATASTORE_LIST_SNAPSHOTS_RETURN_TYPE,
     access: {
         permission: &Permission::Privilege(
             &["datastore", "{store}"],
@@ -809,13 +791,7 @@ pub fn verify(
             },
         },
     },
-    returns: {
-        type: Array,
-        description: "Returns the list of snapshots and a flag indicating if there are kept or removed.",
-        items: {
-            type: PruneListItem,
-        },
-    },
+    returns: pbs_api_types::ADMIN_DATASTORE_PRUNE_RETURN_TYPE,
     access: {
         permission: &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_MODIFY | PRIV_DATASTORE_PRUNE, true),
     },
index 326dbf7a4800ee9b9e11708b67cfb07df468657a..89665c68c83b93117ef9fd94f9c17149f46a250a 100644 (file)
@@ -412,11 +412,7 @@ fn stop_task(
             },
         },
     },
-    returns: {
-        description: "A list of tasks.",
-        type: Array,
-        items: { type: TaskListItem },
-    },
+    returns: pbs_api_types::NODE_TASKS_LIST_TASKS_RETURN_TYPE,
     access: {
         description: "Users can only see their own tasks, unless they have Sys.Audit on /system/tasks.",
         permission: &Permission::Anybody,
index bd3c7ac5e583748bd177a655d6481ffd94884265..2b5e3f714ffc411920269486c574c7cdf956732c 100644 (file)
@@ -379,59 +379,6 @@ pub struct DataStoreStatus {
     pub counts: Option<Counts>,
 }
 
-#[api(
-    properties: {
-        upid: { schema: UPID_SCHEMA },
-        user: { type: Authid },
-    },
-)]
-#[derive(Serialize, Deserialize)]
-/// Task properties.
-pub struct TaskListItem {
-    pub upid: String,
-    /// The node name where the task is running on.
-    pub node: String,
-    /// The Unix PID
-    pub pid: i64,
-    /// The task start time (Epoch)
-    pub pstart: u64,
-    /// The task start time (Epoch)
-    pub starttime: i64,
-    /// Worker type (arbitrary ASCII string)
-    pub worker_type: String,
-    /// Worker ID (arbitrary ASCII string)
-    pub worker_id: Option<String>,
-    /// The authenticated entity who started the task
-    pub user: Authid,
-    /// The task end time (Epoch)
-    #[serde(skip_serializing_if="Option::is_none")]
-    pub endtime: Option<i64>,
-    /// Task end status
-    #[serde(skip_serializing_if="Option::is_none")]
-    pub status: Option<String>,
-}
-
-impl From<crate::server::TaskListInfo> for TaskListItem {
-    fn from(info: crate::server::TaskListInfo) -> Self {
-        let (endtime, status) = info
-            .state
-            .map_or_else(|| (None, None), |a| (Some(a.endtime()), Some(a.to_string())));
-
-        TaskListItem {
-            upid: info.upid_str,
-            node: "localhost".to_string(),
-            pid: info.upid.pid as i64,
-            pstart: info.upid.pstart,
-            starttime: info.upid.starttime,
-            worker_type: info.upid.worker_type,
-            worker_id: info.upid.worker_id,
-            user: info.upid.auth_id,
-            endtime,
-            status,
-        }
-    }
-}
-
 #[api()]
 #[derive(Eq, PartialEq, Debug, Serialize, Deserialize)]
 #[serde(rename_all = "lowercase")]
index be9a479489aad41628f2b25420c68de8adfffe02..075aaa6c2a988b52d64678faed055c7d66379bdc 100644 (file)
@@ -314,6 +314,27 @@ pub struct TaskListInfo {
     pub state: Option<TaskState>, // endtime, status
 }
 
+impl Into<pbs_api_types::TaskListItem> for TaskListInfo {
+    fn into(self) -> pbs_api_types::TaskListItem {
+        let (endtime, status) = self
+            .state
+            .map_or_else(|| (None, None), |a| (Some(a.endtime()), Some(a.to_string())));
+
+        pbs_api_types::TaskListItem {
+            upid: self.upid_str,
+            node: "localhost".to_string(),
+            pid: self.upid.pid as i64,
+            pstart: self.upid.pstart,
+            starttime: self.upid.starttime,
+            worker_type: self.upid.worker_type,
+            worker_id: self.upid.worker_id,
+            user: self.upid.auth_id,
+            endtime,
+            status,
+        }
+    }
+}
+
 fn lock_task_list_files(exclusive: bool) -> Result<BackupLockGuard, Error> {
     open_backup_lockfile(PROXMOX_BACKUP_TASK_LOCK_FN, None, exclusive)
 }