diff --git a/Cargo.lock b/Cargo.lock index 31b39aad..8c1057c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,6 +45,21 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "0.6.12" @@ -357,6 +372,19 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "serde", + "windows-targets 0.52.0", +] + [[package]] name = "clap" version = "4.5.1" @@ -1219,6 +1247,29 @@ dependencies = [ "tokio", ] +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "idna" version = "0.5.0" @@ -1410,9 +1461,12 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +dependencies = [ + "serde", +] [[package]] name = "matchers" @@ -2008,6 +2062,7 @@ name = "ratings" version = "0.0.3" dependencies = [ "axum 0.7.4", + "chrono", "cucumber", "dotenvy", "envy", @@ -2016,6 +2071,7 @@ dependencies = [ "http-body 0.4.6", "hyper 0.14.28", "jsonwebtoken", + "log", "once_cell", "prost", "prost-types", @@ -3491,6 +3547,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index 52eacff0..320732f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,8 @@ tower = "0.4" tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } axum = "0.7.4" +chrono = { version = "0.4.34", default-features = false, features = ["std", "clock", "serde"] } +log = { version = "0.4.21", features = ["serde"] } [build-dependencies] tonic-build = { version = "0.11", features = ["prost"] } diff --git a/src/features/admin/api_version/interface.rs b/src/features/admin/api_version/interface.rs new file mode 100644 index 00000000..96740fb3 --- /dev/null +++ b/src/features/admin/api_version/interface.rs @@ -0,0 +1,21 @@ +//! The public interface of this endpoint + +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; + +/// The request for getting the API Version, this is empty because +/// Any query will return the given response (authentication happens +// at a higher layer). +#[derive(Copy, Clone, Deserialize, Serialize)] +pub struct ApiVersionRequest; + +#[derive(Clone, Serialize, Deserialize)] +/// The response returning the API Version information. +pub struct ApiVersionResponse { + /// The current API Version + version: String, + /// The current commit sha + commit: String, + /// The timestamp this build was done at + build: DateTime, +} diff --git a/src/features/admin/api_version/mod.rs b/src/features/admin/api_version/mod.rs new file mode 100644 index 00000000..8d6c5524 --- /dev/null +++ b/src/features/admin/api_version/mod.rs @@ -0,0 +1,3 @@ +//! Contains API endpoints for getting build target information for the currently running service + +pub mod interface; diff --git a/src/features/admin/log_level/get/interface.rs b/src/features/admin/log_level/get/interface.rs new file mode 100644 index 00000000..7afabaf4 --- /dev/null +++ b/src/features/admin/log_level/get/interface.rs @@ -0,0 +1,17 @@ +//! The public interface for getting the log level + +use log::Level; +use serde::{Deserialize, Serialize}; + +/// The request for getting the log level, empty because +/// the request is empty. +#[derive(Copy, Clone, Deserialize, Serialize)] +pub struct GetLogLevelRequest; + +/// The response for getting the leg level, [`tracing`] doesn't implement +/// [`Serialize`] so we use the one from [`log`] as an intermediary. +#[derive(Copy, Clone, Deserialize, Serialize)] +pub struct GetLogLevelResponse { + /// The log level we currently are at + level: Level, +} diff --git a/src/features/admin/log_level/get/mod.rs b/src/features/admin/log_level/get/mod.rs new file mode 100644 index 00000000..61e161e1 --- /dev/null +++ b/src/features/admin/log_level/get/mod.rs @@ -0,0 +1,3 @@ +//! The interface for setting the current log level + +mod interface; diff --git a/src/features/admin/log_level/mod.rs b/src/features/admin/log_level/mod.rs new file mode 100644 index 00000000..a96c3be7 --- /dev/null +++ b/src/features/admin/log_level/mod.rs @@ -0,0 +1,4 @@ +//! Contains API endpoints for manipulating the log level + +pub mod get; +pub mod set; diff --git a/src/features/admin/log_level/set/interface.rs b/src/features/admin/log_level/set/interface.rs new file mode 100644 index 00000000..46736027 --- /dev/null +++ b/src/features/admin/log_level/set/interface.rs @@ -0,0 +1,16 @@ +//! The public interface for defining setting the log level + +use log::Level; +use serde::{Deserialize, Serialize}; + +/// The request for setting the log level +#[derive(Copy, Clone, Serialize, Deserialize)] +pub struct SetLogLevelRequest { + /// The current log level, [`tracing`] doesn't implement [`serde`] so + // we convert between the two internally. + level: Level, +} + +/// The response for setting the log level, essentially nothing but an Ack +#[derive(Copy, Clone, Serialize, Deserialize)] +pub struct SetLogLevelResponse; diff --git a/src/features/admin/log_level/set/mod.rs b/src/features/admin/log_level/set/mod.rs new file mode 100644 index 00000000..d9818fef --- /dev/null +++ b/src/features/admin/log_level/set/mod.rs @@ -0,0 +1,3 @@ +//! The endpoint for getting the current log level + +mod interface; diff --git a/src/features/admin/mod.rs b/src/features/admin/mod.rs new file mode 100644 index 00000000..d9725973 --- /dev/null +++ b/src/features/admin/mod.rs @@ -0,0 +1,4 @@ +//! Contains API endpoints for administrative features + +mod api_version; +mod log_level; diff --git a/src/features/mod.rs b/src/features/mod.rs index ec0fc264..66469f94 100644 --- a/src/features/mod.rs +++ b/src/features/mod.rs @@ -1,5 +1,6 @@ //! Contains various feature implementations for the ratings backend. +pub mod admin; pub mod chart; pub mod common; pub mod pb;