2020-12-12 13:58:04 +01:00
|
|
|
use std::default::Default;
|
2020-02-14 12:20:17 +01:00
|
|
|
use std::str::FromStr;
|
2020-02-18 16:55:19 +01:00
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use std::io::Read;
|
2020-12-12 13:58:04 +01:00
|
|
|
use std::fs;
|
2020-09-15 14:31:10 +02:00
|
|
|
use std::collections::HashMap;
|
2020-02-18 16:55:19 +01:00
|
|
|
|
2020-12-12 13:58:04 +01:00
|
|
|
use serde::{Serialize, Deserialize};
|
2020-09-15 14:31:10 +02:00
|
|
|
|
2020-12-12 13:58:04 +01:00
|
|
|
use crate::error::Result;
|
|
|
|
use crate::machine::MachineDescription;
|
|
|
|
use crate::db::machine::MachineIdentifier;
|
2020-09-15 14:31:10 +02:00
|
|
|
|
2020-12-12 13:58:04 +01:00
|
|
|
pub fn read(path: &Path) -> Result<Config> {
|
|
|
|
serde_dhall::from_file(path).parse().map_err(Into::into)
|
2020-02-14 12:20:17 +01:00
|
|
|
}
|
|
|
|
|
2020-12-12 13:58:04 +01:00
|
|
|
#[deprecated]
|
|
|
|
pub type Settings = Config;
|
|
|
|
|
2020-02-16 16:02:03 +01:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
2020-12-12 13:58:04 +01:00
|
|
|
pub struct Config {
|
|
|
|
/// A list of address/port pairs to listen on.
|
|
|
|
// TODO: This should really be a variant type; that is something that can figure out itself if
|
|
|
|
// it contains enough information to open a socket (i.e. it checks if it's a valid path (=>
|
|
|
|
// Unix socket) or IPv4/v6 address)
|
2020-09-15 14:31:10 +02:00
|
|
|
pub listens: Box<[Listen]>,
|
2020-02-14 12:20:17 +01:00
|
|
|
|
2020-12-12 13:58:04 +01:00
|
|
|
/// Machine descriptions to load
|
|
|
|
pub machines: HashMap<MachineIdentifier, MachineDescription>,
|
|
|
|
|
|
|
|
/// Modules to load and their configuration options
|
|
|
|
pub modules: HashMap<String, HashMap<String, String>>,
|
2020-02-14 12:20:17 +01:00
|
|
|
}
|
2020-02-18 16:55:19 +01:00
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
pub struct Listen {
|
|
|
|
pub address: String,
|
|
|
|
pub port: Option<u16>,
|
|
|
|
}
|
|
|
|
|
2020-09-15 14:31:10 +02:00
|
|
|
impl Default for Settings {
|
2020-02-18 16:55:19 +01:00
|
|
|
fn default() -> Self {
|
2020-12-12 13:58:04 +01:00
|
|
|
let modules: HashMap::<String, HashMap<String, String>> = HashMap::new();
|
|
|
|
Config {
|
|
|
|
listens: Box::new([]),
|
|
|
|
machines: HashMap::new(),
|
|
|
|
modules: modules,
|
2020-02-18 16:55:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The default port in the non-assignable i.e. free-use area
|
|
|
|
pub const DEFAULT_PORT: u16 = 59661;
|