Compare commits
No commits in common. "6d87adb2e6dae1950730c0fcdcb1b244513c120a" and "9af4fa56e174de927c43cdf326db1e52d2e44104" have entirely different histories.
6d87adb2e6
...
9af4fa56e1
|
@ -15,18 +15,15 @@ use tokio::process::{Child, Command};
|
||||||
use crate::gitust::Gitust;
|
use crate::gitust::Gitust;
|
||||||
use crate::reader::ToStream;
|
use crate::reader::ToStream;
|
||||||
use crate::error;
|
use crate::error;
|
||||||
use crate::webutils::auth;
|
|
||||||
|
|
||||||
//#[get("/git/{owner}/{repo}.git/{path:.*}")]
|
//#[get("/git/{owner}/{repo}.git/{path:.*}")]
|
||||||
pub async fn git_proto<T : auth::AuthValidator>(
|
pub 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, path)): web::Path<(String, String, String)>,
|
||||||
mut req: HttpRequest,
|
mut req: HttpRequest,
|
||||||
gitust : web::Data<Gitust>,
|
gitust : web::Data<Gitust>,
|
||||||
authenticator : web::Data<T>,
|
auth : BasicAuth,
|
||||||
auth : Option<BasicAuth>,
|
|
||||||
) -> Result<HttpResponse, error::Error>{
|
) -> Result<HttpResponse, error::Error>{
|
||||||
let user = auth.and_then(|a| authenticator.check_basic(&a)).ok_or(error::Error::Unauthorized("git_proto".to_string()))?;
|
|
||||||
//println!("enter git_proto");
|
//println!("enter git_proto");
|
||||||
let mut cmd = Command::new("git");
|
let mut cmd = Command::new("git");
|
||||||
cmd.arg("http-backend");
|
cmd.arg("http-backend");
|
||||||
|
@ -35,7 +32,7 @@ pub async fn git_proto<T : auth::AuthValidator>(
|
||||||
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, path));
|
||||||
cmd.env("REMOTE_USER", user.get_name());
|
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));
|
||||||
|
|
|
@ -34,7 +34,6 @@ use gitutils::gitfile::GitFile;
|
||||||
use gitutils::gitproto;
|
use gitutils::gitproto;
|
||||||
use gitutils::gitrepo::GitRepo;
|
use gitutils::gitrepo::GitRepo;
|
||||||
use web::repo;
|
use web::repo;
|
||||||
use webutils::auth;
|
|
||||||
|
|
||||||
use crate::git::GitBrowseEntry;
|
use crate::git::GitBrowseEntry;
|
||||||
use crate::gitust::Gitust;
|
use crate::gitust::Gitust;
|
||||||
|
@ -166,7 +165,6 @@ async fn main() -> std::io::Result<()> {
|
||||||
// .wrap(Logger::new("%a %{User-Agent}i"))
|
// .wrap(Logger::new("%a %{User-Agent}i"))
|
||||||
.wrap(CookieSession::signed(session_key).secure(false))
|
.wrap(CookieSession::signed(session_key).secure(false))
|
||||||
.data(gitust)
|
.data(gitust)
|
||||||
.data(auth::TestValidator)
|
|
||||||
.service(hello)
|
.service(hello)
|
||||||
.service(echo)
|
.service(echo)
|
||||||
.service(hello_test)
|
.service(hello_test)
|
||||||
|
@ -188,7 +186,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
webx::resource("/git/{user}/{repo}.git/{path:.*}")
|
webx::resource("/git/{user}/{repo}.git/{path:.*}")
|
||||||
.route(webx::route().to(gitproto::git_proto::<auth::TestValidator>))
|
.route(webx::route().to(gitproto::git_proto))
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
Files::new("/static", "static")
|
Files::new("/static", "static")
|
||||||
|
|
|
@ -1,19 +1,13 @@
|
||||||
use actix_session::Session;
|
|
||||||
use actix_web::Error;
|
|
||||||
use actix_web_httpauth::extractors::basic::BasicAuth;
|
use actix_web_httpauth::extractors::basic::BasicAuth;
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
pub trait AuthValidator {
|
pub trait AuthValidator {
|
||||||
fn check_user(&self, name : &String, pwd : &String) -> Option<User>;
|
fn check_user(&self, name : &String, pwd : &String) -> bool;
|
||||||
|
|
||||||
fn check_basic(&self, basic : &BasicAuth) -> Option<User> {
|
fn check_basic(&self, basic : BasicAuth) -> bool {
|
||||||
basic.password().and_then(|pwd| self.check_user(&basic.user_id().to_string(), &pwd.to_string()))
|
match basic.password() {
|
||||||
}
|
None => {false}
|
||||||
|
Some(pwd) => {self.check_user(&basic.user_id().to_string(), &pwd.to_string())}
|
||||||
fn check_session(&self, session : &Session) -> Option<User> {
|
|
||||||
let result = session.get::<String>("user");
|
|
||||||
match result {
|
|
||||||
Ok(username) => {username.map(|u| User(u))}
|
|
||||||
Err(e) => {None}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,19 +15,7 @@ pub trait AuthValidator {
|
||||||
pub struct TestValidator;
|
pub struct TestValidator;
|
||||||
|
|
||||||
impl AuthValidator for TestValidator {
|
impl AuthValidator for TestValidator {
|
||||||
fn check_user(&self, name: &String, pwd: &String) -> Option<User> {
|
fn check_user(&self, name: &String, pwd: &String) -> bool {
|
||||||
if pwd.eq(&(name.clone() + "pwd")) {
|
pwd.eq(&(name.clone() + "pwd")) //stub!
|
||||||
Some(User(name.clone()))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct User(String);
|
|
||||||
|
|
||||||
impl User {
|
|
||||||
pub fn get_name(&self) -> String {
|
|
||||||
self.0.clone()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,2 +1 @@
|
||||||
pub mod auth;
|
pub mod auth;
|
||||||
pub mod user;
|
|
Loading…
Reference in New Issue