diff --git a/src/error.rs b/src/error.rs index 9abf9f0..169d99f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -12,11 +12,16 @@ impl Error { impl From for Error { fn from(giterr: git2::Error) -> Self { - // panic!() Error::BadGateway(format!("{}", giterr)) } } +impl From for Error { + fn from(ioerr: std::io::Error) -> Self { + Error::BadGateway(format!("{}", ioerr)) + } +} + impl From for actix_web::error::Error { fn from(e: Error) -> Self { match e { diff --git a/src/gitust.rs b/src/gitust.rs index b19b713..7d22eb8 100644 --- a/src/gitust.rs +++ b/src/gitust.rs @@ -1,3 +1,4 @@ pub struct Gitust { pub repo_root_path : String, + pub session_key : String, } \ No newline at end of file diff --git a/src/gitutils/gitproto.rs b/src/gitutils/gitproto.rs index 6f77ee7..2e9bf22 100644 --- a/src/gitutils/gitproto.rs +++ b/src/gitutils/gitproto.rs @@ -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, auth : BasicAuth, -) -> io::Result{ +) -> Result{ //println!("enter git_proto"); let mut cmd = Command::new("git"); cmd.arg("http-backend"); diff --git a/src/main.rs b/src/main.rs index 84052b6..c7d62df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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) diff --git a/src/webutils/auth.rs b/src/webutils/auth.rs index d185f19..b918f1e 100644 --- a/src/webutils/auth.rs +++ b/src/webutils/auth.rs @@ -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! } \ No newline at end of file