feat: change auth logic/options
This commit is contained in:
parent
ecb3984edc
commit
c50f97925c
3 changed files with 18 additions and 16 deletions
10
README.md
10
README.md
|
@ -89,15 +89,15 @@ ARGS:
|
||||||
<path> Path to a root directory for serving files [default: .]
|
<path> Path to a root directory for serving files [default: .]
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
-a, --auth <user:pass> Use HTTP authentication for all operations
|
-a, --auth <user:pass> Use HTTP authentication to restrict write
|
||||||
|
--auth-access Enhance authentication to restrict access
|
||||||
-A, --allow-all Allow all operations
|
-A, --allow-all Allow all operations
|
||||||
--allow-delete Allow delete operation
|
--allow-delete Allow delete files/folders
|
||||||
--allow-symlink Allow symlink to directories/files outside root directory
|
--allow-symlink Allow symlink to files/folders outside root directory
|
||||||
--allow-upload Allow upload operation
|
--allow-upload Allow upload files/folders
|
||||||
-b, --bind <address> Specify bind address [default: 127.0.0.1]
|
-b, --bind <address> Specify bind address [default: 127.0.0.1]
|
||||||
--cors Enable CORS, sets `Access-Control-Allow-Origin: *`
|
--cors Enable CORS, sets `Access-Control-Allow-Origin: *`
|
||||||
-h, --help Print help information
|
-h, --help Print help information
|
||||||
--no-auth-read Do not authenticate read operations like static serving
|
|
||||||
-p, --port <port> Specify port to listen on [default: 5000]
|
-p, --port <port> Specify port to listen on [default: 5000]
|
||||||
--path-prefix <path> Specify an url path prefix
|
--path-prefix <path> Specify an url path prefix
|
||||||
--render-index Render index.html when requesting a directory
|
--render-index Render index.html when requesting a directory
|
||||||
|
|
22
src/args.rs
22
src/args.rs
|
@ -49,17 +49,17 @@ fn app() -> clap::Command<'static> {
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("allow-upload")
|
Arg::new("allow-upload")
|
||||||
.long("allow-upload")
|
.long("allow-upload")
|
||||||
.help("Allow upload operation"),
|
.help("Allow upload files/folders"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("allow-delete")
|
Arg::new("allow-delete")
|
||||||
.long("allow-delete")
|
.long("allow-delete")
|
||||||
.help("Allow delete operation"),
|
.help("Allow delete files/folders"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("allow-symlink")
|
Arg::new("allow-symlink")
|
||||||
.long("allow-symlink")
|
.long("allow-symlink")
|
||||||
.help("Allow symlink to directories/files outside root directory"),
|
.help("Allow symlink to files/folders outside root directory"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("render-index")
|
Arg::new("render-index")
|
||||||
|
@ -74,14 +74,16 @@ fn app() -> clap::Command<'static> {
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("auth")
|
Arg::new("auth")
|
||||||
.short('a')
|
.short('a')
|
||||||
|
.display_order(1)
|
||||||
.long("auth")
|
.long("auth")
|
||||||
.help("Use HTTP authentication for all operations")
|
.help("Use HTTP authentication to restrict write")
|
||||||
.value_name("user:pass"),
|
.value_name("user:pass"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("no-auth-read")
|
Arg::new("auth-access")
|
||||||
.long("no-auth-read")
|
.display_order(1)
|
||||||
.help("Do not authenticate read operations like static serving"),
|
.long("auth-access")
|
||||||
|
.help("Enhance authentication to restrict access"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("cors")
|
Arg::new("cors")
|
||||||
|
@ -113,7 +115,7 @@ pub struct Args {
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
pub path_prefix: Option<String>,
|
pub path_prefix: Option<String>,
|
||||||
pub auth: Option<String>,
|
pub auth: Option<String>,
|
||||||
pub no_auth_read: bool,
|
pub auth_access: bool,
|
||||||
pub allow_upload: bool,
|
pub allow_upload: bool,
|
||||||
pub allow_delete: bool,
|
pub allow_delete: bool,
|
||||||
pub allow_symlink: bool,
|
pub allow_symlink: bool,
|
||||||
|
@ -135,7 +137,7 @@ impl Args {
|
||||||
let path_prefix = matches.value_of("path-prefix").map(|v| v.to_owned());
|
let path_prefix = matches.value_of("path-prefix").map(|v| v.to_owned());
|
||||||
let cors = matches.is_present("cors");
|
let cors = matches.is_present("cors");
|
||||||
let auth = matches.value_of("auth").map(|v| v.to_owned());
|
let auth = matches.value_of("auth").map(|v| v.to_owned());
|
||||||
let no_auth_read = matches.is_present("no-auth-read");
|
let auth_access = matches.is_present("auth-access");
|
||||||
let allow_upload = matches.is_present("allow-all") || matches.is_present("allow-upload");
|
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");
|
let allow_delete = matches.is_present("allow-all") || matches.is_present("allow-delete");
|
||||||
let allow_symlink = matches.is_present("allow-all") || matches.is_present("allow-symlink");
|
let allow_symlink = matches.is_present("allow-all") || matches.is_present("allow-symlink");
|
||||||
|
@ -156,7 +158,7 @@ impl Args {
|
||||||
path,
|
path,
|
||||||
path_prefix,
|
path_prefix,
|
||||||
auth,
|
auth,
|
||||||
no_auth_read,
|
auth_access,
|
||||||
cors,
|
cors,
|
||||||
allow_delete,
|
allow_delete,
|
||||||
allow_upload,
|
allow_upload,
|
||||||
|
|
|
@ -519,7 +519,7 @@ impl InnerService {
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
None => self.args.no_auth_read && req.method() == Method::GET,
|
None => !self.args.auth_access && req.method() == Method::GET,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue