From 69c13a4411f6f20047c1bcc9cfeca8e296b0b4e8 Mon Sep 17 00:00:00 2001 From: Mewp Date: Fri, 12 Nov 2021 22:39:46 +0100 Subject: [PATCH] Taru can now pass a logged in user's name to a task --- Cargo.lock | 2 +- Cargo.nix | 7 +++---- Cargo.toml | 2 +- README.md | 4 +++- src/main.rs | 14 ++++++++++++-- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 747d9d6..ac5663b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1520,7 +1520,7 @@ dependencies = [ [[package]] name = "taru" -version = "0.4.2" +version = "0.4.3" dependencies = [ "actix-files", "actix-rt", diff --git a/Cargo.nix b/Cargo.nix index 732b0ab..dd54997 100644 --- a/Cargo.nix +++ b/Cargo.nix @@ -1,5 +1,5 @@ -# This file was @generated by crate2nix 0.10.0-alpha.1 with the command: +# This file was @generated by crate2nix 0.9.0 with the command: # "generate" # See https://github.com/kolloch/crate2nix for more info. @@ -4250,7 +4250,7 @@ rec { }; "taru" = rec { crateName = "taru"; - version = "0.4.2"; + version = "0.4.3"; edition = "2018"; crateBin = [ { name = "taru"; path = "src/main.rs"; } @@ -6547,5 +6547,4 @@ rec { # }; -} - +} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index b8c020e..de626bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "taru" -version = "0.4.2" +version = "0.4.3" authors = ["Mewp "] edition = "2018" diff --git a/README.md b/README.md index ef4d4ca..36272bf 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,9 @@ All endpoints that run tasks accept arguments as either parameters in the url qu Users ----- -If you define it, Taru will require users to authenticate by setting the X-User header to their username. Typically, this is done by using a reverse proxy, such as nginx, to authenticate using the desired method, then pass the result as X-User. +If you define it, Taru will require users to authenticate by setting the `X-User` header to their username. Typically, this is done by using a reverse proxy, such as nginx, to authenticate using the desired method, then pass the result as `X-User`. + +The value of the `X-User` header is always available as the `$taru_user` variable that you can pass as an argument to a task. Each use can has three kinds of permissions: diff --git a/src/main.rs b/src/main.rs index f211605..ceee25a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -148,8 +148,18 @@ async fn run_task(req: &HttpRequest, data: &web::Data>>, pa } let cmdline = task.command.iter().map(|segment| - if segment.starts_with("$") && args.contains_key(&segment[1..]) { - args.get(&segment[1..]).unwrap().clone() + if segment.starts_with("$") { + if args.contains_key(&segment[1..]) { + args.get(&segment[1..]).unwrap().clone() + } else if segment == "$taru_user" { + if let Some(Ok(login)) = req.headers().get("x-user").map(|h| h.to_str()) { + login.to_owned() + } else { + String::new() + } + } else { + segment.clone() + } } else { segment.clone() }