From b86f5abf6cdacda0735c36bc481cb4a0d10be51c Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Mon, 13 Jul 2020 14:33:31 +0700 Subject: [PATCH] Chaning the default of permitted_users to depend on `[[users]]` --- README.md | 4 +++- src/config.rs | 6 +++--- src/main.rs | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a349953..d204e47 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,9 @@ Anywhere a username is accepted it can take any username or one of the following - `anyone` means any user with a valid user/pass - `anonymous` means no user/pass required -The default `permitted_users` list is `[ "anonymous" ]` meaning no authentication required. If you want to use authenitcation then after adding your users through `[[users]]` please ensure you update the `permittted_users` for each camera. +The default `permitted_users` list is: +- `[ "anonymous"]` if no `[[users]]` were given in the config meaning no authentication required to connect. +- `[ "anyone" ]` if `[[users]]` were provided meaning any authourised users can connect. You can change the Neolink log level by setting the `RUST_LOG` environment variable (not in the configuration file) to one of `error`, `warn`, `info`, `debug`, or `trace`: diff --git a/src/config.rs b/src/config.rs index d1381a5..086d5db 100644 --- a/src/config.rs +++ b/src/config.rs @@ -70,7 +70,7 @@ pub struct CameraConfig { pub stream: String, #[serde(default = "default_permitted_users")] - pub permitted_users: Vec, + pub permitted_users: Option>, } #[derive(Debug, Deserialize, Validate, Clone)] @@ -108,8 +108,8 @@ fn default_tls_client_auth() -> String { "none".to_string() } -fn default_permitted_users() -> Vec { - vec!["anonymous".to_string()] +fn default_permitted_users() -> Option> { + None } fn default_users() -> Vec { diff --git a/src/main.rs b/src/main.rs index feff234..d2f6898 100644 --- a/src/main.rs +++ b/src/main.rs @@ -177,8 +177,22 @@ fn set_up_users(users: &Vec, rtsp: &RtspServer) { fn get_permitted_users( users: &Vec, - current_permitted_users: &Vec, + permitted_users: &Option>, ) -> Vec { + let current_permitted_users = match permitted_users { + Some(permitted_users) => permitted_users.clone().to_owned(), + None => { + // If None then the users didn't specify permitted_users + // In this case we do either + // - Any authourised user if [[users]] was specified + // - Any connecting user if [[users]] was not added + if users.len() > 0 { + vec!("anyone".to_string()) + } else { + vec!("anonymous".to_string()) + } + } + }; // This is required to handle the special case of "anyone" // ===Special set up of "anyone"=== // If in the camera config there is the user "anyone"