Skip to main content

dockworker/
system.rs

1use serde::de::{self, Deserializer, Visitor};
2use serde::{Deserialize, Serialize};
3use std::fmt;
4use std::path::PathBuf;
5
6struct NumToBoolVisitor;
7
8impl<'de> Visitor<'de> for NumToBoolVisitor {
9    type Value = bool;
10
11    fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
12        formatter.write_str("0 or 1 or true or false")
13    }
14
15    fn visit_bool<E>(self, value: bool) -> Result<Self::Value, E>
16    where
17        E: de::Error,
18    {
19        Ok(value)
20    }
21
22    fn visit_i64<E>(self, value: i64) -> Result<Self::Value, E>
23    where
24        E: de::Error,
25    {
26        Ok(value != 0)
27    }
28
29    fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E>
30    where
31        E: de::Error,
32    {
33        Ok(value != 0)
34    }
35}
36
37fn num_to_bool<'de, D>(deserializer: D) -> Result<bool, D::Error>
38where
39    D: Deserializer<'de>,
40{
41    deserializer.deserialize_any(NumToBoolVisitor)
42}
43
44/// response of /info
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[allow(non_snake_case)]
47pub struct SystemInfo {
48    pub ID: String,
49    pub Containers: u64,
50    // pub ContainersRunning: u64,
51    // pub ContainersPaused: u64,
52    // pub ContainersStopped: u64,
53    pub Images: u64,
54    pub Driver: String,
55    pub DriverStatus: Vec<(String, String)>,
56    pub DockerRootDir: PathBuf,
57    #[serde(deserialize_with = "num_to_bool")]
58    pub MemoryLimit: bool,
59    #[serde(deserialize_with = "num_to_bool")]
60    pub SwapLimit: bool,
61    // pub KernelMemory: bool,
62    // pub OomKillDisable: bool,
63    #[serde(deserialize_with = "num_to_bool")]
64    pub IPv4Forwarding: bool,
65    // pub BridgeNfIptables: bool,
66    // pub BridgeNfIp6tables: bool,
67    #[serde(deserialize_with = "num_to_bool")]
68    pub Debug: bool,
69    pub NFd: u64,
70    pub NGoroutines: u64,
71    // pub SystemTime: String,
72    // pub LoggingDriver: String,
73    // pub CgroupDriver: String,
74    pub NEventsListener: u64,
75    // pub KernelVersion: String,
76    pub OperatingSystem: String,
77    // pub OSType: String,
78    // pub Architecture: String,
79    pub NCPU: u64,
80    pub MemTotal: u64,
81    pub IndexServerAddress: String,
82    // pub HttpProxy: String,
83    // pub HttpsProxy: String,
84    // pub NoProxy: String,
85    // pub Name: String,
86    pub Labels: Option<Vec<String>>,
87    // pub ServerVersion: String,
88}
89
90/// Type of the response of `/auth` api
91#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
92#[allow(non_snake_case)]
93pub struct AuthToken {
94    Status: String,
95    IdentityToken: String,
96}
97
98impl AuthToken {
99    #[allow(dead_code)]
100    pub fn token(&self) -> String {
101        self.IdentityToken.clone()
102    }
103}