summaryrefslogtreecommitdiffstats
path: root/src/config/mod.rs
blob: 3c48023c3a450790a38e9b5a47b1e7bf4ed5f810 (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use std::path::PathBuf;
use std::fmt::Debug;
use std::ops::Deref;

use anyhow::Result;
use getset::Getters;
use getset::CopyGetters;
use serde::Deserialize;

use crate::phase::PhaseName;
use crate::util::EnvironmentVariableName;
use crate::util::docker::ImageName;

#[derive(Debug, Getters, Deserialize)]
pub struct NotValidatedConfiguration {
    #[getset(get = "pub")]
    repository: PathBuf,

    #[getset(get = "pub")]
    docker: DockerConfig,

    #[getset(get = "pub")]
    containers: ContainerConfig,

    #[getset(get = "pub")]
    available_phases: Vec<PhaseName>,
}

impl NotValidatedConfiguration {
    pub fn validate(self) -> Result<Configuration> {
        Ok(Configuration(self)) // TODO: Implement properly
    }
}

#[derive(Debug)]
pub struct Configuration(NotValidatedConfiguration);

impl Deref for Configuration {
    type Target = NotValidatedConfiguration;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}


#[derive(Debug, Getters, Deserialize)]
pub struct DockerConfig {

    #[getset(get = "pub")]
    images: Vec<ImageName>,

    #[getset(get = "pub")]
    endpoints: Vec<Endpoint>,
}

#[derive(Debug, Getters, Deserialize)]
pub struct ContainerConfig {
    #[getset(get = "pub")]
    allowed_env: Vec<EnvironmentVariableName>,
}


#[derive(Debug, Getters, CopyGetters, Deserialize)]
pub struct Endpoint {
    #[getset(get = "pub")]
    name: String,

    #[getset(get = "pub")]
    uri: String,

    #[getset(get = "pub")]
    endpoint_type: EndpointType,

    /// Relative speed to other endpoints
    ///
    /// So if you have two servers, one with 12 cores and one with 24, you want to set "1" for the
    /// first and "2" for the second (or "12" for the first and "24" for the second - the ratio is
    /// the thing here)!
    #[getset(get_copy = "pub")]
    speed: usize,

    /// Maximum number of jobs which are allowed on this endpoint
    #[getset(get_copy = "pub")]
    maxjobs: usize,
}

#[derive(Debug, Deserialize, Eq, PartialEq)]
pub enum EndpointType {
    Socket,
    Http,
}