From 7fbd18047e776441f0110736e358f473adb7acda Mon Sep 17 00:00:00 2001 From: Hubert Date: Thu, 15 Jul 2021 06:45:49 +0200 Subject: [PATCH] save --- src/main.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index e80eaf3..dcc3ff4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -157,9 +157,10 @@ async fn git_main( //#[get("/git/{owner}/{repo}.git/{path:.*}")] async fn git_proto( mut payload : web::Payload, - web::Path((owner, reponame)): web::Path<(String, String)>, + web::Path((owner, reponame, path)): web::Path<(String, String, String)>, mut req: HttpRequest, - gitust : web::Data + gitust : web::Data, + auth : BasicAuth, ) -> io::Result{ //println!("enter git_proto"); let mut cmd = Command::new("git"); @@ -168,11 +169,12 @@ async fn git_proto( // Required environment variables cmd.env("REQUEST_METHOD", req.method().as_str()); cmd.env("GIT_PROJECT_ROOT", &gitust.repo_root_path); - cmd.env("PATH_INFO", format!("/{}/{}.git",owner, reponame)); - cmd.env("REMOTE_USER", ""); + cmd.env("PATH_INFO", format!("/{}/{}.git/{}",owner, reponame, path)); + cmd.env("REMOTE_USER", auth.user_id().to_string()); //cmd.env("REMOTE_ADDR", req.remote_addr().to_string()); cmd.env("QUERY_STRING", req.query_string()); cmd.env("CONTENT_TYPE", header(&req, header::CONTENT_TYPE)); + cmd.env("GIT_HTTP_EXPORT_ALL", ""); cmd.stderr(Stdio::inherit()) .stdout(Stdio::piped()) .stdin(Stdio::piped()); @@ -274,7 +276,7 @@ async fn basic_auth_validator(req: ServiceRequest, credentials: BasicAuth) -> Re fn validate_credentials(user_id: &str, user_password: Option<&str>) -> Result { - if user_id.eq("karl") && user_password.eq(&Option::Some("password")) { + if user_id.eq("hubert") && user_password.eq(&Option::Some("hubert")) { return Ok(true); } return Err(std::io::Error::new(std::io::ErrorKind::Other, "Authentication failed!")); @@ -314,6 +316,7 @@ async fn main() -> std::io::Result<()> { ) .service( web::resource("/git/{user}/{repo}.git/{path:.*}") + // .wrap(auth) .route(web::route().to(git_proto)) ) .service(