parent
5099f79260
commit
7049252787
@ -0,0 +1,38 @@ |
||||
use crate::error::unexpected::{self, Mappable}; |
||||
use crate::origin; |
||||
|
||||
use hex::ToHex; |
||||
use serde::{Deserialize, Serialize}; |
||||
use sha2::{Digest, Sha256}; |
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] |
||||
#[serde(tag = "protocol")] |
||||
pub enum SettingsServeProtocol { |
||||
#[serde(rename = "http")] |
||||
Http, |
||||
#[serde(rename = "https")] |
||||
Https, |
||||
} |
||||
|
||||
fn default_serve_protocols() -> Vec<SettingsServeProtocol> { |
||||
vec![SettingsServeProtocol::Http, SettingsServeProtocol::Https] |
||||
} |
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] |
||||
/// Defines how a domain will behave when it is accessed. These are configured by the owner of the
|
||||
/// domain during setup.
|
||||
pub struct Settings { |
||||
#[serde(flatten)] |
||||
pub origin_descr: origin::Descr, |
||||
|
||||
#[serde(default = "default_serve_protocols")] |
||||
pub serve_protocols: Vec<SettingsServeProtocol>, |
||||
} |
||||
|
||||
impl Settings { |
||||
pub fn hash(&self) -> Result<String, unexpected::Error> { |
||||
let mut h = Sha256::new(); |
||||
serde_json::to_writer(&mut h, self).or_unexpected()?; |
||||
Ok(h.finalize().encode_hex::<String>()) |
||||
} |
||||
} |
Loading…
Reference in new issue