summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/management/BUILD.bazel10
-rw-r--r--common/management/nova.management.v1alpha.proto2
-rw-r--r--common/management/rpc/BUILD.bazel25
-rw-r--r--common/management/rpc/nova.management.rpc.v1alpha.proto3
-rw-r--r--common/rust/cargo/BUILD.bazel85
-rw-r--r--common/rust/src/config.rs8
-rw-r--r--common/rust/src/lib.rs6
-rw-r--r--common/rust/src/nats.rs1
-rw-r--r--common/rust/src/payloads.rs23
9 files changed, 145 insertions, 18 deletions
diff --git a/common/management/BUILD.bazel b/common/management/BUILD.bazel
index 2e8f53f..fd2bdeb 100644
--- a/common/management/BUILD.bazel
+++ b/common/management/BUILD.bazel
@@ -1,24 +1,24 @@
-load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
+load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
proto_library(
- name = "nova_ratelimit_v1_proto",
+ name = "nova_management_v1alpha_proto",
srcs = ["nova.management.v1alpha.proto"],
visibility = ["//visibility:public"],
)
go_proto_library(
- name = "nova_ratelimit_v1_go_proto",
+ name = "nova_management_v1alpha_go_proto",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "github.com/discordnova/nova/common/management",
- proto = ":nova_ratelimit_v1_proto",
+ proto = ":nova_management_v1alpha_proto",
visibility = ["//visibility:public"],
)
go_library(
name = "management",
- embed = [":nova_ratelimit_v1_go_proto"],
+ embed = [":nova_management_v1alpha_go_proto"],
importpath = "github.com/discordnova/nova/common/management",
visibility = ["//visibility:public"],
)
diff --git a/common/management/nova.management.v1alpha.proto b/common/management/nova.management.v1alpha.proto
index f07aa9b..d0d6baf 100644
--- a/common/management/nova.management.v1alpha.proto
+++ b/common/management/nova.management.v1alpha.proto
@@ -1,5 +1,5 @@
syntax = "proto3";
-package nova.ratelimit.v1;
+package nova.management.v1alpha;
message Empty {}
diff --git a/common/management/rpc/BUILD.bazel b/common/management/rpc/BUILD.bazel
new file mode 100644
index 0000000..ed06686
--- /dev/null
+++ b/common/management/rpc/BUILD.bazel
@@ -0,0 +1,25 @@
+load("@rules_proto//proto:defs.bzl", "proto_library")
+load("@io_bazel_rules_go//go:def.bzl", "go_library")
+load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
+
+proto_library(
+ name = "v1alpha_proto",
+ srcs = ["nova.management.rpc.v1alpha.proto"],
+ visibility = ["//visibility:public"],
+ deps = ["//common/management:nova_management_v1alpha_proto"],
+)
+
+go_proto_library(
+ name = "v1alpha_go_proto",
+ importpath = "github.com/discordnova/nova/common/management/rpc",
+ proto = ":v1alpha_proto",
+ visibility = ["//visibility:public"],
+ deps = ["//common/management"],
+)
+
+go_library(
+ name = "rpc",
+ embed = [":v1alpha_go_proto"],
+ importpath = "github.com/discordnova/nova/common/management/rpc",
+ visibility = ["//visibility:public"],
+)
diff --git a/common/management/rpc/nova.management.rpc.v1alpha.proto b/common/management/rpc/nova.management.rpc.v1alpha.proto
index e3b5c96..1ec0168 100644
--- a/common/management/rpc/nova.management.rpc.v1alpha.proto
+++ b/common/management/rpc/nova.management.rpc.v1alpha.proto
@@ -1,4 +1,5 @@
syntax = "proto3";
import "common/management/nova.management.v1alpha.proto";
-package nova.management.rpc.v1alpha; \ No newline at end of file
+package nova.management.rpc.v1alpha;
+
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
+}