Compare commits
3 Commits
b76338f802
...
5f89a95587
Author | SHA1 | Date |
---|---|---|
Hubert | 5f89a95587 | |
Hubert | 8a0b525649 | |
Hubert | 7fbd18047e |
|
@ -18,3 +18,4 @@ env_logger = "0.8.4"
|
|||
serde = "1.0.126"
|
||||
futures = "0.3.15"
|
||||
tokio = {version = "0.2.25", features = ["time", "process", "io-util"]}
|
||||
git2 = "0.13.20"
|
||||
|
|
34
src/main.rs
34
src/main.rs
|
@ -35,6 +35,7 @@ use actix_web::client::PayloadError;
|
|||
use crate::reader::ToStream;
|
||||
use crate::writer::Writer;
|
||||
use crate::gitust::Gitust;
|
||||
use git2::{Reference, Commit, Tree};
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "hello.html")]
|
||||
|
@ -152,14 +153,35 @@ async fn git_main(
|
|||
let owner = Owner { name : owner};
|
||||
let repo = Repository {name : reponame, owner};
|
||||
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)}
|
||||
}
|
||||
//#[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 +190,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 +297,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 +337,7 @@ async fn main() -> std::io::Result<()> {
|
|||
)
|
||||
.service(
|
||||
web::resource("/git/{user}/{repo}.git/{path:.*}")
|
||||
// .wrap(auth)
|
||||
.route(web::route().to(git_proto))
|
||||
)
|
||||
.service(
|
||||
|
|
Loading…
Reference in New Issue