diff --git a/src/commons/api/admin.rs b/src/commons/api/admin.rs index 5bcd8dbc..950c97eb 100644 --- a/src/commons/api/admin.rs +++ b/src/commons/api/admin.rs @@ -11,6 +11,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use rpki::cert::Cert; use rpki::crypto::Signer; use rpki::uri; +use rpki::x509::Time; use crate::commons::api::ca::{ResourceSet, TrustAnchorLocator}; use crate::commons::api::rrdp::PublishElement; @@ -578,6 +579,31 @@ impl fmt::Display for UpdateChildRequest { } } +//------------ ServerInfo ---------------------------------------------------- + +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +pub struct ServerInfo { + version: String, + started: i64, +} + +impl ServerInfo { + pub fn new(version: &str, started: Time) -> Self { + ServerInfo { + version: version.to_string(), + started: started.timestamp(), + } + } + + pub fn version(&self) -> &str { + &self.version + } + + pub fn started(&self) -> i64 { + self.started + } +} + //------------ Tests --------------------------------------------------------- #[cfg(test)] diff --git a/src/daemon/endpoints.rs b/src/daemon/endpoints.rs index 566629c0..07abf12e 100644 --- a/src/daemon/endpoints.rs +++ b/src/daemon/endpoints.rs @@ -193,6 +193,11 @@ pub fn metrics(server: web::Data) -> HttpResponse { HttpResponse::Ok().body(res) } +// Return general server info +pub fn server_info(server: web::Data) -> HttpResponse { + render_json(server.read().server_info()) +} + //------------ Admin: Publishers --------------------------------------------- pub fn repo_stats(server: web::Data) -> HttpResponse { diff --git a/src/daemon/http/server.rs b/src/daemon/http/server.rs index 0e342567..18349315 100644 --- a/src/daemon/http/server.rs +++ b/src/daemon/http/server.rs @@ -52,6 +52,7 @@ pub fn start(config: &Config) -> Result<(), Error> { .wrap(middleware::Logger::default()) .route("/health", get().to(endpoints::health)) .route("/metrics", get().to(metrics)) + .route("/stats/info", get().to(server_info)) .route("/stats/repo", get().to(repo_stats)) .route("/stats/cas", get().to(cas_stats)) // API end-points diff --git a/src/daemon/krillserver.rs b/src/daemon/krillserver.rs index c82b5973..b349f108 100644 --- a/src/daemon/krillserver.rs +++ b/src/daemon/krillserver.rs @@ -6,15 +6,17 @@ use std::thread; use bytes::Bytes; use chrono::Duration; + use rpki::cert::Cert; use rpki::uri; +use rpki::x509::Time; use crate::commons::api::{ AddChildRequest, AllCertAuthIssues, CaRepoDetails, CertAuthHistory, CertAuthInfo, CertAuthInit, CertAuthIssues, CertAuthList, CertAuthStats, ChildCaInfo, ChildHandle, CurrentRepoState, Handle, ListReply, ParentCaContact, ParentCaReq, ParentHandle, PublishDelta, PublisherDetails, PublisherHandle, RepoInfo, RepositoryContact, RepositoryUpdate, RoaDefinition, - RoaDefinitionUpdates, TaCertDetails, UpdateChildRequest, + RoaDefinitionUpdates, ServerInfo, TaCertDetails, UpdateChildRequest, }; use crate::commons::error::Error; use crate::commons::remote::rfc8183; @@ -62,6 +64,9 @@ pub struct KrillServer { // Responsible for background tasks, e.g. re-publishing #[allow(dead_code)] // just need to keep this in scope scheduler: Scheduler, + + // Time this server was started + started: Time, } /// # Set up and initialisation @@ -154,12 +159,17 @@ impl KrillServer { pubserver, caserver, scheduler, + started: Time::now(), }) } pub fn service_base_uri(&self) -> &uri::Https { &self.service_uri } + + pub fn server_info(&self) -> ServerInfo { + ServerInfo::new(KRILL_VERSION, self.started) + } } /// # Authentication