From 942ac099c71db4ac638a3ac158bc889dc0af1ca3 Mon Sep 17 00:00:00 2001 From: Antoine Gersant Date: Sun, 4 Jun 2017 18:32:59 -0700 Subject: [PATCH] autoformat --- src/api.rs | 28 ++++++++++++++++------------ src/main.rs | 4 ++-- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/api.rs b/src/api.rs index 45b9f95..5a0aeb4 100644 --- a/src/api.rs +++ b/src/api.rs @@ -40,25 +40,28 @@ impl Version { #[derive(Deserialize, Serialize)] struct Session { - username: String, + username: String, } struct SessionKey {} impl typemap::Key for SessionKey { - type Value = Session; + type Value = Session; } pub fn get_handler(collection: Collection, secret: &str) -> Chain { let collection = Arc::new(collection); - let api_handler = get_endpoints(collection); + let api_handler = get_endpoints(collection); let mut api_chain = Chain::new(api_handler); let manager = ChaCha20Poly1305SessionManager::::from_password(secret.as_bytes()); let config = SessionConfig::default(); - let session_middleware = SessionMiddleware::>::new(manager, config); + let session_middleware = + SessionMiddleware::>::new(manager, config); api_chain.link_around(session_middleware); - + api_chain } @@ -142,11 +145,9 @@ struct AuthHandler { } fn set_cookie(username: &str, response: &mut Response) { - response.headers.set( - SetCookie(vec![ - format!("username={}; Path=/", username) - ]) - ); + response + .headers + .set(SetCookie(vec![format!("username={}; Path=/", username)])); } impl Handler for AuthHandler { @@ -161,7 +162,8 @@ impl Handler for AuthHandler { auth_success = self.collection .auth(auth.username.as_str(), password.as_str()); username = Some(auth.username.clone()); - req.extensions.insert::(Session { username: auth.username.clone() }); + req.extensions + .insert::(Session { username: auth.username.clone() }); } } @@ -215,7 +217,9 @@ fn auth(request: &mut Request, collection: &Collection) -> IronResult if collection.auth(username.as_str(), password.as_str()) { let mut response = Response::with((status::Ok, "")); set_cookie(&username, &mut response); - request.extensions.insert::(Session { username: username.clone() }); + request + .extensions + .insert::(Session { username: username.clone() }); Ok(response) } else { Err(Error::from(ErrorKind::IncorrectCredentials).into()) diff --git a/src/main.rs b/src/main.rs index 699b845..fe28b49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,12 +84,12 @@ fn daemonize() -> Result<()> { log_file.push("polaris.log"); match daemonize_redirect(Some(&log_file), Some(&log_file), ChdirMode::NoChdir) { Ok(_) => Ok(()), - Err(_) => bail!(ErrorKind::DaemonError) + Err(_) => bail!(ErrorKind::DaemonError), } } fn run() -> Result<()> { - + #[cfg(unix)] daemonize()?;