From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pdm-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 535A11FF16E for <inbox@lore.proxmox.com>; Mon, 20 Jan 2025 10:30:47 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 50B791630E; Mon, 20 Jan 2025 10:30:46 +0100 (CET) From: Dominik Csapak <d.csapak@proxmox.com> To: pdm-devel@lists.proxmox.com Date: Mon, 20 Jan 2025 10:29:58 +0100 Message-Id: <20250120093006.927014-9-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250120093006.927014-1-d.csapak@proxmox.com> References: <20250120093006.927014-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -1.232 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_DBL_SPAM 2.5 Contains a spam URL listed in the Spamhaus DBL blocklist [tasks.rs] Subject: [pdm-devel] [PATCH datacenter-manager 1/9] server: factor out task filters into `TaskFilters` type X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion <pdm-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pdm-devel>, <mailto:pdm-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pdm-devel/> List-Post: <mailto:pdm-devel@lists.proxmox.com> List-Help: <mailto:pdm-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel>, <mailto:pdm-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox Datacenter Manager development discussion <pdm-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" <pdm-devel-bounces@lists.proxmox.com> so we can reuse it Signed-off-by: Dominik Csapak <d.csapak@proxmox.com> --- lib/pdm-api-types/src/lib.rs | 81 ++++++++++++++++++++++++++++++++++- server/src/api/nodes/tasks.rs | 80 ++++++++-------------------------- 2 files changed, 98 insertions(+), 63 deletions(-) diff --git a/lib/pdm-api-types/src/lib.rs b/lib/pdm-api-types/src/lib.rs index bf312cc..3844907 100644 --- a/lib/pdm-api-types/src/lib.rs +++ b/lib/pdm-api-types/src/lib.rs @@ -219,7 +219,7 @@ pub enum NodePowerCommand { #[api] /// The state of a task. -#[derive(Eq, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum TaskStateType { /// Ok @@ -418,3 +418,82 @@ impl fmt::Display for RemoteUpid { serde_plain::derive_deserialize_from_fromstr!(RemoteUpid, "valid remote upid"); serde_plain::derive_serialize_from_display!(RemoteUpid); + +fn limit_default() -> u64 { + 50 +} + +#[api( + properties: { + start: { + type: u64, + description: "List tasks beginning from this offset.", + default: 0, + optional: true, + }, + limit: { + type: u64, + description: "Only list this amount of tasks. (0 means no limit)", + default: 50, + optional: true, + }, + running: { + type: bool, + description: "Only list running tasks.", + optional: true, + default: false, + }, + errors: { + type: bool, + description: "Only list erroneous tasks.", + optional:true, + default: false, + }, + userfilter: { + optional: true, + type: String, + description: "Only list tasks from this user.", + }, + since: { + type: i64, + description: "Only list tasks since this UNIX epoch.", + optional: true, + }, + until: { + type: i64, + description: "Only list tasks until this UNIX epoch.", + optional: true, + }, + typefilter: { + optional: true, + type: String, + description: "Only list tasks whose type contains this.", + }, + statusfilter: { + optional: true, + type: Array, + description: "Only list tasks which have any one of the listed status.", + items: { + type: TaskStateType, + }, + }, + } +)] +/// Task filter settings +#[derive(Deserialize, Serialize, Clone, PartialEq, Eq)] +#[serde(rename_all = "kebab-case")] +pub struct TaskFilters { + #[serde(default)] + pub start: u64, + #[serde(default = "limit_default")] + pub limit: u64, + #[serde(default)] + pub errors: bool, + #[serde(default)] + pub running: bool, + pub userfilter: Option<String>, + pub since: Option<i64>, + pub until: Option<i64>, + pub typefilter: Option<String>, + pub statusfilter: Option<Vec<TaskStateType>>, +} diff --git a/server/src/api/nodes/tasks.rs b/server/src/api/nodes/tasks.rs index 37fe0d8..13a713a 100644 --- a/server/src/api/nodes/tasks.rs +++ b/server/src/api/nodes/tasks.rs @@ -12,8 +12,8 @@ use proxmox_schema::{api, Schema}; use proxmox_sortable_macro::sortable; use pdm_api_types::{ - Authid, TaskListItem, TaskStateType, Tokenname, Userid, NODE_SCHEMA, PRIV_SYS_AUDIT, - PRIV_SYS_MODIFY, UPID, UPID_SCHEMA, + Authid, TaskFilters, TaskListItem, TaskStateType, Tokenname, Userid, NODE_SCHEMA, + PRIV_SYS_AUDIT, PRIV_SYS_MODIFY, UPID, UPID_SCHEMA, }; pub const ROUTER: Router = Router::new() @@ -57,57 +57,9 @@ fn check_task_access(auth_id: &Authid, upid: &UPID) -> Result<(), Error> { node: { schema: NODE_SCHEMA }, - start: { - type: u64, - description: "List tasks beginning from this offset.", - default: 0, - optional: true, - }, - limit: { - type: u64, - description: "Only list this amount of tasks. (0 means no limit)", - default: 50, - optional: true, - }, - running: { - type: bool, - description: "Only list running tasks.", - optional: true, - default: false, - }, - errors: { - type: bool, - description: "Only list erroneous tasks.", - optional:true, - default: false, - }, - userfilter: { - optional: true, - type: String, - description: "Only list tasks from this user.", - }, - since: { - type: i64, - description: "Only list tasks since this UNIX epoch.", - optional: true, - }, - until: { - type: i64, - description: "Only list tasks until this UNIX epoch.", - optional: true, - }, - typefilter: { - optional: true, - type: String, - description: "Only list tasks whose type contains this.", - }, - statusfilter: { - optional: true, - type: Array, - description: "Only list tasks which have any one of the listed status.", - items: { - type: TaskStateType, - }, + filters: { + type: TaskFilters, + flatten: true, }, }, }, @@ -120,17 +72,21 @@ fn check_task_access(auth_id: &Authid, upid: &UPID) -> Result<(), Error> { /// List tasks. #[allow(clippy::too_many_arguments)] pub fn list_tasks( - start: u64, - limit: u64, - errors: bool, - running: bool, - userfilter: Option<String>, - since: Option<i64>, - until: Option<i64>, - typefilter: Option<String>, - statusfilter: Option<Vec<TaskStateType>>, + filters: TaskFilters, rpcenv: &mut dyn RpcEnvironment, ) -> Result<Vec<TaskListItem>, Error> { + let TaskFilters { + start, + limit, + errors, + running, + userfilter, + since, + until, + typefilter, + statusfilter, + } = filters; + let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let user_info = CachedUserInfo::new()?; let user_privs = user_info.lookup_privs(&auth_id, &["system", "tasks"]); -- 2.39.5 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel