diff options
| author | Matthieu <matthieu@developershouse.xyz> | 2021-10-08 14:48:39 +0400 |
|---|---|---|
| committer | Matthieu <matthieu@developershouse.xyz> | 2021-10-08 14:48:39 +0400 |
| commit | a02b25f235ba6eff33c6fd965c97071d5f112b6d (patch) | |
| tree | 2fc18dbde0f1b2403cb83cf1adb6aa5e66cef7b2 /common/rust | |
| parent | 308df902d6ff8656cea13e61e5277890d5ad4f08 (diff) | |
changes in the proto names, and new spec for nats
Diffstat (limited to 'common/rust')
| -rw-r--r-- | common/rust/cargo/BUILD.bazel | 85 | ||||
| -rw-r--r-- | common/rust/src/config.rs | 8 | ||||
| -rw-r--r-- | common/rust/src/lib.rs | 6 | ||||
| -rw-r--r-- | common/rust/src/nats.rs | 1 | ||||
| -rw-r--r-- | common/rust/src/payloads.rs | 23 |
5 files changed, 112 insertions, 11 deletions
diff --git a/common/rust/cargo/BUILD.bazel b/common/rust/cargo/BUILD.bazel new file mode 100644 index 0000000..f92a2e9 --- /dev/null +++ b/common/rust/cargo/BUILD.bazel @@ -0,0 +1,85 @@ +""" +@generated +cargo-raze generated Bazel file. + +DO NOT EDIT! Replaced on runs of cargo-raze +""" + +package(default_visibility = ["//visibility:public"]) + +licenses([ + "notice", # See individual crates for specific licenses +]) + +# Aliased targets +alias( + name = "config", + actual = "@raze__config__0_11_0//:config", + tags = [ + "cargo-raze", + "manual", + ], +) + +alias( + name = "hyper", + actual = "@raze__hyper__0_14_12//:hyper", + tags = [ + "cargo-raze", + "manual", + ], +) + +alias( + name = "log", + actual = "@raze__log__0_4_14//:log", + tags = [ + "cargo-raze", + "manual", + ], +) + +alias( + name = "nats", + actual = "@raze__nats__0_15_2//:nats", + tags = [ + "cargo-raze", + "manual", + ], +) + +alias( + name = "pretty_env_logger", + actual = "@raze__pretty_env_logger__0_4_0//:pretty_env_logger", + tags = [ + "cargo-raze", + "manual", + ], +) + +alias( + name = "prometheus", + actual = "@raze__prometheus__0_12_0//:prometheus", + tags = [ + "cargo-raze", + "manual", + ], +) + +alias( + name = "serde", + actual = "@raze__serde__1_0_130//:serde", + tags = [ + "cargo-raze", + "manual", + ], +) + +alias( + name = "tokio", + actual = "@raze__tokio__1_11_0//:tokio", + tags = [ + "cargo-raze", + "manual", + ], +) diff --git a/common/rust/src/config.rs b/common/rust/src/config.rs index d4437a9..3dcd72c 100644 --- a/common/rust/src/config.rs +++ b/common/rust/src/config.rs @@ -1,9 +1,12 @@ use std::env; - use config::{Config, ConfigError, Environment, File, Source}; use log::info; use serde::Deserialize; +/// Settings<T> is the base structure for all the nova's component config +/// you can specify a type T and the name of the component. the "config" +/// field will be equals to the key named after the given component name +/// and will be of type T #[derive(Debug, Deserialize, Clone)] #[serde(bound(deserialize = "T: Deserialize<'de> + std::default::Default + Clone"))] pub struct Settings<T> { @@ -13,10 +16,13 @@ pub struct Settings<T> { pub nats: crate::nats::NatsConfiguration, } +/// impl<T> Settings<T> where T: Deserialize<'static> + std::default::Default + Clone, { + /// Initializes a new configuration like the other components of nova + /// And starts the prometheus metrics server if needed. pub fn new(service_name: &str) -> Result<Settings<T>, ConfigError> { let mut default = Config::default(); // this file my be shared with all the components diff --git a/common/rust/src/lib.rs b/common/rust/src/lib.rs index 943d7cc..1125f5a 100644 --- a/common/rust/src/lib.rs +++ b/common/rust/src/lib.rs @@ -1,7 +1,7 @@ -/// This crate contains shared code in all the rust projects -/// It contains utilities such as monitoring, logging and more. +/// This crate is all the utilities shared by the nova rust projects +/// It includes loging, config and protocols. pub mod config; pub mod monitoring; pub mod nats; pub mod payloads; -pub mod error;
\ No newline at end of file +pub mod error; diff --git a/common/rust/src/nats.rs b/common/rust/src/nats.rs index 59b480c..437a857 100644 --- a/common/rust/src/nats.rs +++ b/common/rust/src/nats.rs @@ -24,7 +24,6 @@ pub struct NatsConfiguration { host: String, } -/// impl Into<Connection> for NatsConfiguration { fn into(self) -> Connection { let mut options = Options::new(); diff --git a/common/rust/src/payloads.rs b/common/rust/src/payloads.rs index 6eb35c8..2da70e3 100644 --- a/common/rust/src/payloads.rs +++ b/common/rust/src/payloads.rs @@ -1,15 +1,26 @@ use serde::{Deserialize, Serialize}; +use std::fmt::Debug; -/// Payload send to the nova cache queues -#[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(bound(deserialize = "T: Deserialize<'de> + std::default::Default + Clone"))] + + +/// Data structure sent to the cache component +/// by the gateway & webhook. +#[derive(Serialize, Deserialize, Debug)] +#[serde(bound(deserialize = "T: Deserialize<'de> + Debug"))] pub struct CachePayload<T> { + + #[serde(rename = "tr")] pub tracing: Tracing, - pub data: T + + #[serde(rename = "d")] + pub data: T, + + #[serde(rename = "o")] + pub operation: String, } -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug)] pub struct Tracing { pub node_id: String, pub span: Option<String> -}
\ No newline at end of file +} |
