This commit is contained in:
Hubert 2021-07-21 06:53:03 +02:00
parent 381347e66a
commit 90bc6d6d4f
5 changed files with 18 additions and 11 deletions

View File

@ -12,11 +12,16 @@ impl Error {
impl From<git2::Error> for Error {
fn from(giterr: git2::Error) -> Self {
// panic!()
Error::BadGateway(format!("{}", giterr))
}
}
impl From<std::io::Error> for Error {
fn from(ioerr: std::io::Error) -> Self {
Error::BadGateway(format!("{}", ioerr))
}
}
impl From<Error> for actix_web::error::Error {
fn from(e: Error) -> Self {
match e {

View File

@ -1,3 +1,4 @@
pub struct Gitust {
pub repo_root_path : String,
pub session_key : String,
}

View File

@ -14,6 +14,7 @@ use tokio::process::{Child, Command};
use crate::gitust::Gitust;
use crate::reader::ToStream;
use crate::error;
//#[get("/git/{owner}/{repo}.git/{path:.*}")]
pub async fn git_proto(
@ -22,7 +23,7 @@ pub async fn git_proto(
mut req: HttpRequest,
gitust : web::Data<Gitust>,
auth : BasicAuth,
) -> io::Result<HttpResponse>{
) -> Result<HttpResponse, error::Error>{
//println!("enter git_proto");
let mut cmd = Command::new("git");
cmd.arg("http-backend");

View File

@ -155,13 +155,16 @@ async fn main() -> std::io::Result<()> {
env_logger::from_env(Env::default().default_filter_or("info")).init();
HttpServer::new(|| {
let auth = HttpAuthentication::basic(basic_auth_validator);
let gitust = Gitust {
repo_root_path: "/home/hubert/gitust".to_string(),
session_key: "oWe0ait9bi2Ohyiod2eeXirao1Oochie".to_string(),
};
let session_key = (&gitust.session_key).as_bytes();
App::new()
.data(Gitust {
repo_root_path: "/home/hubert/gitust".to_string(),
})
.wrap(Logger::default())
// .wrap(Logger::new("%a %{User-Agent}i"))
.wrap(CookieSession::signed(&[0; 32]).secure(false))
.wrap(CookieSession::signed(session_key).secure(false))
.data(gitust)
.service(hello)
.service(echo)
.service(hello_test)

View File

@ -1,9 +1,6 @@
use actix_web_httpauth::extractors::basic::BasicAuth;
use std::borrow::Cow;
pub fn check_user(auth : BasicAuth) -> bool {
match auth.password() {
None => {false}
Some(pwd) => {pwd.to_string().eq(&(auth.user_id().to_string() + "pwd"))}
}
pub fn check_user(name : String, pwd : String) -> bool {
pwd.eq(&(name + "pwd")) //stub!
}