pub fn from_filename_and_env(path: String) -> Self {
        let mut settings = config::Config::default();
        settings
            .merge(config::File::with_name(&path))
            .unwrap()
            .merge(config::Environment::with_prefix("SAML"))
            .unwrap();

        let filenames: Vec<String> = match settings.get("sp_metadata_files") {
            Ok(filenames) => filenames,
            _ => Vec::<String>::new(),
        };

        log::debug!("Loading SP Metadata from config.");

        let sp_metadata = load_sp_metadata(filenames);
        eprintln!("Done loading SP Metadata from config.");

        let tilde_cert_path: String = settings.get("tls_cert_path").unwrap_or_else(|error| {
            eprintln!(
                "You need to specify 'tls_cert_path' in configuration, quitting. ({:?})",
                error
            );
            std::process::exit(1)
        });
        let tilde_key_path: String = settings.get("tls_key_path").unwrap_or_else(|error| {
            eprintln!(
                "You need to specify 'tls_key_path' in configuration, quitting. ({:?})",
                error
            );
            std::process::exit(1)
        });

        let tilde_saml_cert_path: String = settings.get("saml_cert_path").unwrap_or_else(|error| {
            eprintln!(
                "You need to specify 'saml_cert_path' in configuration, quitting. ({:?})",
                error
            );
            std::process::exit(1)
        });
        let tilde_saml_key_path: String = settings.get("saml_key_path").unwrap_or_else(|error| {
            eprintln!(
                "You need to specify 'saml_key_path' in configuration, quitting. ({:?})",
                error
            );
            std::process::exit(1)
        });
        let bind_address: String = settings.get("bind_address").unwrap_or_else(|error| {
            eprintln!(
                "You need to specify 'bind_address' in configuration, quitting. ({:?})",
                error
            );
            std::process::exit(1)
        });
        let tls_cert_path = shellexpand::tilde(&tilde_cert_path).into_owned();
        let tls_key_path = shellexpand::tilde(&tilde_key_path).into_owned();
        let saml_cert_path = shellexpand::tilde(&tilde_saml_cert_path).into_owned();
        let saml_key_path = shellexpand::tilde(&tilde_saml_key_path).into_owned();

        use saml_rs::sign::load_key_from_filename;
        let saml_signing_key = match load_key_from_filename(&saml_key_path) {
            Ok(value) => value,
            Err(error) => {
                eprintln!(
                    "Failed to load SAML signing key from {}: {:?}",
                    &saml_key_path, error
                );
                std::process::exit(1);
            }
        };
        let saml_signing_cert = match saml_rs::sign::load_public_cert_from_filename(&saml_cert_path)
        {
            Ok(value) => value,
            Err(error) => {
                eprintln!(
                    "Failed to load SAML signing cert from {}: {:?}",
                    &saml_key_path, error
                );
                std::process::exit(1);
            }
        };

        eprintln!("SETTINGS\n{:?}", settings);
        ServerConfig {
            public_hostname: settings
                .get("public_hostname")
                .unwrap_or(ServerConfig::default().public_hostname),
            bind_address,
            tls_cert_path,
            tls_key_path,
            entity_id: settings
                .get("entity_id")
                .unwrap_or(ServerConfig::default().entity_id),
            sp_metadata_files: settings
                .get("sp_metadata_files")
                .unwrap_or(ServerConfig::default().sp_metadata_files),
            sp_metadata,
            session_lifetime: settings
                .get("default_session_lifetime")
                .unwrap_or(ServerConfig::default().session_lifetime),
            saml_cert_path,
            saml_key_path,

            saml_signing_key: Some(saml_signing_key),
            saml_signing_cert: Some(saml_signing_cert),
        }
    }
