Add env based config for LDAP addr

This commit is contained in:
Alex Wright 2019-08-11 12:37:54 +02:00
parent ca45203392
commit 467a449457
1 changed files with 12 additions and 2 deletions

View File

@ -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<LdapUser, AuthError> {
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<RouterService, std::io::Error> {
}
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));