Skip to content

Commit

Permalink
Taru can now pass a logged in user's name to a task
Browse files Browse the repository at this point in the history
  • Loading branch information
Mewp committed Nov 12, 2021
1 parent 6ebf808 commit 69c13a4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Cargo.nix
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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"; }
Expand Down Expand Up @@ -6547,5 +6547,4 @@ rec {
#

};
}

}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "taru"
version = "0.4.2"
version = "0.4.3"
authors = ["Mewp <[email protected]>"]
edition = "2018"

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
14 changes: 12 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,18 @@ async fn run_task(req: &HttpRequest, data: &web::Data<Arc<RwLock<AppState>>>, 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()
}
Expand Down

0 comments on commit 69c13a4

Please sign in to comment.