diff options
author | Proudmuslim <proudmuslim-dev@protonmail.com> | 2023-07-21 05:58:40 +0000 |
---|---|---|
committer | Proudmuslim <proudmuslim-dev@protonmail.com> | 2023-07-21 05:58:40 +0000 |
commit | fc6e179d6e613d7274c3b3ee27f5d4f68d11b9e6 (patch) | |
tree | 4e8c87aa614d963db4014fffd44b9ef621f8a853 /src/config.rs | |
parent | Bump deps (diff) | |
download | miniserve-fc6e179d6e613d7274c3b3ee27f5d4f68d11b9e6.tar.gz miniserve-fc6e179d6e613d7274c3b3ee27f5d4f68d11b9e6.zip |
Add ability to read auth from file
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/config.rs b/src/config.rs index 8976d35..e353afd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,7 @@ #[cfg(feature = "tls")] use std::{fs::File, io::BufReader}; use std::{ + io::BufRead, net::{IpAddr, Ipv4Addr, Ipv6Addr}, path::PathBuf, }; @@ -14,7 +15,7 @@ use http::HeaderMap; use rustls_pemfile as pemfile; use crate::{ - args::{CliArgs, MediaType}, + args::{parse_auth, CliArgs, MediaType}, auth::RequiredAuth, file_upload::sanitize_path, renderer::ThemeSlug, @@ -157,6 +158,17 @@ impl MiniserveConfig { _ => "".to_owned(), }; + let mut auth = args.auth; + + if let Some(path) = args.auth_file { + let file = File::open(path)?; + let lines = BufReader::new(file).lines(); + + for line in lines { + auth.push(parse_auth(line?.as_str())?); + } + } + // Generate some random routes for the favicon and css so that they are very unlikely to conflict with // real files. // If --random-route is enabled , in order to not leak the random generated route, we must not use it @@ -239,7 +251,7 @@ impl MiniserveConfig { path: args.path.unwrap_or_else(|| PathBuf::from(".")), port, interfaces, - auth: args.auth, + auth, path_explicitly_chosen, no_symlinks: args.no_symlinks, show_hidden: args.hidden, |