From 381347e66a9bc31b2621e4262d48574d8c43963f Mon Sep 17 00:00:00 2001 From: Hubert Date: Wed, 21 Jul 2021 06:05:54 +0200 Subject: [PATCH] user from basic auth --- src/error.rs | 5 +---- src/main.rs | 1 - src/web/repo.rs | 10 ++++++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/error.rs b/src/error.rs index b98795f..9abf9f0 100644 --- a/src/error.rs +++ b/src/error.rs @@ -21,9 +21,6 @@ impl From for actix_web::error::Error { fn from(e: Error) -> Self { match e { Error::BadGateway(msg) => {HttpResponseBuilder::new(StatusCode::BAD_GATEWAY).body(msg).into()} - Error::Unauthorized(msg) => { - let config : basic::Config = Default::default(); - AuthenticationError::from(config).into()} - } + Error::Unauthorized(realm) => {AuthenticationError::from(basic::Config::default().realm(realm)).into()}} } } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index a1caad4..84052b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -183,7 +183,6 @@ async fn main() -> std::io::Result<()> { ) .service( webx::resource("/git/{user}/{repo}.git/{path:.*}") - // .wrap(auth) .route(webx::route().to(gitproto::git_proto)) ) .service( diff --git a/src/web/repo.rs b/src/web/repo.rs index b94f562..1414b5d 100644 --- a/src/web/repo.rs +++ b/src/web/repo.rs @@ -1,7 +1,7 @@ use std::path::Path; use actix_web::web; -use actix_web_httpauth::extractors::basic::BasicAuth; +use actix_web_httpauth::extractors::basic; use actix_web::get; use askama_actix::Template; @@ -60,9 +60,10 @@ pub async fn git_main( web::Path((ownername, reponame)): web::Path<(String, String)>, web::Query(GitWebQ{commit : commitnameopt, path : pathopt, branch : branchopt}) : web::Query, gitust : web::Data, - auth : Option, + auth : Option, //auth : BasicAuth, ) -> Result, Vec<(String, String)>>, error::Error> { + // let authtorization = auth.ok_or(error::Error::Unauthorized("safe repo".to_string()))?; let rootname = match pathopt { None => {"".to_string()} Some(s) => { @@ -82,7 +83,8 @@ pub async fn git_main( }; let owner = Owner { name : ownername}; let repo = Repository {name : reponame, owner}; - let user = User { name : "Hubert".to_string()}; + // let user = User { name : "Hubert".to_string()}; + let user = auth.map(|auth| User{name : auth.user_id().to_string()}); // il faut ajouter le commit/branch dans la query let path = rootname.split("/").map_accum("/git/".to_string() + &repo.owner.name + "/" + &repo.name, |str_ref, b| { let href = b + "/" + str_ref; @@ -104,5 +106,5 @@ pub async fn git_main( } } } - Ok(GitMainTemplate { repo, browse : entries, root : path, user_opt : Some(user)}) + Ok(GitMainTemplate { repo, browse : entries, root : path, user_opt : user}) }