From 5ff136b6fb947a658264cb2e66ce58c2db96ebee Mon Sep 17 00:00:00 2001 From: Tim Bruijnzeels Date: Thu, 9 Sep 2021 15:28:15 +0200 Subject: [PATCH] Show suspended/active state for child CAs. (#656) --- src/commons/api/ca.rs | 37 +++++++++++++++++++++++++++++++++++-- src/daemon/ca/child.rs | 18 ++---------------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/commons/api/ca.rs b/src/commons/api/ca.rs index 35648fa1..1cf24dcd 100644 --- a/src/commons/api/ca.rs +++ b/src/commons/api/ca.rs @@ -141,23 +141,55 @@ impl From<&IdCert> for IdCertPem { } } +//------------ ChildState ---------------------------------------------------- + +#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[allow(clippy::large_enum_variant)] +#[serde(rename_all = "snake_case")] +pub enum ChildState { + Active, + Suspended, +} + +impl Default for ChildState { + fn default() -> Self { + ChildState::Active + } +} + +impl fmt::Display for ChildState { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match &self { + ChildState::Active => "active", + ChildState::Suspended => "suspended", + } + .fmt(f) + } +} + //------------ ChildCaInfo --------------------------------------------------- /// This type represents information about a child CA that is shared through the API. #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] pub struct ChildCaInfo { + state: ChildState, id_cert: IdCertPem, entitled_resources: ResourceSet, } impl ChildCaInfo { - pub fn new(id_cert: IdCertPem, entitled_resources: ResourceSet) -> Self { + pub fn new(state: ChildState, id_cert: IdCertPem, entitled_resources: ResourceSet) -> Self { ChildCaInfo { + state, id_cert, entitled_resources, } } + pub fn state(&self) -> ChildState { + self.state + } + pub fn id_cert(&self) -> &IdCertPem { &self.id_cert } @@ -171,7 +203,8 @@ impl fmt::Display for ChildCaInfo { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { writeln!(f, "{}", self.id_cert.pem())?; writeln!(f, "SHA256 hash of PEM encoded certificate: {}", self.id_cert.hash())?; - writeln!(f, "resources: {}", self.entitled_resources) + writeln!(f, "resources: {}", self.entitled_resources)?; + writeln!(f, "state: {}", self.state) } } diff --git a/src/daemon/ca/child.rs b/src/daemon/ca/child.rs index 4e71ab81..00bb1fa9 100644 --- a/src/daemon/ca/child.rs +++ b/src/daemon/ca/child.rs @@ -6,7 +6,7 @@ use rpki::repository::crypto::KeyIdentifier; use rpki::repository::x509::Time; use crate::commons::api::{ - ChildCaInfo, ChildHandle, IssuedCert, ResourceClassName, ResourceSet, SuspendedCert, UnsuspendedCert, + ChildCaInfo, ChildHandle, ChildState, IssuedCert, ResourceClassName, ResourceSet, SuspendedCert, UnsuspendedCert, }; use crate::commons::crypto::IdCert; use crate::commons::error::Error; @@ -25,20 +25,6 @@ pub enum UsedKeyState { Revoked, } -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] -#[allow(clippy::large_enum_variant)] -#[serde(rename_all = "snake_case")] -pub enum ChildState { - Active, - Suspended, -} - -impl Default for ChildState { - fn default() -> Self { - ChildState::Active - } -} - //------------ ChildInfo --------------------------------------------------- /// Contains information about a child CA needed by a parent [CertAuth](ca.CertAuth). @@ -135,7 +121,7 @@ impl ChildDetails { impl From for ChildCaInfo { fn from(details: ChildDetails) -> Self { - ChildCaInfo::new((&details.id_cert).into(), details.resources) + ChildCaInfo::new(details.state, (&details.id_cert).into(), details.resources) } }