aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2025-08-11 22:02:37 +0200
committerrtkay123 <dev@kanjala.com>2025-08-11 22:02:37 +0200
commit9c850d6c4d0ed468709c2eb5340d7b64bbb9aa68 (patch)
tree4aa550323df9372e367932fa6bccf40db9aeac26
parent1ffebf617e651e1008d13bcc8cfbe79c9323c48b (diff)
downloadwarden-9c850d6c4d0ed468709c2eb5340d7b64bbb9aa68.tar.bz2
warden-9c850d6c4d0ed468709c2eb5340d7b64bbb9aa68.zip
build(config): create crate
-rw-r--r--Cargo.lock20
-rw-r--r--contrib/docker-compose/init-db/init.sql1
-rw-r--r--crates/configuration/Cargo.toml34
-rw-r--r--crates/configuration/src/main.rs3
-rw-r--r--lib/warden-core/Cargo.toml1
-rw-r--r--lib/warden-core/build.rs32
-rw-r--r--lib/warden-core/src/configuration.rs3
-rw-r--r--lib/warden-core/src/google.rs1
-rw-r--r--lib/warden-core/src/lib.rs8
-rw-r--r--proto/configuration/routing.proto60
10 files changed, 154 insertions, 9 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c306dc6..cb439a4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3819,6 +3819,26 @@ dependencies = [
]
[[package]]
+name = "warden-config"
+version = "0.1.0"
+dependencies = [
+ "anyhow",
+ "clap",
+ "config",
+ "metrics",
+ "metrics-exporter-prometheus",
+ "serde",
+ "serde_json",
+ "sqlx",
+ "time",
+ "tokio",
+ "tonic 0.14.0",
+ "tracing",
+ "warden-core",
+ "warden-stack",
+]
+
+[[package]]
name = "warden-core"
version = "0.1.0"
dependencies = [
diff --git a/contrib/docker-compose/init-db/init.sql b/contrib/docker-compose/init-db/init.sql
index ca01766..888884d 100644
--- a/contrib/docker-compose/init-db/init.sql
+++ b/contrib/docker-compose/init-db/init.sql
@@ -1,2 +1,3 @@
create database transaction_history;
create database pseudonyms;
+create database configuration;
diff --git a/crates/configuration/Cargo.toml b/crates/configuration/Cargo.toml
new file mode 100644
index 0000000..86f6923
--- /dev/null
+++ b/crates/configuration/Cargo.toml
@@ -0,0 +1,34 @@
+[package]
+name = "warden-config"
+version = "0.1.0"
+edition = "2024"
+license.workspace = true
+homepage.workspace = true
+documentation.workspace = true
+description.workspace = true
+
+[dependencies]
+anyhow.workspace = true
+clap = { workspace = true, features = ["derive"] }
+config = { workspace = true, features = ["convert-case", "toml"] }
+metrics.workspace = true
+metrics-exporter-prometheus.workspace = true
+serde = { workspace = true, features = ["derive"] }
+serde_json.workspace = true
+sqlx = { workspace = true, features = [
+ "macros",
+ "migrate",
+ "postgres",
+ "runtime-tokio",
+ "time",
+ "tls-rustls",
+] }
+time.workspace = true
+tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal"] }
+tonic.workspace = true
+tracing.workspace = true
+warden-core = { workspace = true, features = ["configuration", "serde-time"] }
+
+[dependencies.warden-stack]
+workspace = true
+features = ["api", "cache", "postgres", "opentelemetry-tonic", "tracing-loki"]
diff --git a/crates/configuration/src/main.rs b/crates/configuration/src/main.rs
new file mode 100644
index 0000000..e7a11a9
--- /dev/null
+++ b/crates/configuration/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Hello, world!");
+}
diff --git a/lib/warden-core/Cargo.toml b/lib/warden-core/Cargo.toml
index 759e018..dc9e83e 100644
--- a/lib/warden-core/Cargo.toml
+++ b/lib/warden-core/Cargo.toml
@@ -23,6 +23,7 @@ utoipa = { workspace = true, optional = true }
[features]
default = []
+configuration = ["dep:prost", "dep:tonic", "dep:tonic-types", "dep:tonic-prost"]
message = ["dep:prost", "dep:tonic", "dep:tonic-types", "dep:tonic-prost"]
pseudonyms = ["dep:prost", "dep:tonic", "dep:tonic-types", "dep:tonic-prost"]
serde = ["dep:serde", "serde/derive", "dep:serde_json"]
diff --git a/lib/warden-core/build.rs b/lib/warden-core/build.rs
index 37c1c68..9088fd7 100644
--- a/lib/warden-core/build.rs
+++ b/lib/warden-core/build.rs
@@ -1,12 +1,14 @@
-#[cfg(any(feature = "message", feature = "pseudonyms"))]
+#[cfg(any(feature = "message", feature = "pseudonyms", feature = "configuration"))]
enum Entity {
#[cfg(feature = "message")]
ISO2022,
#[cfg(feature = "pseudonyms")]
Pseudonyms,
+ #[cfg(feature = "configuration")]
+ Configuration,
}
-#[cfg(any(feature = "message", feature = "pseudonyms"))]
+#[cfg(any(feature = "message", feature = "pseudonyms", feature = "configuration"))]
impl Entity {
fn protos(&self) -> Vec<&'static str> {
let mut res: Vec<&'static str> = vec![];
@@ -16,6 +18,14 @@ impl Entity {
vec!["proto/warden_message.proto"]
}
+
+ #[cfg(feature = "configuration")]
+ fn configuration_protos() -> Vec<&'static str> {
+ vec![
+ "proto/configuration/routing.proto",
+ ]
+ }
+
#[cfg(feature = "pseudonyms")]
fn pseudonyms_protos() -> Vec<&'static str> {
vec![
@@ -35,6 +45,10 @@ impl Entity {
Entity::Pseudonyms => {
res.extend(pseudonyms_protos());
}
+ #[cfg(feature = "configuration")]
+ Entity::Configuration => {
+ res.extend(configuration_protos());
+ }
}
res
}
@@ -43,7 +57,7 @@ impl Entity {
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=../../proto");
- #[cfg(any(feature = "message", feature = "pseudonyms"))]
+ #[cfg(any(feature = "message", feature = "pseudonyms", feature = "configuration"))]
let mut protos: Vec<&'static str> = vec![];
#[cfg(feature = "message")]
@@ -52,13 +66,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(feature = "pseudonyms")]
protos.extend(Entity::Pseudonyms.protos());
- #[cfg(any(feature = "message", feature = "pseudonyms"))]
+ #[cfg(feature = "configuration")]
+ protos.extend(Entity::Configuration.protos());
+
+ #[cfg(any(feature = "message", feature = "pseudonyms", feature = "configuration"))]
build_proto(&protos)?;
+
Ok(())
}
-#[cfg(any(feature = "message", feature = "pseudonyms"))]
+#[cfg(any(feature = "message", feature = "pseudonyms", feature = "configuration"))]
fn build_proto(protos: &[&str]) -> Result<(), Box<dyn std::error::Error>> {
let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
@@ -82,7 +100,7 @@ fn build_proto(protos: &[&str]) -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
-#[cfg(all(feature = "serde", any(feature = "pseudonyms", feature = "message")))]
+#[cfg(all(feature = "serde", any(feature = "pseudonyms", feature = "message", feature = "configuration")))]
fn add_serde(config: tonic_prost_build::Builder) -> tonic_prost_build::Builder {
let config = config.type_attribute(
".",
@@ -98,7 +116,7 @@ fn add_serde(config: tonic_prost_build::Builder) -> tonic_prost_build::Builder {
config
}
-#[cfg(all(feature = "openapi", any(feature = "message", feature = "pseudonyms")))]
+#[cfg(all(feature = "openapi", any(feature = "message", feature = "pseudonyms", feature = "configuration")))]
fn add_openapi(config: tonic_prost_build::Builder) -> tonic_prost_build::Builder {
config.type_attribute(".", "#[derive(utoipa::ToSchema)]")
}
diff --git a/lib/warden-core/src/configuration.rs b/lib/warden-core/src/configuration.rs
new file mode 100644
index 0000000..da589c2
--- /dev/null
+++ b/lib/warden-core/src/configuration.rs
@@ -0,0 +1,3 @@
+pub mod routing {
+ tonic::include_proto!("configuration.routing");
+}
diff --git a/lib/warden-core/src/google.rs b/lib/warden-core/src/google.rs
index 30accb9..88f7037 100644
--- a/lib/warden-core/src/google.rs
+++ b/lib/warden-core/src/google.rs
@@ -5,6 +5,7 @@ pub mod protobuf {
include!(concat!(env!("OUT_DIR"), "/google.protobuf.rs"));
}
+#[cfg(any(feature = "message", feature = "pseudonyms"))]
pub mod r#type {
include!(concat!(env!("OUT_DIR"), "/google.r#type.rs"));
}
diff --git a/lib/warden-core/src/lib.rs b/lib/warden-core/src/lib.rs
index d039516..c97bef3 100644
--- a/lib/warden-core/src/lib.rs
+++ b/lib/warden-core/src/lib.rs
@@ -7,12 +7,12 @@
)]
/// Type file descriptor
-#[cfg(any(feature = "message", feature = "pseudonyms"))]
+#[cfg(any(feature = "message", feature = "pseudonyms", feature = "configuration"))]
pub const FILE_DESCRIPTOR_SET: &[u8] = tonic::include_file_descriptor_set!("warden_descriptor");
/// Google well known types
#[allow(missing_docs)]
-#[cfg(any(feature = "message", feature = "pseudonyms"))]
+#[cfg(any(feature = "message", feature = "pseudonyms", feature = "configuration"))]
pub mod google;
/// ISO20022 messages
@@ -29,3 +29,7 @@ pub mod message;
#[allow(missing_docs)]
#[cfg(feature = "pseudonyms")]
pub mod pseudonyms;
+
+#[allow(missing_docs)]
+#[cfg(feature = "configuration")]
+pub mod configuration;
diff --git a/proto/configuration/routing.proto b/proto/configuration/routing.proto
new file mode 100644
index 0000000..b254fd2
--- /dev/null
+++ b/proto/configuration/routing.proto
@@ -0,0 +1,60 @@
+syntax = "proto3";
+
+package configuration.routing;
+
+import "google/protobuf/empty.proto";
+import "google/protobuf/timestamp.proto";
+
+message RoutingConfiguration {
+ bool active = 1;
+ optional string name = 2;
+ string version = 3;
+ repeated Message messages = 4;
+ google.protobuf.Timestamp created_at = 5;
+ google.protobuf.Timestamp updated_at = 6;
+}
+
+message Message {
+ string id = 1;
+ string version = 2;
+ string tx_tp = 3;
+ repeated Typology typologies = 4;
+}
+
+message Typology {
+ string id = 1;
+ string version = 2;
+ repeated Rule rules = 3;
+}
+
+message Rule {
+ string id = 1;
+ optional string version = 2;
+}
+
+message RoutingConfigurationRequest {
+ string id = 1;
+}
+
+message UpdateRoutingRequest {
+ string id = 1;
+ RoutingConfiguration configuration = 2;
+}
+
+message GetActiveRoutingResponse {
+ optional RoutingConfiguration configuration = 1;
+}
+
+message DeleteConfigurationRequest {
+ string id = 1;
+}
+
+service QueryRouting {
+ rpc GetActiveRoutingConfiguration (google.protobuf.Empty) returns (GetActiveRoutingResponse);
+}
+
+service MutateRouting {
+ rpc CreateRoutingConfiguration (RoutingConfiguration) returns (RoutingConfiguration);
+ rpc UpdateRoutingConfiguration (UpdateRoutingRequest) returns (RoutingConfiguration);
+ rpc DeleteRoutingConfiguration (DeleteConfigurationRequest) returns (RoutingConfiguration);
+}