This commit is contained in:
Hubert 2021-07-15 06:45:49 +02:00
parent b76338f802
commit 7fbd18047e
1 changed files with 8 additions and 5 deletions

View File

@ -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>
gitust : web::Data<Gitust>,
auth : BasicAuth,
) -> io::Result<HttpResponse>{
//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<bool, std::io::Error>
{
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(