save
This commit is contained in:
parent
b76338f802
commit
7fbd18047e
13
src/main.rs
13
src/main.rs
|
@ -157,9 +157,10 @@ async fn git_main(
|
||||||
//#[get("/git/{owner}/{repo}.git/{path:.*}")]
|
//#[get("/git/{owner}/{repo}.git/{path:.*}")]
|
||||||
async fn git_proto(
|
async fn git_proto(
|
||||||
mut payload : web::Payload,
|
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,
|
mut req: HttpRequest,
|
||||||
gitust : web::Data<Gitust>
|
gitust : web::Data<Gitust>,
|
||||||
|
auth : BasicAuth,
|
||||||
) -> io::Result<HttpResponse>{
|
) -> io::Result<HttpResponse>{
|
||||||
//println!("enter git_proto");
|
//println!("enter git_proto");
|
||||||
let mut cmd = Command::new("git");
|
let mut cmd = Command::new("git");
|
||||||
|
@ -168,11 +169,12 @@ async fn git_proto(
|
||||||
// Required environment variables
|
// Required environment variables
|
||||||
cmd.env("REQUEST_METHOD", req.method().as_str());
|
cmd.env("REQUEST_METHOD", req.method().as_str());
|
||||||
cmd.env("GIT_PROJECT_ROOT", &gitust.repo_root_path);
|
cmd.env("GIT_PROJECT_ROOT", &gitust.repo_root_path);
|
||||||
cmd.env("PATH_INFO", format!("/{}/{}.git",owner, reponame));
|
cmd.env("PATH_INFO", format!("/{}/{}.git/{}",owner, reponame, path));
|
||||||
cmd.env("REMOTE_USER", "");
|
cmd.env("REMOTE_USER", auth.user_id().to_string());
|
||||||
//cmd.env("REMOTE_ADDR", req.remote_addr().to_string());
|
//cmd.env("REMOTE_ADDR", req.remote_addr().to_string());
|
||||||
cmd.env("QUERY_STRING", req.query_string());
|
cmd.env("QUERY_STRING", req.query_string());
|
||||||
cmd.env("CONTENT_TYPE", header(&req, header::CONTENT_TYPE));
|
cmd.env("CONTENT_TYPE", header(&req, header::CONTENT_TYPE));
|
||||||
|
cmd.env("GIT_HTTP_EXPORT_ALL", "");
|
||||||
cmd.stderr(Stdio::inherit())
|
cmd.stderr(Stdio::inherit())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stdin(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>
|
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 Ok(true);
|
||||||
}
|
}
|
||||||
return Err(std::io::Error::new(std::io::ErrorKind::Other, "Authentication failed!"));
|
return Err(std::io::Error::new(std::io::ErrorKind::Other, "Authentication failed!"));
|
||||||
|
@ -314,6 +316,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::resource("/git/{user}/{repo}.git/{path:.*}")
|
web::resource("/git/{user}/{repo}.git/{path:.*}")
|
||||||
|
// .wrap(auth)
|
||||||
.route(web::route().to(git_proto))
|
.route(web::route().to(git_proto))
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
|
|
Loading…
Reference in New Issue