From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 01/10] api2/node/tasks: add check_job_store and use it
Date: Mon, 9 Nov 2020 16:01:21 +0100 [thread overview]
Message-ID: <20201109150130.4956-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20201109150130.4956-1-d.csapak@proxmox.com>
to easily check the store of a worker_id
this fixes the issue that one could not filter by type 'syncjob' and
datastore simultaneously
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/api2/node/tasks.rs | 47 ++++++++++++++++++++++++++++--------------
1 file changed, 32 insertions(+), 15 deletions(-)
diff --git a/src/api2/node/tasks.rs b/src/api2/node/tasks.rs
index 4e023fbf..3f06ec70 100644
--- a/src/api2/node/tasks.rs
+++ b/src/api2/node/tasks.rs
@@ -71,6 +71,36 @@ fn check_job_privs(auth_id: &Authid, user_info: &CachedUserInfo, upid: &UPID) ->
bail!("not a scheduled job task");
}
+// get the store out of the worker_id
+fn check_job_store(upid: &UPID, store: &str) -> bool {
+ match (upid.worker_type.as_str(), &upid.worker_id) {
+ (workertype, Some(workerid)) if workertype.starts_with("verif") => {
+ if let Some(captures) = VERIFICATION_JOB_WORKER_ID_REGEX.captures(&workerid) {
+ if let Some(jobstore) = captures.get(1) {
+ return store == jobstore.as_str();
+ }
+ } else {
+ return workerid == store;
+ }
+ }
+ ("syncjob", Some(workerid)) => {
+ if let Some(captures) = SYNC_JOB_WORKER_ID_REGEX.captures(&workerid) {
+ if let Some(local_store) = captures.get(3) {
+ return store == local_store.as_str();
+ }
+ }
+ }
+ ("prune", Some(workerid))
+ | ("backup", Some(workerid))
+ | ("garbage_collection", Some(workerid)) => {
+ return workerid == store || workerid.starts_with(&format!("{}:", store));
+ }
+ _ => {}
+ };
+
+ false
+}
+
fn check_task_access(auth_id: &Authid, upid: &UPID) -> Result<(), Error> {
let task_auth_id = &upid.auth_id;
if auth_id == task_auth_id
@@ -455,21 +485,8 @@ pub fn list_tasks(
}
if let Some(store) = store {
- // Note: useful to select all tasks spawned by proxmox-backup-client
- let worker_id = match &info.upid.worker_id {
- Some(w) => w,
- None => return None, // skip
- };
-
- if info.upid.worker_type == "backup" || info.upid.worker_type == "restore" ||
- info.upid.worker_type == "prune"
- {
- let prefix = format!("{}:", store);
- if !worker_id.starts_with(&prefix) { return None; }
- } else if info.upid.worker_type == "garbage_collection" {
- if worker_id != store { return None; }
- } else {
- return None; // skip
+ if !check_job_store(&info.upid, store) {
+ return None;
}
}
--
2.20.1
next prev parent reply other threads:[~2020-11-09 15:02 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-09 15:01 [pbs-devel] [PATCH proxmox-backup 00/10] add Datastore overview panel Dominik Csapak
2020-11-09 15:01 ` Dominik Csapak [this message]
2020-11-09 15:01 ` [pbs-devel] [PATCH proxmox-backup 02/10] ui: refactor render_estimate Dominik Csapak
2020-11-09 15:01 ` [pbs-devel] [PATCH proxmox-backup 03/10] ui: refactor render_size_usage to Utils Dominik Csapak
2020-11-09 15:01 ` [pbs-devel] [PATCH proxmox-backup 04/10] ui: Utils: add parse_datastore_worker_id Dominik Csapak
2020-11-09 15:01 ` [pbs-devel] [PATCH proxmox-backup 05/10] ui: make Sync/VerifyView and Edit usable without datastore Dominik Csapak
2020-11-09 15:01 ` [pbs-devel] [PATCH proxmox-backup 06/10] ui: TaskSummary: move state/types/titles out of the controller Dominik Csapak
2020-11-09 15:01 ` [pbs-devel] [PATCH proxmox-backup 07/10] ui: TaskSummary: add subPanelModal and datastore parameters Dominik Csapak
2020-11-09 15:01 ` [pbs-devel] [PATCH proxmox-backup 08/10] ui: TaskSummary: handle less defined parameters of tasks Dominik Csapak
2020-11-09 15:01 ` [pbs-devel] [PATCH proxmox-backup 09/10] ui: add Panels necessary for Datastores Overview Dominik Csapak
2020-11-09 15:01 ` [pbs-devel] [PATCH proxmox-backup 10/10] ui: make Datastore clickable again Dominik Csapak
2020-11-09 17:55 ` [pbs-devel] applied series: [PATCH proxmox-backup 00/10] add Datastore overview panel Thomas Lamprecht
2020-11-09 18:28 ` Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201109150130.4956-2-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox