validator for git proto

This commit is contained in:
Hubert 2021-07-21 13:33:12 +02:00
parent aa131d009f
commit 6d87adb2e6
3 changed files with 15 additions and 4 deletions

View File

@ -15,15 +15,18 @@ use tokio::process::{Child, Command};
use crate::gitust::Gitust;
use crate::reader::ToStream;
use crate::error;
use crate::webutils::auth;
//#[get("/git/{owner}/{repo}.git/{path:.*}")]
pub async fn git_proto(
pub async fn git_proto<T : auth::AuthValidator>(
mut payload : web::Payload,
web::Path((owner, reponame, path)): web::Path<(String, String, String)>,
mut req: HttpRequest,
gitust : web::Data<Gitust>,
auth : BasicAuth,
authenticator : web::Data<T>,
auth : Option<BasicAuth>,
) -> 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");
let mut cmd = Command::new("git");
cmd.arg("http-backend");
@ -32,7 +35,7 @@ pub async fn git_proto(
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, path));
cmd.env("REMOTE_USER", auth.user_id().to_string());
cmd.env("REMOTE_USER", user.get_name());
//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));

View File

@ -34,6 +34,7 @@ use gitutils::gitfile::GitFile;
use gitutils::gitproto;
use gitutils::gitrepo::GitRepo;
use web::repo;
use webutils::auth;
use crate::git::GitBrowseEntry;
use crate::gitust::Gitust;
@ -165,6 +166,7 @@ async fn main() -> std::io::Result<()> {
// .wrap(Logger::new("%a %{User-Agent}i"))
.wrap(CookieSession::signed(session_key).secure(false))
.data(gitust)
.data(auth::TestValidator)
.service(hello)
.service(echo)
.service(hello_test)
@ -186,7 +188,7 @@ async fn main() -> std::io::Result<()> {
)
.service(
webx::resource("/git/{user}/{repo}.git/{path:.*}")
.route(webx::route().to(gitproto::git_proto))
.route(webx::route().to(gitproto::git_proto::<auth::TestValidator>))
)
.service(
Files::new("/static", "static")

View File

@ -31,3 +31,9 @@ impl AuthValidator for TestValidator {
}
pub struct User(String);
impl User {
pub fn get_name(&self) -> String {
self.0.clone()
}
}