/// Pass this a filename (with or without extension) and it'll choose from JSON/YAML/TOML etc and also check
/// environment variables starting with SAML_
Pass this a filename (with or without extension) and it'll choose from JSON/YAML/TOML etc and also check
environment variables starting with SAML_
Pass this a filename ( with or without extension ) and it ' ll choose from JSON / YAML / TOML etc and also check environment variables starting with SAML_
pub fn from_filename_and_env(path: String) -> Self {
        let mut settings = config::Config::default();
        settings
            .merge(config::File::with_name(&path))
            .unwrap()
            .merge(config::Environment::with_prefix("SAML"))
            .unwrap();
        let filenames: Vec<String> = match settings.get("sp_metadata_files") {
            Ok(filenames) => filenames,
            _ => Vec::<String>::new(),
        };
        log::debug!("Loading SP Metadata from config.");
        let sp_metadata = load_sp_metadata(filenames);
        eprintln!("Done loading SP Metadata from config.");
        let tilde_cert_path: String = settings.get("tls_cert_path").unwrap_or_else(|error| {
            eprintln!(
                "You need to specify 'tls_cert_path' in configuration, quitting. ({:?})",
                error
            );
            std::process::exit(1)
        });
        let tilde_key_path: String = settings.get("tls_key_path").unwrap_or_else(|error| {
            eprintln!(
                "You need to specify 'tls_key_path' in configuration, quitting. ({:?})",
                error
            );
            std::process::exit(1)
        });
        let tilde_saml_cert_path: String = settings.get("saml_cert_path").unwrap_or_else(|error| {
            eprintln!(
                "You need to specify 'saml_cert_path' in configuration, quitting. ({:?})",
                error
            );
            std::process::exit(1)
        });
        let tilde_saml_key_path: String = settings.get("saml_key_path").unwrap_or_else(|error| {
            eprintln!(
                "You need to specify 'saml_key_path' in configuration, quitting. ({:?})",
                error
            );
            std::process::exit(1)
        });
        let bind_address: String = settings.get("bind_address").unwrap_or_else(|error| {
            eprintln!(
                "You need to specify 'bind_address' in configuration, quitting. ({:?})",
                error
            );
            std::process::exit(1)
        });
        let tls_cert_path = shellexpand::tilde(&tilde_cert_path).into_owned();
        let tls_key_path = shellexpand::tilde(&tilde_key_path).into_owned();
        let saml_cert_path = shellexpand::tilde(&tilde_saml_cert_path).into_owned();
        let saml_key_path = shellexpand::tilde(&tilde_saml_key_path).into_owned();
        use saml_rs::sign::load_key_from_filename;
        let saml_signing_key = match load_key_from_filename(&saml_key_path) {
            Ok(value) => value,
            Err(error) => {
                eprintln!(
                    "Failed to load SAML signing key from {}: {:?}",
                    &saml_key_path, error
                );
                std::process::exit(1);
            }
        };
        let saml_signing_cert = match saml_rs::sign::load_public_cert_from_filename(&saml_cert_path)
        {
            Ok(value) => value,
            Err(error) => {
                eprintln!(
                    "Failed to load SAML signing cert from {}: {:?}",
                    &saml_key_path, error
                );
                std::process::exit(1);
            }
        };
        eprintln!("SETTINGS\n{:?}", settings);
        ServerConfig {
            public_hostname: settings
                .get("public_hostname")
                .unwrap_or(ServerConfig::default().public_hostname),
            bind_address,
            tls_cert_path,
            tls_key_path,
            entity_id: settings
                .get("entity_id")
                .unwrap_or(ServerConfig::default().entity_id),
            sp_metadata_files: settings
                .get("sp_metadata_files")
                .unwrap_or(ServerConfig::default().sp_metadata_files),
            sp_metadata,
            session_lifetime: settings
                .get("default_session_lifetime")
                .unwrap_or(ServerConfig::default().session_lifetime),
            saml_cert_path,
            saml_key_path,
            saml_signing_key: Some(saml_signing_key),
            saml_signing_cert: Some(saml_signing_cert),
        }
    }
pub fn from_filename_and_env ( path : String ) -> Self { let mut settings = config :: Config :: default ( ) ; settings . merge ( config :: File :: with_name ( & path ) ) . unwrap ( ) . merge ( config :: Environment :: with_prefix ( " " ) ) . unwrap ( ) ; let filenames : Vec < String > = match settings . get ( " " ) { Ok ( filenames ) => filenames , _ => Vec :: < String > :: new ( ) , } ; log :: debug ! ( " " ) ; let sp_metadata = load_sp_metadata ( filenames ) ; eprintln ! ( " " ) ; let tilde_cert_path : String = settings . get ( " " ) . unwrap_or_else ( | error | { eprintln ! ( " " error ) ; std :: process :: exit ( 1 ) } ) ; let tilde_key_path : String = settings . get ( " " ) . unwrap_or_else ( | error | { eprintln ! ( " " error ) ; std :: process :: exit ( 1 ) } ) ; let tilde_saml_cert_path : String = settings . get ( " " ) . unwrap_or_else ( | error | { eprintln ! ( " " error ) ; std :: process :: exit ( 1 ) } ) ; let tilde_saml_key_path : String = settings . get ( " " ) . unwrap_or_else ( | error | { eprintln ! ( " " error ) ; std :: process :: exit ( 1 ) } ) ; let bind_address : String = settings . get ( " " ) . unwrap_or_else ( | error | { eprintln ! ( " " error ) ; std :: process :: exit ( 1 ) } ) ; let tls_cert_path = shellexpand :: tilde ( & tilde_cert_path ) . into_owned ( ) ; let tls_key_path = shellexpand :: tilde ( & tilde_key_path ) . into_owned ( ) ; let saml_cert_path = shellexpand :: tilde ( & tilde_saml_cert_path ) . into_owned ( ) ; let saml_key_path = shellexpand :: tilde ( & tilde_saml_key_path ) . into_owned ( ) ; use saml_rs :: sign :: load_key_from_filename ; let saml_signing_key = match load_key_from_filename ( & saml_key_path ) { Ok ( value ) => value , Err ( error ) => { eprintln ! ( " " saml_key_path error ) ; std :: process :: exit ( 1 ) ; } } ; let saml_signing_cert = match saml_rs :: sign :: load_public_cert_from_filename ( & saml_cert_path ) { Ok ( value ) => value , Err ( error ) => { eprintln ! ( " " saml_key_path error ) ; std :: process :: exit ( 1 ) ; } } ; eprintln ! ( " \n " settings ) ; ServerConfig { public_hostname : settings . get ( " " ) . unwrap_or ( ServerConfig :: default ( ) . public_hostname ) , bind_address , tls_cert_path , tls_key_path , entity_id : settings . get ( " " ) . unwrap_or ( ServerConfig :: default ( ) . entity_id ) , sp_metadata_files : settings . get ( " " ) . unwrap_or ( ServerConfig :: default ( ) . sp_metadata_files ) , sp_metadata , session_lifetime : settings . get ( " " ) . unwrap_or ( ServerConfig :: default ( ) . session_lifetime ) , saml_cert_path , saml_key_path , saml_signing_key : Some ( saml_signing_key ) , saml_signing_cert : Some ( saml_signing_cert ) , } }
Pass this a filename (with or without extension) and it'll choose from JSON/YAML/TOML etc and also check
environment variables starting with SAML_
Pass this a filename ( with or without extension ) and it ' ll choose from JSON / YAML / TOML etc and also check environment variables starting with SAML_
path
String
path
String