save
This commit is contained in:
parent
381347e66a
commit
90bc6d6d4f
|
@ -12,11 +12,16 @@ impl Error {
|
||||||
|
|
||||||
impl From<git2::Error> for Error {
|
impl From<git2::Error> for Error {
|
||||||
fn from(giterr: git2::Error) -> Self {
|
fn from(giterr: git2::Error) -> Self {
|
||||||
// panic!()
|
|
||||||
Error::BadGateway(format!("{}", giterr))
|
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 {
|
impl From<Error> for actix_web::error::Error {
|
||||||
fn from(e: Error) -> Self {
|
fn from(e: Error) -> Self {
|
||||||
match e {
|
match e {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
pub struct Gitust {
|
pub struct Gitust {
|
||||||
pub repo_root_path : String,
|
pub repo_root_path : String,
|
||||||
|
pub session_key : String,
|
||||||
}
|
}
|
|
@ -14,6 +14,7 @@ use tokio::process::{Child, Command};
|
||||||
|
|
||||||
use crate::gitust::Gitust;
|
use crate::gitust::Gitust;
|
||||||
use crate::reader::ToStream;
|
use crate::reader::ToStream;
|
||||||
|
use crate::error;
|
||||||
|
|
||||||
//#[get("/git/{owner}/{repo}.git/{path:.*}")]
|
//#[get("/git/{owner}/{repo}.git/{path:.*}")]
|
||||||
pub async fn git_proto(
|
pub async fn git_proto(
|
||||||
|
@ -22,7 +23,7 @@ pub async fn git_proto(
|
||||||
mut req: HttpRequest,
|
mut req: HttpRequest,
|
||||||
gitust : web::Data<Gitust>,
|
gitust : web::Data<Gitust>,
|
||||||
auth : BasicAuth,
|
auth : BasicAuth,
|
||||||
) -> io::Result<HttpResponse>{
|
) -> Result<HttpResponse, error::Error>{
|
||||||
//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");
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -155,13 +155,16 @@ async fn main() -> std::io::Result<()> {
|
||||||
env_logger::from_env(Env::default().default_filter_or("info")).init();
|
env_logger::from_env(Env::default().default_filter_or("info")).init();
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
let auth = HttpAuthentication::basic(basic_auth_validator);
|
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()
|
App::new()
|
||||||
.data(Gitust {
|
|
||||||
repo_root_path: "/home/hubert/gitust".to_string(),
|
|
||||||
})
|
|
||||||
.wrap(Logger::default())
|
.wrap(Logger::default())
|
||||||
// .wrap(Logger::new("%a %{User-Agent}i"))
|
// .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(hello)
|
||||||
.service(echo)
|
.service(echo)
|
||||||
.service(hello_test)
|
.service(hello_test)
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
use actix_web_httpauth::extractors::basic::BasicAuth;
|
use actix_web_httpauth::extractors::basic::BasicAuth;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
pub fn check_user(auth : BasicAuth) -> bool {
|
pub fn check_user(name : String, pwd : String) -> bool {
|
||||||
match auth.password() {
|
pwd.eq(&(name + "pwd")) //stub!
|
||||||
None => {false}
|
|
||||||
Some(pwd) => {pwd.to_string().eq(&(auth.user_id().to_string() + "pwd"))}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue