add example config and just overall improve the config data stuff
This commit is contained in:
parent
0d0cb945a1
commit
9887d5196f
3 changed files with 83 additions and 35 deletions
68
src/data.rs
Normal file
68
src/data.rs
Normal file
|
@ -0,0 +1,68 @@
|
|||
use std::{collections::HashMap, path::PathBuf, str::FromStr};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||
struct SiteInfo {
|
||||
name: String,
|
||||
aliases: Vec<String>,
|
||||
/// Aliases for this subdomain - will have the same exact settings
|
||||
/// The socket address (e.g. `192.168.1.8:8080`) or port number (if on `localhost`) of the service to reverse proxy
|
||||
address: String,
|
||||
/// What auth file to use - 0 means none
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
auth: Option<u8>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
conf_file: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||
struct Config {
|
||||
/// What directory to output the conf files to
|
||||
#[serde(default = "default_output_dir")]
|
||||
output_dir: PathBuf,
|
||||
domain: String,
|
||||
/// Subdomains/services in the format `subdomain: SiteInfo`
|
||||
subdomains: HashMap<String, SiteInfo>,
|
||||
/// Paths to the htpasswd file for each auth number - starts at 1, goes to 255; see [`SiteInfo`]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
htpasswd_files: Option<Vec<PathBuf>>,
|
||||
/// Default IP for if it's not specified in `socket_address_or_port` in [`SiteInfo`]. Defaults to localhost if not specified.
|
||||
#[serde(default = "default_default_ip")]
|
||||
default_ip: String,
|
||||
}
|
||||
|
||||
/// Generates the default
|
||||
pub(crate) fn example_config() -> String {
|
||||
let mut subdomains: HashMap<String, SiteInfo> = HashMap::new();
|
||||
subdomains.insert(
|
||||
"qbittorrent".to_string(),
|
||||
SiteInfo {
|
||||
name: "Qbittorrent".to_string(),
|
||||
aliases: vec!["qb".to_string()],
|
||||
address: "6011".to_string(),
|
||||
auth: None,
|
||||
conf_file: None,
|
||||
},
|
||||
);
|
||||
return serde_yml::to_string(
|
||||
&(Config {
|
||||
output_dir: default_output_dir(),
|
||||
domain: "example.net".to_string(),
|
||||
subdomains: subdomains,
|
||||
htpasswd_files: None,
|
||||
default_ip: default_default_ip(),
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- DEFAULTS -----------------------------------------------------
|
||||
|
||||
fn default_output_dir() -> PathBuf {
|
||||
return PathBuf::from_str("conf.d").unwrap();
|
||||
}
|
||||
|
||||
fn default_default_ip() -> String {
|
||||
return "localhost".to_string();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue