mirror of
https://github.com/sigoden/dufs.git
synced 2026-04-09 09:09:03 +03:00
feat: added basic auth (#60)
* some small css fixes and changes * added basic auth https://stackoverflow.com/a/9534652/3642588 * most tests are passing * fixed all the tests * maybe now CI will pass * implemented sigoden's suggestions * test basic auth * fixed some little things
This commit is contained in:
15
src/args.rs
15
src/args.rs
@@ -5,6 +5,7 @@ use std::net::IpAddr;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::auth::AccessControl;
|
||||
use crate::auth::AuthMethod;
|
||||
use crate::tls::{load_certs, load_private_key};
|
||||
use crate::BoxResult;
|
||||
|
||||
@@ -47,6 +48,14 @@ fn app() -> Command<'static> {
|
||||
.value_name("path")
|
||||
.help("Specify an url path prefix"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("auth-method")
|
||||
.long("auth-method")
|
||||
.help("Choose auth method")
|
||||
.possible_values(["basic", "digest"])
|
||||
.default_value("digest")
|
||||
.value_name("value"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("auth")
|
||||
.short('a')
|
||||
@@ -123,6 +132,7 @@ pub struct Args {
|
||||
pub path_is_file: bool,
|
||||
pub path_prefix: String,
|
||||
pub uri_prefix: String,
|
||||
pub auth_method: AuthMethod,
|
||||
pub auth: AccessControl,
|
||||
pub allow_upload: bool,
|
||||
pub allow_delete: bool,
|
||||
@@ -162,6 +172,10 @@ impl Args {
|
||||
.values_of("auth")
|
||||
.map(|v| v.collect())
|
||||
.unwrap_or_default();
|
||||
let auth_method = match matches.value_of("auth-method").unwrap() {
|
||||
"basic" => AuthMethod::Basic,
|
||||
_ => AuthMethod::Digest,
|
||||
};
|
||||
let auth = AccessControl::new(&auth, &uri_prefix)?;
|
||||
let allow_upload = matches.is_present("allow-all") || matches.is_present("allow-upload");
|
||||
let allow_delete = matches.is_present("allow-all") || matches.is_present("allow-delete");
|
||||
@@ -185,6 +199,7 @@ impl Args {
|
||||
path_is_file,
|
||||
path_prefix,
|
||||
uri_prefix,
|
||||
auth_method,
|
||||
auth,
|
||||
enable_cors,
|
||||
allow_delete,
|
||||
|
||||
Reference in New Issue
Block a user