diff --git a/src/main.rs b/src/main.rs index 8c6f2f1..62ce75d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ extern crate tokio; #[macro_use] extern crate serde_derive; +use std::env; use std::str::{ FromStr, from_utf8, @@ -32,6 +33,7 @@ pub enum AuthError { Parse, Decode, LdapBind, + LdapConfig, LdapConnection, LdapSearch, } @@ -63,7 +65,11 @@ struct LdapUser { } fn auth_user(auth: &BasicAuthentication) -> Result { - let ldap = match LdapConn::new("ldap://192.168.122.61:389") { + let ldap_server_addr = match env::var("LDAP_SERVER_ADDR") { + Ok(addr) => addr, + _ => return Err(AuthError::LdapConfig), + }; + let ldap = match LdapConn::new(&ldap_server_addr) { Ok(conn) => conn, Err(_err) => return Err(AuthError::LdapConnection), }; @@ -187,7 +193,11 @@ fn router_service() -> Result { } fn main() { - let addr = "0.0.0.0:3000".parse().expect("Bad Address"); + let addr_str = match env::var("LISTEN_ADDR") { + Ok(addr) => addr, + _ => "0.0.0.0:3000".to_string(), + }; + let addr = addr_str.parse().expect("Bad Address"); let server = Server::bind(&addr) .serve(router_service) .map_err(|e| eprintln!("server error: {}", e));