Compare commits
No commits in common. "5f89a9558787c4208e95277efd0379d630216433" and "b76338f8024d79e376b01d0abb78198c53743732" have entirely different histories.
5f89a95587
...
b76338f802
|
@ -18,4 +18,3 @@ env_logger = "0.8.4"
|
||||||
serde = "1.0.126"
|
serde = "1.0.126"
|
||||||
futures = "0.3.15"
|
futures = "0.3.15"
|
||||||
tokio = {version = "0.2.25", features = ["time", "process", "io-util"]}
|
tokio = {version = "0.2.25", features = ["time", "process", "io-util"]}
|
||||||
git2 = "0.13.20"
|
|
||||||
|
|
34
src/main.rs
34
src/main.rs
|
@ -35,7 +35,6 @@ use actix_web::client::PayloadError;
|
||||||
use crate::reader::ToStream;
|
use crate::reader::ToStream;
|
||||||
use crate::writer::Writer;
|
use crate::writer::Writer;
|
||||||
use crate::gitust::Gitust;
|
use crate::gitust::Gitust;
|
||||||
use git2::{Reference, Commit, Tree};
|
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "hello.html")]
|
#[template(path = "hello.html")]
|
||||||
|
@ -153,35 +152,14 @@ async fn git_main(
|
||||||
let owner = Owner { name : owner};
|
let owner = Owner { name : owner};
|
||||||
let repo = Repository {name : reponame, owner};
|
let repo = Repository {name : reponame, owner};
|
||||||
let user = User { name : "Hubert".to_string()};
|
let user = User { name : "Hubert".to_string()};
|
||||||
let repogit = match git2::Repository::open(format!("{}/{}/{}.git", &gitust.repo_root_path, &repo.owner.name, &repo.name)) {
|
|
||||||
Ok(repo) => repo,
|
|
||||||
Err(e) => panic!("failed to open: {}", e),
|
|
||||||
};
|
|
||||||
let head = match repogit.head() {
|
|
||||||
Ok(head) => head,
|
|
||||||
Err(e) => panic!("failed to get head: {}", e)
|
|
||||||
};
|
|
||||||
let commit = match head.peel_to_commit() {
|
|
||||||
Ok(commit) => commit,
|
|
||||||
Err(e) => panic!("failed to get commit: {}", e)
|
|
||||||
};
|
|
||||||
let tree = match commit.tree() {
|
|
||||||
Ok(tree) => tree,
|
|
||||||
Err(e) => panic!("failed to get tree: {}", e)
|
|
||||||
};
|
|
||||||
for entry in tree.iter() {
|
|
||||||
println!("{:?}", entry.name());
|
|
||||||
println!("{:?}", entry.kind());
|
|
||||||
}
|
|
||||||
GitMainTemplate { repo, browse : browse, root : path, user_opt : Some(user)}
|
GitMainTemplate { repo, browse : browse, root : path, user_opt : Some(user)}
|
||||||
}
|
}
|
||||||
//#[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, path)): web::Path<(String, String, String)>,
|
web::Path((owner, reponame)): web::Path<(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");
|
||||||
|
@ -190,12 +168,11 @@ 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, path));
|
cmd.env("PATH_INFO", format!("/{}/{}.git",owner, reponame));
|
||||||
cmd.env("REMOTE_USER", auth.user_id().to_string());
|
cmd.env("REMOTE_USER", "");
|
||||||
//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());
|
||||||
|
@ -297,7 +274,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("hubert") && user_password.eq(&Option::Some("hubert")) {
|
if user_id.eq("karl") && user_password.eq(&Option::Some("password")) {
|
||||||
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!"));
|
||||||
|
@ -337,7 +314,6 @@ 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