Browse Source

Forbid unknown configuration fields

If a configuration field has a typo in its name, the configuration
should show an error message instead of silently ignoring this field,
which could create unwanted behavior.
pull/5/head
Rodolphe Breard 6 years ago
parent
commit
5e252d8b17
  1. 8
      acmed/src/config.rs

8
acmed/src/config.rs

@ -9,6 +9,7 @@ use std::io::prelude::*;
use std::path::Path; use std::path::Path;
#[derive(Deserialize)] #[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Config { pub struct Config {
pub global: Option<GlobalOptions>, pub global: Option<GlobalOptions>,
pub endpoint: Vec<Endpoint>, pub endpoint: Vec<Endpoint>,
@ -110,6 +111,7 @@ impl Config {
} }
#[derive(Deserialize)] #[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct GlobalOptions { pub struct GlobalOptions {
pub accounts_directory: Option<String>, pub accounts_directory: Option<String>,
pub certificates_directory: Option<String>, pub certificates_directory: Option<String>,
@ -122,6 +124,7 @@ pub struct GlobalOptions {
} }
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Endpoint { pub struct Endpoint {
pub name: String, pub name: String,
pub url: String, pub url: String,
@ -129,6 +132,7 @@ pub struct Endpoint {
} }
#[derive(Deserialize)] #[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Hook { pub struct Hook {
pub name: String, pub name: String,
#[serde(rename = "type")] #[serde(rename = "type")]
@ -163,18 +167,21 @@ pub enum HookType {
} }
#[derive(Deserialize)] #[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Group { pub struct Group {
pub name: String, pub name: String,
pub hooks: Vec<String>, pub hooks: Vec<String>,
} }
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Account { pub struct Account {
pub name: String, pub name: String,
pub email: String, pub email: String,
} }
#[derive(Deserialize)] #[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Certificate { pub struct Certificate {
pub account: String, pub account: String,
pub endpoint: String, pub endpoint: String,
@ -271,6 +278,7 @@ impl Certificate {
} }
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Domain { pub struct Domain {
pub challenge: String, pub challenge: String,
pub dns: String, pub dns: String,

Loading…
Cancel
Save