1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/// This error will be returned if an attempt to load Bulwark's configuration file fails.
#[derive(thiserror::Error, Debug)]
pub enum ConfigFileError {
    #[error(transparent)]
    IO(#[from] std::io::Error),
    #[error("config file not found: '{0}'")]
    ConfigNotFound(String),
    #[error("included config file not found: '{0}'")]
    IncludedConfigNotFound(String),
    #[error("included plugin file not found: '{0}'")]
    PluginNotFound(String),
    #[error(transparent)]
    Deserialization(#[from] toml::de::Error),
    #[error(transparent)]
    Validation(#[from] validator::ValidationError),
    #[error(transparent)]
    Validations(#[from] validator::ValidationErrors),
    #[error(transparent)]
    Resolution(#[from] ResolutionError),
    #[error(transparent)]
    InvalidRemoteUri(#[from] url::ParseError),
    #[error("uri must be https: '{0}'")]
    InsecureRemoteUri(String),
    #[error("missing parent: '{0}'")]
    MissingParent(String),
    #[error("invalid circular include: '{0}'")]
    CircularInclude(String),
    #[error("duplicate named plugin or preset: '{0}'")]
    Duplicate(String),
    #[error("invalid secret config: {0}")]
    InvalidSecretConfig(String),
    #[error("invalid plugin config: {0}")]
    InvalidPluginConfig(String),
    #[error("invalid resource config: {0}")]
    InvalidResourceConfig(String),
}

/// This error will be returned if an attempt to serialize a config structure fails.
#[derive(thiserror::Error, Debug)]
pub enum ConfigSerializationError {
    #[error(transparent)]
    Json(#[from] serde_json::Error),
}

/// This error will be returned if an attempt to convert a secret fails.
#[derive(thiserror::Error, Debug)]
pub enum SecretConversionError {
    #[error("one and only one of path or env_var must be set")]
    InvalidSecretLocation,
}

/// This error will be returned if an attempt to convert a plugin fails.
#[derive(thiserror::Error, Debug)]
pub enum PluginConversionError {
    #[error("one and only one of path, uri, or bytes must be set")]
    InvalidLocation,
    #[error(transparent)]
    InvalidRemoteUri(#[from] url::ParseError),
    #[error(transparent)]
    InvalidHexEncoding(#[from] hex::FromHexError),
}

/// This error will be returned if attempting to resolve references fails.
#[derive(thiserror::Error, Debug)]
pub enum ResolutionError {
    #[error("missing named plugin or preset: '{0}'")]
    Missing(String),
    #[error("invalid circular preset reference: '{0}'")]
    CircularPreset(String),
}