paas_api/
status.rs

1use crate::{CURRENT_PROTOCOL_VERSION, MIN_SUPPORTED_VERSION};
2use chrono::{DateTime, Utc};
3use semver::Version;
4use serde::{Deserialize, Serialize};
5
6fn default_protocol_version() -> Version {
7    Version::parse(CURRENT_PROTOCOL_VERSION).expect("Invalid CURRENT_PROTOCOL_VERSION")
8}
9fn default_min_version() -> Version {
10    Version::parse(MIN_SUPPORTED_VERSION).expect("Invalid MIN_SUPPORTED_VERSION")
11}
12#[derive(Serialize, Deserialize, Debug)]
13/// Information about the API protocol
14pub struct VersionInfo {
15    #[serde(default = "default_protocol_version")]
16    pub protocol_version: Version,
17    #[serde(default = "default_min_version")]
18    pub min_supported_version: Version,
19}
20impl Default for VersionInfo {
21    fn default() -> Self {
22        Self {
23            protocol_version: default_protocol_version(),
24            min_supported_version: default_min_version(),
25        }
26    }
27}
28impl VersionInfo {
29    pub fn new() -> Self {
30        Self::default()
31    }
32    pub fn is_compatible_with(&self, other: &VersionInfo) -> bool {
33        self.protocol_version >= other.min_supported_version
34            && other.protocol_version >= self.min_supported_version
35    }
36}
37
38/// Systems are identified by their system name
39pub type SystemId = String;
40
41#[derive(Serialize, Deserialize, Debug)]
42/// Status of a transcryptor
43pub struct StatusResponse {
44    pub system_id: SystemId,
45    pub timestamp: DateTime<Utc>,
46    pub version_info: VersionInfo,
47}