From a7b07434110b80e0e3b42931cf37cd38c263277e Mon Sep 17 00:00:00 2001 From: paulobressan Date: Tue, 9 Jan 2024 21:06:31 -0300 Subject: [PATCH 01/23] chore: adjusted handlers --- operator/src/controller.rs | 14 +--- operator/src/handlers/auth.rs | 126 ++++++++++++++----------------- operator/src/handlers/gateway.rs | 89 +++++++++++----------- operator/src/helpers/mod.rs | 2 +- 4 files changed, 105 insertions(+), 126 deletions(-) diff --git a/operator/src/controller.rs b/operator/src/controller.rs index c9698e5..ae45c5d 100644 --- a/operator/src/controller.rs +++ b/operator/src/controller.rs @@ -1,7 +1,7 @@ use futures::StreamExt; use kube::{ runtime::{controller::Action, watcher::Config as WatcherConfig, Controller}, - Api, Client, CustomResource, ResourceExt, + Api, Client, CustomResource, }; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -10,7 +10,6 @@ use tracing::{error, info, instrument}; use crate::{ auth::handle_auth, - build_private_dns_service_name, gateway::{handle_http_route, handle_reference_grant}, Error, Metrics, Network, Result, State, }; @@ -57,14 +56,9 @@ impl Context { } async fn reconcile(crd: Arc, ctx: Arc) -> Result { - let client = ctx.client.clone(); - let namespace = crd.namespace().unwrap(); - - let private_dns_service_name = - build_private_dns_service_name(&crd.spec.network, &crd.spec.version); - handle_reference_grant(client.clone(), &namespace, &crd, &private_dns_service_name).await?; - handle_http_route(client.clone(), &namespace, &crd, &private_dns_service_name).await?; - handle_auth(client.clone(), &namespace, &crd).await?; + handle_reference_grant(ctx.client.clone(), &crd).await?; + handle_http_route(ctx.client.clone(), &crd).await?; + handle_auth(ctx.client.clone(), &crd).await?; Ok(Action::await_change()) } diff --git a/operator/src/handlers/auth.rs b/operator/src/handlers/auth.rs index de1781c..4baf44c 100644 --- a/operator/src/handlers/auth.rs +++ b/operator/src/handlers/auth.rs @@ -20,40 +20,36 @@ use crate::{ kong_plugin, patch_resource, patch_resource_status, Error, OgmiosPort, OgmiosPortStatus, }; -pub async fn handle_auth( - client: Client, - namespace: &str, - resource: &OgmiosPort, -) -> Result<(), Error> { - handle_auth_secret(client.clone(), namespace, resource).await?; - handle_auth_plugin(client.clone(), namespace, resource).await?; - handle_acl_secret(client.clone(), namespace, resource).await?; - handle_acl_plugin(client.clone(), namespace, resource).await?; - handle_consumer(client.clone(), namespace, resource).await?; +pub async fn handle_auth(client: Client, crd: &OgmiosPort) -> Result<(), Error> { + handle_auth_secret(client.clone(), crd).await?; + handle_auth_plugin(client.clone(), crd).await?; + + handle_acl_secret(client.clone(), crd).await?; + handle_acl_plugin(client.clone(), crd).await?; + + handle_consumer(client.clone(), crd).await?; Ok(()) } -async fn handle_auth_secret( - client: Client, - namespace: &str, - resource: &OgmiosPort, -) -> Result<(), Error> { - let name = get_auth_name(&resource.name_any()); - let api_key = generate_api_key(&name, namespace).await?; +async fn handle_auth_secret(client: Client, crd: &OgmiosPort) -> Result<(), Error> { + let namespace = crd.namespace().unwrap(); + + let name = get_auth_name(&crd.name_any()); + let api_key = generate_api_key(&name, &namespace).await?; let ogmios_port = OgmiosPort::api_resource(); - let api = Api::::namespaced(client.clone(), namespace); + let api = Api::::namespaced(client.clone(), &namespace); - let secret = auth_secret(&name, &api_key, resource.clone()); + let secret = auth_secret(&name, &api_key, crd.clone()); let result = api.get_opt(&name).await?; if result.is_some() { - info!(resource = resource.name_any(), "Updating auth secret"); + info!(resource = crd.name_any(), "Updating auth secret"); let patch_params = PatchParams::default(); api.patch(&name, &patch_params, &Patch::Merge(secret)) .await?; } else { - info!(resource = resource.name_any(), "Creating auth secret"); + info!(resource = crd.name_any(), "Creating auth secret"); let post_params = PostParams::default(); api.create(&post_params, &secret).await?; } @@ -65,55 +61,51 @@ async fn handle_auth_secret( patch_resource_status( client.clone(), - namespace, + &namespace, ogmios_port, - &resource.name_any(), + &crd.name_any(), serde_json::to_value(status)?, ) .await?; Ok(()) } -async fn handle_auth_plugin( - client: Client, - namespace: &str, - resource: &OgmiosPort, -) -> Result<(), Error> { - let name = get_auth_name(&resource.name_any()); +async fn handle_auth_plugin(client: Client, crd: &OgmiosPort) -> Result<(), Error> { + let namespace = crd.namespace().unwrap(); + + let name = get_auth_name(&crd.name_any()); let kong_plugin = kong_plugin(); - let result = get_resource(client.clone(), namespace, &kong_plugin, &name).await?; - let (metadata, data, raw) = auth_plugin(resource.clone())?; + let result = get_resource(client.clone(), &namespace, &kong_plugin, &name).await?; + let (metadata, data, raw) = auth_plugin(crd.clone())?; if result.is_some() { - info!(resource = resource.name_any(), "Updating auth plugin"); - patch_resource(client.clone(), namespace, kong_plugin, &name, raw).await?; + info!(resource = crd.name_any(), "Updating auth plugin"); + patch_resource(client.clone(), &namespace, kong_plugin, &name, raw).await?; } else { - info!(resource = resource.name_any(), "Creating auth plugin"); - create_resource(client.clone(), namespace, kong_plugin, metadata, data).await?; + info!(resource = crd.name_any(), "Creating auth plugin"); + create_resource(client.clone(), &namespace, kong_plugin, metadata, data).await?; } Ok(()) } -async fn handle_acl_secret( - client: Client, - namespace: &str, - resource: &OgmiosPort, -) -> Result<(), Error> { - let name = get_acl_name(&resource.name_any()); +async fn handle_acl_secret(client: Client, crd: &OgmiosPort) -> Result<(), Error> { + let namespace = crd.namespace().unwrap(); - let api = Api::::namespaced(client.clone(), namespace); + let name = get_acl_name(&crd.name_any()); - let secret = acl_secret(&name, resource.clone()); + let api = Api::::namespaced(client.clone(), &namespace); + + let secret = acl_secret(&name, crd.clone()); let result = api.get_opt(&name).await?; if result.is_some() { - info!(resource = resource.name_any(), "Updating acl secret"); + info!(resource = crd.name_any(), "Updating acl secret"); let patch_params = PatchParams::default(); api.patch(&name, &patch_params, &Patch::Merge(secret)) .await?; } else { - info!(resource = resource.name_any(), "Creating acl secret"); + info!(resource = crd.name_any(), "Creating acl secret"); let post_params = PostParams::default(); api.create(&post_params, &secret).await?; } @@ -121,44 +113,40 @@ async fn handle_acl_secret( Ok(()) } -async fn handle_acl_plugin( - client: Client, - namespace: &str, - resource: &OgmiosPort, -) -> Result<(), Error> { - let name = get_acl_name(&resource.name_any()); +async fn handle_acl_plugin(client: Client, crd: &OgmiosPort) -> Result<(), Error> { + let namespace = crd.namespace().unwrap(); + + let name = get_acl_name(&crd.name_any()); let kong_plugin = kong_plugin(); - let result = get_resource(client.clone(), namespace, &kong_plugin, &name).await?; - let (metadata, data, raw) = acl_plugin(resource.clone())?; + let result = get_resource(client.clone(), &namespace, &kong_plugin, &name).await?; + let (metadata, data, raw) = acl_plugin(crd.clone())?; if result.is_some() { - info!(resource = resource.name_any(), "Updating acl plugin"); - patch_resource(client.clone(), namespace, kong_plugin, &name, raw).await?; + info!(resource = crd.name_any(), "Updating acl plugin"); + patch_resource(client.clone(), &namespace, kong_plugin, &name, raw).await?; } else { - info!(resource = resource.name_any(), "Creating acl plugin"); - create_resource(client.clone(), namespace, kong_plugin, metadata, data).await?; + info!(resource = crd.name_any(), "Creating acl plugin"); + create_resource(client.clone(), &namespace, kong_plugin, metadata, data).await?; } Ok(()) } -async fn handle_consumer( - client: Client, - namespace: &str, - resource: &OgmiosPort, -) -> Result<(), Error> { - let name = get_auth_name(&resource.name_any()); +async fn handle_consumer(client: Client, crd: &OgmiosPort) -> Result<(), Error> { + let namespace = crd.namespace().unwrap(); + + let name = get_auth_name(&crd.name_any()); let kong_consumer = kong_consumer(); - let result = get_resource(client.clone(), namespace, &kong_consumer, &name).await?; - let (metadata, data, raw) = consumer(resource.clone())?; + let result = get_resource(client.clone(), &namespace, &kong_consumer, &name).await?; + let (metadata, data, raw) = consumer(crd.clone())?; if result.is_some() { - info!(resource = resource.name_any(), "Updating consumer"); - patch_resource(client.clone(), namespace, kong_consumer, &name, raw).await?; + info!(resource = crd.name_any(), "Updating consumer"); + patch_resource(client.clone(), &namespace, kong_consumer, &name, raw).await?; } else { - info!(resource = resource.name_any(), "Creating consumer"); - create_resource(client.clone(), namespace, kong_consumer, metadata, data).await?; + info!(resource = crd.name_any(), "Creating consumer"); + create_resource(client.clone(), &namespace, kong_consumer, metadata, data).await?; } Ok(()) } diff --git a/operator/src/handlers/gateway.rs b/operator/src/handlers/gateway.rs index 6de8ad1..935015d 100644 --- a/operator/src/handlers/gateway.rs +++ b/operator/src/handlers/gateway.rs @@ -5,30 +5,29 @@ use tracing::info; use crate::{ create_resource, get_acl_name, get_auth_name, get_config, get_resource, http_route, - patch_resource, patch_resource_status, reference_grant, Error, OgmiosPort, OgmiosPortStatus, + ogmios_service_name, patch_resource, patch_resource_status, reference_grant, Error, OgmiosPort, + OgmiosPortStatus, }; -pub async fn handle_http_route( - client: Client, - namespace: &str, - resource: &OgmiosPort, - private_dns_service_name: &str, -) -> Result<(), Error> { - let name = format!("ogmios-{}", resource.name_any()); - let host_name = build_host(&resource.name_any(), &namespace_to_slug(namespace)); +pub async fn handle_http_route(client: Client, crd: &OgmiosPort) -> Result<(), Error> { + let namespace = crd.namespace().unwrap(); + let ogmios_service = ogmios_service_name(&crd.spec.network, &crd.spec.version); + + let name = format!("ogmios-{}", crd.name_any()); + let host_name = build_host(&crd.name_any(), &namespace_to_slug(&namespace)); let http_route = http_route(); let ogmios_port = OgmiosPort::api_resource(); - let result = get_resource(client.clone(), namespace, &http_route, &name).await?; + let result = get_resource(client.clone(), &namespace, &http_route, &name).await?; - let (metadata, data, raw) = route(&name, &host_name, resource, private_dns_service_name)?; + let (metadata, data, raw) = build_route(&name, &host_name, crd, &ogmios_service)?; if result.is_some() { - info!(resource = resource.name_any(), "Updating http route"); - patch_resource(client.clone(), namespace, http_route, &name, raw).await?; + info!(resource = crd.name_any(), "Updating http route"); + patch_resource(client.clone(), &namespace, http_route, &name, raw).await?; } else { - info!(resource = resource.name_any(), "Creating http route"); - create_resource(client.clone(), namespace, http_route, metadata, data).await?; + info!(resource = crd.name_any(), "Creating http route"); + create_resource(client.clone(), &namespace, http_route, metadata, data).await?; } let status = OgmiosPortStatus { @@ -37,31 +36,29 @@ pub async fn handle_http_route( }; patch_resource_status( client.clone(), - namespace, + &namespace, ogmios_port, - &resource.name_any(), + &crd.name_any(), serde_json::to_value(status)?, ) .await?; Ok(()) } -pub async fn handle_reference_grant( - client: Client, - namespace: &str, - resource: &OgmiosPort, - private_dns_service_name: &str, -) -> Result<(), Error> { - let name = format!("{}-{}-http", namespace, resource.name_any()); +pub async fn handle_reference_grant(client: Client, crd: &OgmiosPort) -> Result<(), Error> { + let namespace = crd.namespace().unwrap(); + let ogmios_service = ogmios_service_name(&crd.spec.network, &crd.spec.version); + + let name = format!("{}-{}-http", namespace, crd.name_any()); let reference_grant = reference_grant(); let config = get_config(); let result = get_resource(client.clone(), &config.namespace, &reference_grant, &name).await?; - let (metadata, data, raw) = grant(&name, private_dns_service_name, namespace)?; + let (metadata, data, raw) = build_grant(&name, &ogmios_service, &namespace)?; if result.is_some() { - info!(resource = resource.name_any(), "Updating reference grant"); + info!(resource = crd.name_any(), "Updating reference grant"); patch_resource( client.clone(), &config.namespace, @@ -71,7 +68,7 @@ pub async fn handle_reference_grant( ) .await?; } else { - info!(resource = resource.name_any(), "Creating reference grant"); + info!(resource = crd.name_any(), "Creating reference grant"); // we need to get the deserialized payload create_resource( client.clone(), @@ -85,24 +82,11 @@ pub async fn handle_reference_grant( Ok(()) } -fn build_host(name: &str, project_slug: &str) -> String { - let config = get_config(); - - format!( - "{}-{}.{}.{}", - name, project_slug, config.ingress_class, config.dns_zone - ) -} - -fn namespace_to_slug(namespace: &str) -> String { - namespace.split_once('-').unwrap().1.to_string() -} - -fn route( +fn build_route( name: &str, hostname: &str, owner: &OgmiosPort, - private_dns_service_name: &str, + ogmios_service: &str, ) -> Result<(ObjectMeta, JsonValue, JsonValue), Error> { let config = get_config(); let http_route = http_route(); @@ -146,7 +130,7 @@ fn route( "backendRefs": [ { "kind": "Service", - "name": private_dns_service_name, + "name": ogmios_service, "port": config.http_port.parse::()?, "namespace": config.namespace } @@ -166,9 +150,9 @@ fn route( Ok((metadata, data, raw)) } -fn grant( +fn build_grant( name: &str, - private_dns_service_name: &str, + ogmios_service: &str, project_namespace: &str, ) -> Result<(ObjectMeta, JsonValue, JsonValue), Error> { let reference_grant = reference_grant(); @@ -191,7 +175,7 @@ fn grant( { "group": "", "kind": "Service", - "name": private_dns_service_name, + "name": ogmios_service, }, ], } @@ -206,3 +190,16 @@ fn grant( Ok((metadata, data, raw)) } + +fn build_host(name: &str, project_slug: &str) -> String { + let config = get_config(); + + format!( + "{}-{}.{}.{}", + name, project_slug, config.ingress_class, config.dns_zone + ) +} + +fn namespace_to_slug(namespace: &str) -> String { + namespace.split_once('-').unwrap().1.to_string() +} diff --git a/operator/src/helpers/mod.rs b/operator/src/helpers/mod.rs index a1bb53d..5701af0 100644 --- a/operator/src/helpers/mod.rs +++ b/operator/src/helpers/mod.rs @@ -116,6 +116,6 @@ pub fn get_acl_name(name: &str) -> String { format!("ogmios-acl-{name}") } -pub fn build_private_dns_service_name(network: &Network, version: &u8) -> String { +pub fn ogmios_service_name(network: &Network, version: &u8) -> String { format!("ogmios-{network}-{version}") } From 0ef6c32b8425a25c6de6f78e4ff1dd7ece1ccd17 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Wed, 7 Feb 2024 15:23:39 -0300 Subject: [PATCH 02/23] feat: added proxy --- proxy/.gitignore | 3 + proxy/Cargo.lock | 1463 ++++++++++++++++++++++++++ proxy/Cargo.toml | 26 + proxy/Dockerfile | 15 + proxy/examples/README.md | 59 ++ proxy/examples/docker-compose.yml | 33 + proxy/examples/proxy.toml | 30 + proxy/src/config.rs | 114 ++ proxy/src/main.rs | 43 + proxy/src/metrics.rs | 100 ++ proxy/src/plugins/auth_dmtr.rs | 59 ++ proxy/src/plugins/host_key_header.rs | 46 + proxy/src/plugins/mod.rs | 38 + proxy/src/plugins/rate_limit.rs | 28 + proxy/src/proxy.rs | 220 ++++ proxy/src/utils.rs | 15 + 16 files changed, 2292 insertions(+) create mode 100644 proxy/.gitignore create mode 100644 proxy/Cargo.lock create mode 100644 proxy/Cargo.toml create mode 100644 proxy/Dockerfile create mode 100644 proxy/examples/README.md create mode 100644 proxy/examples/docker-compose.yml create mode 100644 proxy/examples/proxy.toml create mode 100644 proxy/src/config.rs create mode 100644 proxy/src/main.rs create mode 100644 proxy/src/metrics.rs create mode 100644 proxy/src/plugins/auth_dmtr.rs create mode 100644 proxy/src/plugins/host_key_header.rs create mode 100644 proxy/src/plugins/mod.rs create mode 100644 proxy/src/plugins/rate_limit.rs create mode 100644 proxy/src/proxy.rs create mode 100644 proxy/src/utils.rs diff --git a/proxy/.gitignore b/proxy/.gitignore new file mode 100644 index 0000000..50cd4e8 --- /dev/null +++ b/proxy/.gitignore @@ -0,0 +1,3 @@ +/target +fake-api +.env* \ No newline at end of file diff --git a/proxy/Cargo.lock b/proxy/Cargo.lock new file mode 100644 index 0000000..8a9fe60 --- /dev/null +++ b/proxy/Cargo.lock @@ -0,0 +1,1463 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "async-trait" +version = "0.1.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "backtrace" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +dependencies = [ + "serde", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "config" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7328b20597b53c2454f0b1919720c25c7339051c02b72b7e05409e00b14132be" +dependencies = [ + "async-trait", + "convert_case", + "json5", + "lazy_static", + "nom", + "pathdiff", + "ron", + "rust-ini", + "serde", + "serde_json", + "toml", + "yaml-rust", +] + +[[package]] +name = "const-random" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aaf16c9c2c612020bcfd042e170f6e32de9b9d75adb5277cdbbd2e2c8c8299a" +dependencies = [ + "const-random-macro", +] + +[[package]] +name = "const-random-macro" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" +dependencies = [ + "getrandom", + "once_cell", + "tiny-keccak", +] + +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "data-encoding" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "dlv-list" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "442039f5147480ba31067cb00ada1adae6892028e40e45fc5de7b7df6dcc1b5f" +dependencies = [ + "const-random", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-core", + "futures-macro", + "futures-sink", + "futures-task", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "h2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d308f63daf4181410c242d34c11f928dcb3aa105852019e043c9d1f4e4368a" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "hermit-abi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d3d0e0f38255e7fa3cf31335b3a56f05febd18025f4db5ef7a0cfb4f8da651f" + +[[package]] +name = "http" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5aa53871fc917b1a9ed87b683a5d86db645e23acb32c2e0785a353e522fb75" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "tokio", + "want", +] + +[[package]] +name = "hyper-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +dependencies = [ + "equivalent", + "hashbrown 0.14.3", +] + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "json5" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1" +dependencies = [ + "pest", + "pest_derive", + "serde", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "leaky-bucket" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eb491abd89e9794d50f93c8db610a29509123e3fbbc9c8c67a528e9391cd853" +dependencies = [ + "parking_lot", + "tokio", + "tracing", +] + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "memchr" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" +dependencies = [ + "libc", + "wasi", + "windows-sys", +] + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "ordered-multimap" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ed8acf08e98e744e5384c8bc63ceb0364e68a6854187221c18df61c4797690e" +dependencies = [ + "dlv-list", + "hashbrown 0.13.2", +] + +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "pathdiff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pest" +version = "2.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "219c0dcc30b6a27553f9cc242972b67f75b60eb0db71f0b5462f38b058c41546" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22e1288dbd7786462961e69bfd4df7848c1e37e8b74303dbdab82c3a9cdd2809" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1381c29a877c6d34b8c176e734f35d7f7f5b3adaefe940cb4d1bb7af94678e2e" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0934d6907f148c22a3acbda520c7eed243ad7487a30f51f6ce52b58b7077a8a" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + +[[package]] +name = "pin-project" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0302c4a0442c456bd56f841aee5c3bfd17967563f6fadc9ceb9f9c23cf3807e0" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "prometheus" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "449811d15fbdf5ceb5c1144416066429cf82316e2ec8ce0c1f6f8a02e7bbcf8c" +dependencies = [ + "cfg-if", + "fnv", + "lazy_static", + "memchr", + "parking_lot", + "protobuf", + "thiserror", +] + +[[package]] +name = "protobuf" +version = "2.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" + +[[package]] +name = "proxy" +version = "0.1.0" +dependencies = [ + "async-trait", + "bytes", + "config", + "futures-channel", + "futures-util", + "http-body-util", + "hyper", + "hyper-util", + "leaky-bucket", + "prometheus", + "regex", + "serde", + "thiserror", + "tokio", + "tokio-tungstenite", + "tracing", + "tracing-subscriber", + "url", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "regex" +version = "1.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "ron" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" +dependencies = [ + "base64", + "bitflags 2.4.2", + "serde", + "serde_derive", +] + +[[package]] +name = "rust-ini" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e2a3bcec1f113553ef1c88aae6c020a369d03d55b58de9869a0908930385091" +dependencies = [ + "cfg-if", + "ordered-multimap", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "ryu" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.196" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.196" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.112" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d1bd37ce2324cf3bf85e5a25f96eb4baf0d5aa6eba43e7ae8958870c4ec48ed" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_spanned" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +dependencies = [ + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" + +[[package]] +name = "socket2" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.35.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-tungstenite" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" +dependencies = [ + "futures-util", + "log", + "tokio", + "tungstenite", +] + +[[package]] +name = "tokio-util" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + +[[package]] +name = "toml" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6a4b9e8023eb94392d3dca65d717c53abc5dad49c07cb65bb8fcd87115fa325" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "nu-ansi-term", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "tungstenite" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" +dependencies = [ + "byteorder", + "bytes", + "data-encoding", + "http", + "httparse", + "log", + "rand", + "sha1", + "thiserror", + "url", + "utf-8", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "winnow" +version = "0.5.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7cad8365489051ae9f054164e459304af2e7e9bb407c958076c8bf4aef52da5" +dependencies = [ + "memchr", +] + +[[package]] +name = "yaml-rust" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +dependencies = [ + "linked-hash-map", +] diff --git a/proxy/Cargo.toml b/proxy/Cargo.toml new file mode 100644 index 0000000..8d5de78 --- /dev/null +++ b/proxy/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "proxy" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +async-trait = "0.1.77" +bytes = "1.5.0" +config = { version = "0.14.0", features = ["toml"] } +futures-channel = "0.3.30" +futures-util = "0.3.30" +http-body-util = "0.1.0" +hyper = { version = "1.1.0", features = ["full"] } +hyper-util = { version = "0.1.3", features = ["full"] } +leaky-bucket = "1.0.1" +prometheus = "0.13.3" +regex = "1.10.3" +serde = { version = "1.0.196", features = ["derive"] } +thiserror = "1.0.56" +tokio = { version = "1.35.1", features = ["full"] } +tokio-tungstenite = "0.21.0" +tracing = "0.1.40" +tracing-subscriber = "0.3.18" +url = "2.5.0" diff --git a/proxy/Dockerfile b/proxy/Dockerfile new file mode 100644 index 0000000..d5be2f6 --- /dev/null +++ b/proxy/Dockerfile @@ -0,0 +1,15 @@ +FROM rust:1.74-slim-buster as build + +WORKDIR /app + +COPY ./Cargo.lock ./Cargo.lock +COPY ./Cargo.toml ./Cargo.toml +COPY ./src ./src + +RUN cargo build --release + +FROM rust:1.74-slim-buster + +COPY --from=build /app/target/release/proxy . + +CMD ["./proxy"] \ No newline at end of file diff --git a/proxy/examples/README.md b/proxy/examples/README.md new file mode 100644 index 0000000..ec3178d --- /dev/null +++ b/proxy/examples/README.md @@ -0,0 +1,59 @@ +# Proxy Example + +execute docker compose up to run proxy container and a mock api, after that it's possible to request /headers of the mock api + + +in the proxy.toml file some plugins is enabled. + +## Metrics + +To access prometheus metrics, open the link below + +``` +http://0.0.0.0:5000/metrics +``` + +## Http + +the key on the host will be extract by the plugin and inject in the header. + +```bash +curl http://dmtr_kupo1d988zmt0g4skjdt6xdxkg5zp23f55ttpxfmsemy6fa.0.0.0.0.nip.io/headers +``` + +## Websocket + +Below a script to access the mock api using websocket. + +```nodejs +const WebSocket = require("ws"); + +const ws = new WebSocket("ws://0.0.0.0:80", { + headers: { + "dmtr-api-key": `dmtr_kupo1d988zmt0g4skjdt6xdxkg5zp23f55ttpxfmsemy6fa`, + }, +}); +let interval = 0; + +ws.on("open", () => { + console.log("Connected to WebSocket server"); + + interval = setInterval(() => { + ws.send(`Hello, WebSocket server! ${Math.random()}`); + }, 10); +}); + +ws.on("message", (message) => { + console.log(`Received message from server: ${message}`); +}); + +ws.on("close", () => { + console.log("Connection to WebSocket server closed"); + clearInterval(interval); +}); + +ws.on("error", (err) => { + console.error(err); +}); + +``` \ No newline at end of file diff --git a/proxy/examples/docker-compose.yml b/proxy/examples/docker-compose.yml new file mode 100644 index 0000000..485a1ce --- /dev/null +++ b/proxy/examples/docker-compose.yml @@ -0,0 +1,33 @@ +version: "3.8" + +networks: + proxy-network: + driver: bridge + +services: + proxy: + container_name: proxy + build: ../ + networks: + - proxy-network + ports: + - "80:80" + - "5000:5000" + deploy: + restart_policy: + condition: any + environment: + - PROXY_CONFIG_PATH=/opt/proxy/proxy.toml + volumes: + - ./proxy.toml:/opt/proxy/proxy.toml + + mock_api: + container_name: mock_api + image: paulobressan/mock-api:1.0.0 + networks: + - proxy-network + deploy: + restart_policy: + condition: any + environment: + - PORT=80 diff --git a/proxy/examples/proxy.toml b/proxy/examples/proxy.toml new file mode 100644 index 0000000..bb19e80 --- /dev/null +++ b/proxy/examples/proxy.toml @@ -0,0 +1,30 @@ +proxy_addr = "0.0.0.0:80" +prometheus_addr = "0.0.0.0:5000" + +[[routes]] +path = "/headers" +host = "mock_api" +port = 80 +protocol = "http" + +[[routes]] +path = "/" +host = "mock_api" +port = 80 +protocol = "websocket" + +[[http_plugins]] +type = "AuthDmtrPlugin" +priority = 1 + +[[http_plugins]] +type = "RateLimiterPlugin" +priority = 2 + +[[http_plugins]] +type = "HostKeyHeaderPlugin" +priority = 0 + +[[websocket_plugins]] +type = "RateLimiterPlugin" +priority = 0 \ No newline at end of file diff --git a/proxy/src/config.rs b/proxy/src/config.rs new file mode 100644 index 0000000..373041a --- /dev/null +++ b/proxy/src/config.rs @@ -0,0 +1,114 @@ +use std::{env, error::Error}; + +use serde::Deserialize; + +use crate::plugins::{ + auth_dmtr::AuthDmtrPlugin, host_key_header::HostKeyHeaderPlugin, rate_limit::RateLimiterPlugin, + Plugin, +}; + +#[derive(Debug, Clone, Deserialize)] +pub enum Protocol { + Http, + Websocket, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct Route { + pub path: String, + pub host: String, + pub port: u16, + pub protocol: Protocol, +} + +#[derive(Debug, Clone, Deserialize, PartialEq, Eq, PartialOrd, Ord)] +#[serde(tag = "type", content = "priority")] +pub enum HttpPluginsAvailable { + AuthDmtrPlugin(u16), + RateLimiterPlugin(u16), + HostKeyHeaderPlugin(u16), +} +impl HttpPluginsAvailable { + pub fn priority(&self) -> u16 { + match self { + HttpPluginsAvailable::AuthDmtrPlugin(priority) => priority.clone(), + HttpPluginsAvailable::RateLimiterPlugin(priority) => priority.clone(), + HttpPluginsAvailable::HostKeyHeaderPlugin(priority) => priority.clone(), + } + } +} + +#[derive(Debug, Clone, Deserialize, PartialEq, Eq, PartialOrd, Ord)] +#[serde(tag = "type", content = "priority")] +pub enum WebsocketPluginsAvailable { + RateLimiterPlugin(u16), +} +impl WebsocketPluginsAvailable { + pub fn priority(&self) -> u16 { + match self { + WebsocketPluginsAvailable::RateLimiterPlugin(priority) => priority.clone(), + } + } +} + +#[derive(Debug, Clone, Deserialize)] +pub struct Config { + pub proxy_addr: String, + pub prometheus_addr: String, + pub routes: Vec, + pub http_plugins: Vec, + pub websocket_plugins: Vec, +} + +impl Config { + pub fn try_new() -> Result> { + let path = env::var("PROXY_CONFIG_PATH").unwrap_or("proxy.toml".into()); + + let config = config::Config::builder() + .add_source(config::File::with_name(&path).required(true)) + .build()? + .try_deserialize()?; + + Ok(config) + } + + pub fn match_route(&self, path: &str) -> Option<&Route> { + self.routes.iter().find(|r| r.path.eq(path)) + } + + pub fn mount_plugins(&self) -> (Vec>, Vec>) { + let mut http_plugins: Vec> = Vec::new(); + + let mut config_http_plugins = self.http_plugins.clone(); + config_http_plugins.sort_by_key(|p| p.priority()); + + for plugin in config_http_plugins.iter() { + match plugin { + HttpPluginsAvailable::AuthDmtrPlugin(_) => { + http_plugins.push(Box::new(AuthDmtrPlugin::new())) + } + HttpPluginsAvailable::RateLimiterPlugin(_) => { + http_plugins.push(Box::new(RateLimiterPlugin::new())) + } + HttpPluginsAvailable::HostKeyHeaderPlugin(_) => { + http_plugins.push(Box::new(HostKeyHeaderPlugin::new())) + } + } + } + + let mut websocket_plugins: Vec> = Vec::new(); + + let mut config_websocket_plugins = self.websocket_plugins.clone(); + config_websocket_plugins.sort_by_key(|p| p.priority()); + + for plugin in self.websocket_plugins.iter() { + match plugin { + WebsocketPluginsAvailable::RateLimiterPlugin(_) => { + websocket_plugins.push(Box::new(RateLimiterPlugin::new())) + } + } + } + + (http_plugins, websocket_plugins) + } +} diff --git a/proxy/src/main.rs b/proxy/src/main.rs new file mode 100644 index 0000000..017b173 --- /dev/null +++ b/proxy/src/main.rs @@ -0,0 +1,43 @@ +use config::Config; +use futures_util::future; +use metrics::Metrics; +use prometheus::Registry; +use std::error::Error; +use std::sync::Arc; +use tokio::pin; +use tracing::Level; + +mod config; +mod metrics; +mod plugins; +mod proxy; +mod utils; + +#[derive(Debug, Clone)] +pub struct State { + config: Config, + metrics: Metrics, +} +impl State { + pub fn try_new() -> Result> { + let config = Config::try_new()?; + let metrics = Metrics::try_new(Registry::default())?; + + Ok(Self { config, metrics }) + } +} + +#[tokio::main] +async fn main() -> Result<(), Box> { + tracing_subscriber::fmt().with_max_level(Level::INFO).init(); + + let state = Arc::new(State::try_new()?); + + let metrics = metrics::start(state.clone()); + let proxy_server = proxy::start(state.clone()); + pin!(metrics, proxy_server); + + future::select(metrics, proxy_server).await; + + Ok(()) +} diff --git a/proxy/src/metrics.rs b/proxy/src/metrics.rs new file mode 100644 index 0000000..ef5d197 --- /dev/null +++ b/proxy/src/metrics.rs @@ -0,0 +1,100 @@ +use std::error::Error; +use std::sync::Arc; +use std::{net::SocketAddr, str::FromStr}; + +use hyper::server::conn::http1 as http1_server; +use hyper::{body::Incoming, service::service_fn, Method, Request, Response, StatusCode}; +use hyper_util::rt::TokioIo; +use prometheus::{opts, Encoder, IntCounterVec, Registry, TextEncoder}; +use tokio::net::TcpListener; +use tracing::{error, info}; + +use crate::utils::{full, ProxyResponse}; +use crate::State; + +#[derive(Debug, Clone)] +pub struct Metrics { + registry: Registry, + pub ws_total_frame: IntCounterVec, + pub http_total_request: IntCounterVec, +} + +impl Metrics { + pub fn try_new(registry: Registry) -> Result> { + let ws_total_frame = IntCounterVec::new( + opts!("proxy_ws_total_frame", "total of websocket frame",), + &["dmtr_key"], + ) + .unwrap(); + let http_total_request = IntCounterVec::new( + opts!("proxy_http_total_request", "total of http request",), + &["dmtr_key"], + ) + .unwrap(); + + registry.register(Box::new(ws_total_frame.clone()))?; + registry.register(Box::new(http_total_request.clone()))?; + + Ok(Metrics { + registry, + ws_total_frame, + http_total_request, + }) + } + + pub fn metrics_collected(&self) -> Vec { + self.registry.gather() + } + + pub fn count_ws_total_frame(&self, dmtr_key: &str) { + self.ws_total_frame.with_label_values(&[dmtr_key]).inc() + } + + pub fn count_http_total_request(&self, dmtr_key: &str) { + self.http_total_request.with_label_values(&[dmtr_key]).inc() + } +} + +async fn api_get_metrics(state: &State) -> Result { + let metrics = state.metrics.metrics_collected(); + let encoder = TextEncoder::new(); + let mut buffer = vec![]; + encoder.encode(&metrics, &mut buffer).unwrap(); + + let res = Response::builder().body(full(buffer)).unwrap(); + Ok(res) +} + +async fn routes_match(req: Request, state: Arc) -> Result { + match (req.method(), req.uri().path()) { + (&Method::GET, "/metrics") => api_get_metrics(&state).await, + _ => Ok(Response::builder() + .status(StatusCode::NOT_FOUND) + .body(full("Not Found")) + .unwrap()), + } +} + +pub async fn start(state: Arc) -> Result<(), Box> { + let addr = SocketAddr::from_str(&state.config.prometheus_addr)?; + let listener = TcpListener::bind(addr).await?; + info!(addr = state.config.prometheus_addr, "metrics listening"); + + loop { + let state = state.clone(); + + let (stream, _) = listener.accept().await.unwrap(); + let io = TokioIo::new(stream); + + tokio::task::spawn(async move { + let service = service_fn(move |req| routes_match(req, state.clone())); + + if let Err(err) = http1_server::Builder::new() + .serve_connection(io, service) + .await + { + error!(error = err.to_string(), "failed metrics server connection"); + } + }); + } +} diff --git a/proxy/src/plugins/auth_dmtr.rs b/proxy/src/plugins/auth_dmtr.rs new file mode 100644 index 0000000..5570106 --- /dev/null +++ b/proxy/src/plugins/auth_dmtr.rs @@ -0,0 +1,59 @@ +use std::collections::HashMap; + +use async_trait::async_trait; +use hyper::{body::Incoming, header::HeaderValue, Request, StatusCode}; + +use crate::utils::{full, DMTR_API_KEY, DMTR_PROJECT_ID}; + +use super::{Plugin, PluginError}; + +#[derive(Debug)] +pub struct DmtrConsumer { + project_id: String, +} + +pub struct AuthDmtrPlugin { + consumers: HashMap, +} +impl AuthDmtrPlugin { + pub fn new() -> Self { + let mut consumers = HashMap::new(); + + consumers.insert( + "dmtr_kupo1d988zmt0g4skjdt6xdxkg5zp23f55ttpxfmsemy6fa".into(), + DmtrConsumer { + project_id: "prj-xxxxx-xxxxx".into(), + }, + ); + + Self { consumers } + } +} + +#[async_trait] +impl Plugin for AuthDmtrPlugin { + fn execute<'a>( + &self, + req: &'a mut Request, + ) -> Result<&'a mut Request, PluginError> { + let dmtr_key = req + .headers() + .get(DMTR_API_KEY) + .map(|k| k.to_str().unwrap_or_default()) + .unwrap_or_default(); + + if let Some(costumer) = self.consumers.get(dmtr_key) { + req.headers_mut().insert( + DMTR_PROJECT_ID, + HeaderValue::from_str(&costumer.project_id).unwrap(), + ); + + return Ok(req); + } + + return Err(PluginError::Http( + StatusCode::UNAUTHORIZED, + full("Unauthorized"), + )); + } +} diff --git a/proxy/src/plugins/host_key_header.rs b/proxy/src/plugins/host_key_header.rs new file mode 100644 index 0000000..50963f8 --- /dev/null +++ b/proxy/src/plugins/host_key_header.rs @@ -0,0 +1,46 @@ +use async_trait::async_trait; +use hyper::{ + body::Incoming, + header::{HeaderValue, HOST}, + Request, +}; +use regex::Regex; + +use crate::utils::DMTR_API_KEY; + +use super::{Plugin, PluginError}; + +#[derive(Debug)] +pub struct HostKeyHeaderPlugin { + regex: Regex, +} +impl HostKeyHeaderPlugin { + pub fn new() -> Self { + let regex = Regex::new(r"(dmtr_[\w\d-]+)\.[\w+].+").unwrap(); + Self { regex } + } +} + +#[async_trait] +impl Plugin for HostKeyHeaderPlugin { + fn execute<'a>( + &self, + req: &'a mut Request, + ) -> Result<&'a mut Request, PluginError> { + let host = req + .headers() + .get(HOST) + .map(|k| k.to_str().unwrap_or_default()) + .unwrap_or_default() + .to_string(); + + if let Some(captures) = self.regex.captures(&host) { + let dmtr_key = captures.get(1).unwrap().as_str(); + + req.headers_mut() + .insert(DMTR_API_KEY, HeaderValue::from_str(dmtr_key).unwrap()); + } + + Ok(req) + } +} diff --git a/proxy/src/plugins/mod.rs b/proxy/src/plugins/mod.rs new file mode 100644 index 0000000..3e0ebea --- /dev/null +++ b/proxy/src/plugins/mod.rs @@ -0,0 +1,38 @@ +use std::fmt::Debug; + +use async_trait::async_trait; +use hyper::{body::Incoming, Request, StatusCode}; +use thiserror::Error; + +use crate::utils::Body; + +pub mod auth_dmtr; +pub mod host_key_header; +pub mod rate_limit; + +#[derive(Debug, Error)] +pub enum PluginError { + #[error("Http Error: {0}")] + Http(StatusCode, Body), +} + +#[async_trait] +pub trait Plugin: Send + Sync { + fn execute<'a>( + &self, + req: &'a mut Request, + ) -> Result<&'a mut Request, PluginError>; +} + +pub fn execute_plugins<'a>( + req: &'a mut Request, + plugins: &[Box], +) -> Result<&'a mut Request, PluginError> { + for plugin in plugins.iter() { + if let Err(err) = plugin.execute(req) { + return Err(err); + } + } + + Ok(req) +} diff --git a/proxy/src/plugins/rate_limit.rs b/proxy/src/plugins/rate_limit.rs new file mode 100644 index 0000000..93c3442 --- /dev/null +++ b/proxy/src/plugins/rate_limit.rs @@ -0,0 +1,28 @@ +use std::collections::HashMap; + +use async_trait::async_trait; +use hyper::{body::Incoming, Request}; +use leaky_bucket::RateLimiter; + +use super::{Plugin, PluginError}; + +pub struct RateLimiterPlugin { + consumers: HashMap, +} +impl RateLimiterPlugin { + pub fn new() -> Self { + let consumers = HashMap::new(); + Self { consumers } + } +} + +#[async_trait] +impl Plugin for RateLimiterPlugin { + fn execute<'a>( + &self, + req: &'a mut Request, + ) -> Result<&'a mut Request, PluginError> { + // self.consumers.insert("k".into(), RateLimiter::builder().build()); + Ok(req) + } +} diff --git a/proxy/src/proxy.rs b/proxy/src/proxy.rs new file mode 100644 index 0000000..b7dfbda --- /dev/null +++ b/proxy/src/proxy.rs @@ -0,0 +1,220 @@ +use futures_util::{future, stream::TryStreamExt, StreamExt}; +use http_body_util::{combinators::BoxBody, BodyExt}; +use hyper::body::Incoming; +use hyper::client::conn::http1 as http1_client; +use hyper::header::{HeaderValue, CONNECTION, SEC_WEBSOCKET_ACCEPT, SEC_WEBSOCKET_KEY, UPGRADE}; +use hyper::server::conn::http1 as http1_server; +use hyper::service::service_fn; +use hyper::{Method, Request, Response, StatusCode}; +use hyper_util::rt::TokioIo; +use std::net::SocketAddr; +use std::str::FromStr; +use std::sync::Arc; +use tokio::net::{TcpListener, TcpStream}; +use tokio_tungstenite::tungstenite::handshake::derive_accept_key; +use tokio_tungstenite::tungstenite::protocol::Role; +use tokio_tungstenite::{connect_async, WebSocketStream}; +use tracing::{error, info}; +use url::Url; + +use crate::config::{Protocol, Route}; +use crate::plugins::{execute_plugins, Plugin, PluginError}; +use crate::utils::{full, ProxyResponse, DMTR_PROJECT_ID}; +use crate::State; + +pub async fn start(state: Arc) -> Result<(), Box> { + let addr = SocketAddr::from_str(&state.config.proxy_addr)?; + let listener = TcpListener::bind(addr).await?; + info!(addr = state.config.proxy_addr, "proxy listening"); + + let (http_plugins, websocket_plugins) = state.config.mount_plugins(); + let http_plugins = Arc::new(http_plugins); + let websocket_plugins = Arc::new(websocket_plugins); + + loop { + let state = state.clone(); + let http_plugins = http_plugins.clone(); + let websocket_plugins = websocket_plugins.clone(); + + let (stream, _) = listener.accept().await?; + + tokio::task::spawn(async move { + let io = TokioIo::new(stream); + + let service = service_fn(move |req| { + handle( + req, + state.clone(), + http_plugins.clone(), + websocket_plugins.clone(), + ) + }); + + if let Err(err) = http1_server::Builder::new() + .serve_connection(io, service) + .with_upgrades() + .await + { + error!(error = err.to_string(), "failed proxy server connection"); + } + }); + } +} + +async fn handle( + mut req: Request, + state: Arc, + http_plugins: Arc>>, + websocket_plugins: Arc>>, +) -> Result { + if let Some(route) = state.config.match_route(req.uri().path()) { + if let Err(err) = execute_plugins(&mut req, &http_plugins) { + match err { + PluginError::Http(status, body) => { + let mut res = Response::new(body); + *res.status_mut() = status; + return Ok(res); + } + } + } + + return match route.protocol { + Protocol::Http => handle_http(req, route, state.clone()).await, + Protocol::Websocket => { + handle_websocket(req, route, state.clone(), websocket_plugins.clone()).await + } + }; + } + + let mut res = Response::new(full("Invalid path")); + *res.status_mut() = StatusCode::UNPROCESSABLE_ENTITY; + + Ok(res) +} + +async fn handle_http( + req: Request, + route: &Route, + state: Arc, +) -> Result { + let dmtr_project_id = req + .headers() + .get(DMTR_PROJECT_ID) + .map(|k| k.to_str().unwrap_or_default()) + .unwrap_or_default(); + + state.metrics.count_http_total_request(dmtr_project_id); + + let stream = TcpStream::connect((route.host.clone(), route.port)) + .await + .unwrap(); + + let io = TokioIo::new(stream); + + let (mut sender, conn) = http1_client::Builder::new() + .preserve_header_case(true) + .title_case_headers(true) + .handshake(io) + .await?; + + tokio::task::spawn(async move { + if let Err(err) = conn.await { + println!("Connection failed: {:?}", err); + } + }); + + let resp = sender.send_request(req).await?; + Ok(resp.map(|b| b.boxed())) +} + +async fn handle_websocket( + mut req: Request, + route: &Route, + state: Arc, + websocket_plugins: Arc>>, +) -> Result { + let headers = req.headers(); + + if req.method() != Method::GET + || !headers + .get(UPGRADE) + .and_then(|h| h.to_str().ok()) + .map(|h| h.eq_ignore_ascii_case("websocket")) + .unwrap_or(false) + { + let mut res = Response::new(full("Invalid websocket request")); + *res.status_mut() = StatusCode::RANGE_NOT_SATISFIABLE; + return Ok(res); + } + + let upgrade = HeaderValue::from_static("Upgrade"); + let websocket = HeaderValue::from_static("websocket"); + + let key = headers.get(SEC_WEBSOCKET_KEY); + let derived = key.map(|k| derive_accept_key(k.as_bytes())); + let version = req.version(); + + let host = route.host.clone(); + let port = route.port; + + let dmtr_project_id = req + .headers() + .get(DMTR_PROJECT_ID) + .map(|k| k.to_str().unwrap_or_default()) + .unwrap_or_default() + .to_string(); + + tokio::task::spawn(async move { + match hyper::upgrade::on(&mut req).await { + Ok(upgraded) => { + let upgraded = TokioIo::new(upgraded); + dbg!(&upgraded); + + let client_stream = + WebSocketStream::from_raw_socket(upgraded, Role::Server, None).await; + let (client_outgoing, client_incoming) = client_stream.split(); + + let url_result = Url::parse(&format!("ws://{}:{}", host, port)); + if let Err(err) = url_result { + error!( + error = err.to_string(), + "host and port invalid to mount the url on route config" + ); + return; + } + let url = url_result.unwrap(); + + let connection_result = connect_async(url).await; + if let Err(err) = connection_result { + error!(error = err.to_string(), "fail to connect to the host"); + return; + } + let (host_stream, _) = connection_result.unwrap(); + let (host_outgoing, host_incoming) = host_stream.split(); + + let client_in = client_incoming + .inspect_ok(|_| { + let _result = execute_plugins(&mut req, &websocket_plugins); + state.metrics.count_ws_total_frame(&dmtr_project_id); + }) + .forward(host_outgoing); + let host_in = host_incoming.forward(client_outgoing); + + future::select(client_in, host_in).await; + } + Err(err) => { + error!(error = err.to_string(), "upgrade error"); + } + } + }); + + let mut res = Response::new(BoxBody::default()); + *res.status_mut() = StatusCode::SWITCHING_PROTOCOLS; + *res.version_mut() = version; + res.headers_mut().append(CONNECTION, upgrade); + res.headers_mut().append(UPGRADE, websocket); + res.headers_mut() + .append(SEC_WEBSOCKET_ACCEPT, derived.unwrap().parse().unwrap()); + + Ok(res) +} diff --git a/proxy/src/utils.rs b/proxy/src/utils.rs new file mode 100644 index 0000000..62ff388 --- /dev/null +++ b/proxy/src/utils.rs @@ -0,0 +1,15 @@ +use bytes::Bytes; +use http_body_util::{combinators::BoxBody, BodyExt, Full}; +use hyper::Response; + +pub type Body = BoxBody; +pub type ProxyResponse = Response; + +pub const DMTR_PROJECT_ID: &str = "dmtr-project-id"; +pub const DMTR_API_KEY: &str = "dmtr-api-key"; + +pub fn full>(chunk: T) -> Body { + Full::new(chunk.into()) + .map_err(|never| match never {}) + .boxed() +} From df8ff5157d2c9e7678d9b7e4abcec64326c7844f Mon Sep 17 00:00:00 2001 From: paulobressan Date: Thu, 8 Feb 2024 14:54:21 -0300 Subject: [PATCH 03/23] feat: added workspace to reuse Ogmios port to watch on proxy --- .gitignore | 1 + operator/Cargo.lock => Cargo.lock | 676 ++++++++----- Cargo.toml | 6 + operator/LICENSE => LICENSE | 0 operator/Cargo.toml | 2 +- operator/src/crdgen.rs | 2 +- operator/src/main.rs | 2 +- proxy/Cargo.lock | 1463 ----------------------------- 8 files changed, 471 insertions(+), 1681 deletions(-) create mode 100644 .gitignore rename operator/Cargo.lock => Cargo.lock (80%) create mode 100644 Cargo.toml rename operator/LICENSE => LICENSE (100%) delete mode 100644 proxy/Cargo.lock diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c41cc9e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target \ No newline at end of file diff --git a/operator/Cargo.lock b/Cargo.lock similarity index 80% rename from operator/Cargo.lock rename to Cargo.lock index fa47fd6..66504db 100644 --- a/operator/Cargo.lock +++ b/Cargo.lock @@ -4,11 +4,11 @@ version = 3 [[package]] name = "actix-codec" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "617a8268e3537fe1d8c9ead925fca49ef6400927ee7bc26750e90ecee14ce4b8" +checksum = "5f7b0a21988c1bf877cf4759ef5ddaac04c1c9fe808c9142ecb78ba97d97a28a" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.2", "bytes", "futures-core", "futures-sink", @@ -21,9 +21,9 @@ dependencies = [ [[package]] name = "actix-http" -version = "3.4.0" +version = "3.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92ef85799cba03f76e4f7c10f533e66d87c9a7e7055f3391f09000ad8351bc9" +checksum = "d223b13fd481fc0d1f83bb12659ae774d9e3601814c68a0bc539731698cca743" dependencies = [ "actix-codec", "actix-rt", @@ -31,7 +31,7 @@ dependencies = [ "actix-utils", "ahash", "base64", - "bitflags 2.4.1", + "bitflags 2.4.2", "brotli", "bytes", "bytestring", @@ -39,8 +39,8 @@ dependencies = [ "encoding_rs", "flate2", "futures-core", - "h2", - "http", + "h2 0.3.24", + "http 0.2.11", "httparse", "httpdate", "itoa", @@ -65,17 +65,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb" dependencies = [ "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] name = "actix-router" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d66ff4d247d2b160861fa2866457e85706833527840e4133f8f49aa423a38799" +checksum = "d22475596539443685426b6bdadb926ad0ecaefdfc5fb05e5e3441f15463c511" dependencies = [ "bytestring", - "http", + "http 0.2.11", "regex", "serde", "tracing", @@ -131,9 +131,9 @@ dependencies = [ [[package]] name = "actix-web" -version = "4.4.0" +version = "4.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4a5b5e29603ca8c94a77c65cf874718ceb60292c5a5c3e5f4ace041af462b9" +checksum = "43a6556ddebb638c2358714d853257ed226ece6023ef9364f23f0c70737ea984" dependencies = [ "actix-codec", "actix-http", @@ -178,7 +178,7 @@ dependencies = [ "actix-router", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -198,9 +198,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" dependencies = [ "cfg-if", "getrandom", @@ -256,9 +256,9 @@ dependencies = [ [[package]] name = "argon2" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ba4cac0a46bc1d2912652a751c47f2a9f3a7fe89bcae2275d418f5270402f9" +checksum = "3c3610892ee6e0cbce8ae2700349fcf8f98adb0dbfbee85aec3c9179d29cc072" dependencies = [ "base64ct", "blake2", @@ -268,13 +268,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.74" +version = "0.1.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" +checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -311,9 +311,9 @@ dependencies = [ [[package]] name = "base64" -version = "0.21.5" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "base64ct" @@ -335,9 +335,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "blake2" @@ -384,6 +384,12 @@ version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" version = "1.5.0" @@ -417,15 +423,15 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.31" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +checksum = "9f13690e35a5e4ace198e7beea2895d29f3a9cc55015fcebe6336bd2010af9eb" dependencies = [ "android-tzdata", "iana-time-zone", "num-traits", "serde", - "windows-targets 0.48.5", + "windows-targets 0.52.0", ] [[package]] @@ -463,9 +469,9 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "cpufeatures" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] @@ -491,9 +497,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.20.3" +version = "0.20.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" +checksum = "fc5d6b04b3fd0ba9926f945895de7d806260a2d7431ba82e7edaecb043c4c6b8" dependencies = [ "darling_core", "darling_macro", @@ -501,34 +507,40 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.3" +version = "0.20.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" +checksum = "04e48a959bcd5c761246f5d090ebc2fbf7b9cd527a492b07a67510c108f1e7e3" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", "strsim", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] name = "darling_macro" -version = "0.20.3" +version = "0.20.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" +checksum = "1d1545d67a2149e1d93b7e5c7752dce5a7426eb5d1357ddcfd89336b94444f77" dependencies = [ "darling_core", "quote", - "syn 2.0.41", + "syn 2.0.48", ] +[[package]] +name = "data-encoding" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" + [[package]] name = "deranged" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eb30d70a07a3b04884d2677f06bec33509dc67ca60d92949e5535352d3191dc" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ "powerfmt", ] @@ -601,30 +613,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "ext-cardano-ogmios" -version = "0.1.0" -dependencies = [ - "actix-web", - "argon2", - "base64", - "bech32", - "dotenv", - "futures", - "k8s-openapi", - "kube", - "lazy_static", - "prometheus", - "schemars", - "serde", - "serde_json", - "serde_yaml", - "thiserror", - "tokio", - "tracing", - "tracing-subscriber", -] - [[package]] name = "flate2" version = "1.0.28" @@ -652,9 +640,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" dependencies = [ "futures-channel", "futures-core", @@ -667,9 +655,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", "futures-sink", @@ -677,15 +665,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] name = "futures-executor" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" dependencies = [ "futures-core", "futures-task", @@ -694,38 +682,38 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-macro" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] name = "futures-sink" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" [[package]] name = "futures-task" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-util" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-channel", "futures-core", @@ -751,9 +739,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "libc", @@ -768,16 +756,35 @@ checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "h2" -version = "0.3.22" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.11", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "h2" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178" +checksum = "31d030e59af851932b72ceebadf4a2b5986dba4c3b99dd2493f8273a0f151943" dependencies = [ "bytes", "fnv", "futures-core", "futures-sink", "futures-util", - "http", + "http 1.0.0", "indexmap", "slab", "tokio", @@ -797,9 +804,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.3" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +checksum = "d0c62115964e08cb8039170eb33c1d0e2388a256930279edca206fff675f82c3" [[package]] name = "home" @@ -821,6 +828,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.6" @@ -828,7 +846,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", - "http", + "http 0.2.11", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http 1.0.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" +dependencies = [ + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", "pin-project-lite", ] @@ -860,8 +901,8 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "http", - "http-body", + "http 0.2.11", + "http-body 0.4.6", "httparse", "httpdate", "itoa", @@ -873,6 +914,26 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5aa53871fc917b1a9ed87b683a5d86db645e23acb32c2e0785a353e522fb75" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2 0.4.2", + "http 1.0.0", + "http-body 1.0.0", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "tokio", + "want", +] + [[package]] name = "hyper-rustls" version = "0.24.2" @@ -880,8 +941,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", - "http", - "hyper", + "http 0.2.11", + "hyper 0.14.28", "log", "rustls", "rustls-native-certs", @@ -895,17 +956,37 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" dependencies = [ - "hyper", + "hyper 0.14.28", "pin-project-lite", "tokio", "tokio-io-timeout", ] +[[package]] +name = "hyper-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "hyper 1.1.0", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + [[package]] name = "iana-time-zone" -version = "0.1.58" +version = "0.1.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -942,9 +1023,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.1.0" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520" dependencies = [ "equivalent", "hashbrown", @@ -967,18 +1048,18 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "jobserver" -version = "0.1.27" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d" +checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6" dependencies = [ "libc", ] [[package]] name = "js-sys" -version = "0.3.66" +version = "0.3.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" +checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" dependencies = [ "wasm-bindgen", ] @@ -996,14 +1077,16 @@ dependencies = [ ] [[package]] -name = "jsonpath_lib" -version = "0.3.0" +name = "jsonpath-rust" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaa63191d68230cccb81c5aa23abd53ed64d83337cacbb25a7b8c7979523774f" +checksum = "06cc127b7c3d270be504572364f9569761a180b981919dd0d87693a7f5fb7829" dependencies = [ - "log", - "serde", + "pest", + "pest_derive", + "regex", "serde_json", + "thiserror", ] [[package]] @@ -1022,9 +1105,9 @@ dependencies = [ [[package]] name = "kube" -version = "0.87.1" +version = "0.87.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e34392aea935145070dcd5b39a6dea689ac6534d7d117461316c3d157b1d0fc3" +checksum = "3499c8d60c763246c7a213f51caac1e9033f46026904cb89bc8951ae8601f26e" dependencies = [ "k8s-openapi", "kube-client", @@ -1035,9 +1118,9 @@ dependencies = [ [[package]] name = "kube-client" -version = "0.87.1" +version = "0.87.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7266548b9269d9fa19022620d706697e64f312fb2ba31b93e6986453fcc82c92" +checksum = "033450dfa0762130565890dadf2f8835faedf749376ca13345bcd8ecd6b5f29f" dependencies = [ "base64", "bytes", @@ -1045,12 +1128,12 @@ dependencies = [ "either", "futures", "home", - "http", - "http-body", - "hyper", + "http 0.2.11", + "http-body 0.4.6", + "hyper 0.14.28", "hyper-rustls", "hyper-timeout", - "jsonpath_lib", + "jsonpath-rust", "k8s-openapi", "kube-core", "pem", @@ -1071,13 +1154,13 @@ dependencies = [ [[package]] name = "kube-core" -version = "0.87.1" +version = "0.87.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8321c315b96b59f59ef6b33f604b84b905ab8f9ff114a4f909d934c520227b1" +checksum = "b5bba93d054786eba7994d03ce522f368ef7d48c88a1826faa28478d85fb63ae" dependencies = [ "chrono", "form_urlencoded", - "http", + "http 0.2.11", "json-patch", "k8s-openapi", "once_cell", @@ -1089,22 +1172,22 @@ dependencies = [ [[package]] name = "kube-derive" -version = "0.87.1" +version = "0.87.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54591e1f37fc329d412c0fdaced010cc1305b546a39f283fc51700f8fb49421" +checksum = "91e98dd5e5767c7b894c1f0e41fd628b145f808e981feb8b08ed66455d47f1a4" dependencies = [ "darling", "proc-macro2", "quote", "serde_json", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] name = "kube-runtime" -version = "0.87.1" +version = "0.87.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e511e2c1a368d9d4bf6e70db58197e535d818df355b5a2007a8aeb17a370a8ba" +checksum = "2d8893eb18fbf6bb6c80ef6ee7dd11ec32b1dc3c034c988ac1b3a84d46a230ae" dependencies = [ "ahash", "async-trait", @@ -1138,11 +1221,22 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "leaky-bucket" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eb491abd89e9794d50f93c8db610a29509123e3fbbc9c8c67a528e9391cd853" +dependencies = [ + "parking_lot", + "tokio", + "tracing", +] + [[package]] name = "libc" -version = "0.2.151" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "local-channel" @@ -1179,9 +1273,9 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "memchr" -version = "2.6.4" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "mime" @@ -1191,9 +1285,9 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "miniz_oxide" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" dependencies = [ "adler", ] @@ -1220,11 +1314,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" dependencies = [ "autocfg", ] @@ -1241,9 +1341,9 @@ dependencies = [ [[package]] name = "object" -version = "0.32.1" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ "memchr", ] @@ -1260,6 +1360,30 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "operator" +version = "0.1.0" +dependencies = [ + "actix-web", + "argon2", + "base64", + "bech32", + "dotenv", + "futures", + "k8s-openapi", + "kube", + "lazy_static", + "prometheus", + "schemars", + "serde", + "serde_json", + "serde_yaml", + "thiserror", + "tokio", + "tracing", + "tracing-subscriber", +] + [[package]] name = "ordered-float" version = "2.10.1" @@ -1331,24 +1455,69 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "pest" +version = "2.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "219c0dcc30b6a27553f9cc242972b67f75b60eb0db71f0b5462f38b058c41546" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22e1288dbd7786462961e69bfd4df7848c1e37e8b74303dbdab82c3a9cdd2809" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1381c29a877c6d34b8c176e734f35d7f7f5b3adaefe940cb4d1bb7af94678e2e" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "pest_meta" +version = "2.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0934d6907f148c22a3acbda520c7eed243ad7487a30f51f6ce52b58b7077a8a" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + [[package]] name = "pin-project" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" +checksum = "0302c4a0442c456bd56f841aee5c3bfd17967563f6fadc9ceb9f9c23cf3807e0" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" +checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -1365,9 +1534,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" +checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" [[package]] name = "powerfmt" @@ -1383,9 +1552,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -1411,11 +1580,34 @@ version = "2.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" +[[package]] +name = "proxy" +version = "0.1.0" +dependencies = [ + "bytes", + "dotenv", + "futures-channel", + "futures-util", + "http-body-util", + "hyper 1.1.0", + "hyper-util", + "leaky-bucket", + "operator", + "prometheus", + "regex", + "thiserror", + "tokio", + "tokio-tungstenite", + "tracing", + "tracing-subscriber", + "url", +] + [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -1461,9 +1653,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.2" +version = "1.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" dependencies = [ "aho-corasick", "memchr", @@ -1473,9 +1665,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" dependencies = [ "aho-corasick", "memchr", @@ -1568,11 +1760,11 @@ checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "schannel" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1650,15 +1842,15 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" dependencies = [ "serde_derive", ] @@ -1675,13 +1867,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -1697,11 +1889,10 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.113" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" dependencies = [ - "indexmap", "itoa", "ryu", "serde", @@ -1721,9 +1912,9 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.9.27" +version = "0.9.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cc7a1570e38322cfe4154732e5110f887ea57e22b76f4bfd32b5bdd3368666c" +checksum = "adf8a49373e98a4c5f0ceb5d05aa7c648d75f63774981ed95b7c7443bbd50c6e" dependencies = [ "indexmap", "itoa", @@ -1743,6 +1934,17 @@ dependencies = [ "digest", ] +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -1772,9 +1974,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "socket2" @@ -1817,9 +2019,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.41" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -1828,22 +2030,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -1858,12 +2060,13 @@ dependencies = [ [[package]] name = "time" -version = "0.3.31" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" +checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" dependencies = [ "deranged", "itoa", + "num-conv", "powerfmt", "serde", "time-core", @@ -1878,10 +2081,11 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" +checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" dependencies = [ + "num-conv", "time-core", ] @@ -1902,9 +2106,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.35.1" +version = "1.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" +checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" dependencies = [ "backtrace", "bytes", @@ -1937,7 +2141,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -1950,6 +2154,18 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-tungstenite" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" +dependencies = [ + "futures-util", + "log", + "tokio", + "tungstenite", +] + [[package]] name = "tokio-util" version = "0.7.10" @@ -1989,12 +2205,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61c5bb1d698276a2443e5ecfabc1008bf15a36c12e6a7176e7bf089ea9131140" dependencies = [ "base64", - "bitflags 2.4.1", + "bitflags 2.4.2", "bytes", "futures-core", "futures-util", - "http", - "http-body", + "http 0.2.11", + "http-body 0.4.6", "http-range-header", "mime", "pin-project-lite", @@ -2035,7 +2251,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -2075,9 +2291,9 @@ dependencies = [ [[package]] name = "treediff" -version = "4.0.2" +version = "4.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52984d277bdf2a751072b5df30ec0377febdb02f7696d64c2d7d54630bac4303" +checksum = "4d127780145176e2b5d16611cc25a900150e86e9fd79d3bde6ff3a37359c9cb5" dependencies = [ "serde_json", ] @@ -2088,17 +2304,42 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "tungstenite" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" +dependencies = [ + "byteorder", + "bytes", + "data-encoding", + "http 1.0.0", + "httparse", + "log", + "rand", + "sha1", + "thiserror", + "url", + "utf-8", +] + [[package]] name = "typenum" version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + [[package]] name = "unicode-bidi" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" @@ -2138,6 +2379,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + [[package]] name = "valuable" version = "0.1.0" @@ -2167,9 +2414,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.89" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" +checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -2177,24 +2424,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.89" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" +checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.89" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" +checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2202,22 +2449,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.89" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" +checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.89" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" +checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" [[package]] name = "winapi" @@ -2243,11 +2490,11 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-core" -version = "0.51.1" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.48.5", + "windows-targets 0.52.0", ] [[package]] @@ -2384,22 +2631,22 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "zerocopy" -version = "0.7.31" +version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c4061bedbb353041c12f413700357bec76df2c7e2ca8e4df8bac24c6bf68e3d" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.31" +version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3c129550b3e6de3fd0ba67ba5c81818f9805e58b8d7fee80a3a59d2c9fc601a" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -2410,20 +2657,19 @@ checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" [[package]] name = "zstd" -version = "0.12.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a27595e173641171fc74a1232b7b1c7a7cb6e18222c11e9dfb9888fa424c53c" +checksum = "bffb3309596d527cfcba7dfc6ed6052f1d39dfbd7c867aa2e865e4a449c10110" dependencies = [ "zstd-safe", ] [[package]] name = "zstd-safe" -version = "6.0.6" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee98ffd0b48ee95e6c5168188e44a54550b1564d9d530ee21d5f0eaed1069581" +checksum = "43747c7422e2924c11144d5229878b98180ef8b06cca4ab5af37afc8a8d8ea3e" dependencies = [ - "libc", "zstd-sys", ] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..d760de7 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[workspace] + +members = [ + "operator", + "proxy", +] \ No newline at end of file diff --git a/operator/LICENSE b/LICENSE similarity index 100% rename from operator/LICENSE rename to LICENSE diff --git a/operator/Cargo.toml b/operator/Cargo.toml index 3e5adad..0f722b3 100644 --- a/operator/Cargo.toml +++ b/operator/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "ext-cardano-ogmios" +name = "operator" version = "0.1.0" edition = "2021" default-run = "controller" diff --git a/operator/src/crdgen.rs b/operator/src/crdgen.rs index af5f8bb..7afa1aa 100644 --- a/operator/src/crdgen.rs +++ b/operator/src/crdgen.rs @@ -1,4 +1,4 @@ -use ext_cardano_ogmios::controller; +use operator::controller; use kube::CustomResourceExt; fn main() { diff --git a/operator/src/main.rs b/operator/src/main.rs index 05a7c13..f06d4aa 100644 --- a/operator/src/main.rs +++ b/operator/src/main.rs @@ -6,7 +6,7 @@ use prometheus::{Encoder, TextEncoder}; use std::{io, sync::Arc}; use tracing::{info, Level}; -use ext_cardano_ogmios::{controller, State}; +use operator::{controller, State}; #[get("/metrics")] async fn metrics(c: Data>, _req: HttpRequest) -> impl Responder { diff --git a/proxy/Cargo.lock b/proxy/Cargo.lock deleted file mode 100644 index 8a9fe60..0000000 --- a/proxy/Cargo.lock +++ /dev/null @@ -1,1463 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "aho-corasick" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" -dependencies = [ - "memchr", -] - -[[package]] -name = "async-trait" -version = "0.1.77" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "backtrace" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "base64" -version = "0.21.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" -dependencies = [ - "serde", -] - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "cc" -version = "1.0.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" -dependencies = [ - "libc", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "config" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7328b20597b53c2454f0b1919720c25c7339051c02b72b7e05409e00b14132be" -dependencies = [ - "async-trait", - "convert_case", - "json5", - "lazy_static", - "nom", - "pathdiff", - "ron", - "rust-ini", - "serde", - "serde_json", - "toml", - "yaml-rust", -] - -[[package]] -name = "const-random" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aaf16c9c2c612020bcfd042e170f6e32de9b9d75adb5277cdbbd2e2c8c8299a" -dependencies = [ - "const-random-macro", -] - -[[package]] -name = "const-random-macro" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" -dependencies = [ - "getrandom", - "once_cell", - "tiny-keccak", -] - -[[package]] -name = "convert_case" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "cpufeatures" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" -dependencies = [ - "libc", -] - -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "data-encoding" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", -] - -[[package]] -name = "dlv-list" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "442039f5147480ba31067cb00ada1adae6892028e40e45fc5de7b7df6dcc1b5f" -dependencies = [ - "const-random", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-core", - "futures-macro", - "futures-sink", - "futures-task", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getrandom" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "h2" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d308f63daf4181410c242d34c11f928dcb3aa105852019e043c9d1f4e4368a" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" - -[[package]] -name = "hashbrown" -version = "0.14.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" - -[[package]] -name = "hermit-abi" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d3d0e0f38255e7fa3cf31335b3a56f05febd18025f4db5ef7a0cfb4f8da651f" - -[[package]] -name = "http" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" -dependencies = [ - "bytes", - "http", -] - -[[package]] -name = "http-body-util" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" -dependencies = [ - "bytes", - "futures-util", - "http", - "http-body", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" - -[[package]] -name = "httpdate" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" - -[[package]] -name = "hyper" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5aa53871fc917b1a9ed87b683a5d86db645e23acb32c2e0785a353e522fb75" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "tokio", - "want", -] - -[[package]] -name = "hyper-util" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "http", - "http-body", - "hyper", - "pin-project-lite", - "socket2", - "tokio", - "tower", - "tower-service", - "tracing", -] - -[[package]] -name = "idna" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "indexmap" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" -dependencies = [ - "equivalent", - "hashbrown 0.14.3", -] - -[[package]] -name = "itoa" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" - -[[package]] -name = "json5" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1" -dependencies = [ - "pest", - "pest_derive", - "serde", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "leaky-bucket" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eb491abd89e9794d50f93c8db610a29509123e3fbbc9c8c67a528e9391cd853" -dependencies = [ - "parking_lot", - "tokio", - "tracing", -] - -[[package]] -name = "libc" -version = "0.2.153" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" - -[[package]] -name = "linked-hash-map" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" - -[[package]] -name = "lock_api" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" - -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - -[[package]] -name = "miniz_oxide" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" -dependencies = [ - "libc", - "wasi", - "windows-sys", -] - -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - -[[package]] -name = "nu-ansi-term" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" -dependencies = [ - "overload", - "winapi", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "ordered-multimap" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ed8acf08e98e744e5384c8bc63ceb0364e68a6854187221c18df61c4797690e" -dependencies = [ - "dlv-list", - "hashbrown 0.13.2", -] - -[[package]] -name = "overload" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" - -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - -[[package]] -name = "pathdiff" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" - -[[package]] -name = "percent-encoding" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" - -[[package]] -name = "pest" -version = "2.7.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "219c0dcc30b6a27553f9cc242972b67f75b60eb0db71f0b5462f38b058c41546" -dependencies = [ - "memchr", - "thiserror", - "ucd-trie", -] - -[[package]] -name = "pest_derive" -version = "2.7.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e1288dbd7786462961e69bfd4df7848c1e37e8b74303dbdab82c3a9cdd2809" -dependencies = [ - "pest", - "pest_generator", -] - -[[package]] -name = "pest_generator" -version = "2.7.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1381c29a877c6d34b8c176e734f35d7f7f5b3adaefe940cb4d1bb7af94678e2e" -dependencies = [ - "pest", - "pest_meta", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pest_meta" -version = "2.7.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0934d6907f148c22a3acbda520c7eed243ad7487a30f51f6ce52b58b7077a8a" -dependencies = [ - "once_cell", - "pest", - "sha2", -] - -[[package]] -name = "pin-project" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0302c4a0442c456bd56f841aee5c3bfd17967563f6fadc9ceb9f9c23cf3807e0" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - -[[package]] -name = "proc-macro2" -version = "1.0.78" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "prometheus" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "449811d15fbdf5ceb5c1144416066429cf82316e2ec8ce0c1f6f8a02e7bbcf8c" -dependencies = [ - "cfg-if", - "fnv", - "lazy_static", - "memchr", - "parking_lot", - "protobuf", - "thiserror", -] - -[[package]] -name = "protobuf" -version = "2.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" - -[[package]] -name = "proxy" -version = "0.1.0" -dependencies = [ - "async-trait", - "bytes", - "config", - "futures-channel", - "futures-util", - "http-body-util", - "hyper", - "hyper-util", - "leaky-bucket", - "prometheus", - "regex", - "serde", - "thiserror", - "tokio", - "tokio-tungstenite", - "tracing", - "tracing-subscriber", - "url", -] - -[[package]] -name = "quote" -version = "1.0.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "regex" -version = "1.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" - -[[package]] -name = "ron" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" -dependencies = [ - "base64", - "bitflags 2.4.2", - "serde", - "serde_derive", -] - -[[package]] -name = "rust-ini" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e2a3bcec1f113553ef1c88aae6c020a369d03d55b58de9869a0908930385091" -dependencies = [ - "cfg-if", - "ordered-multimap", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" - -[[package]] -name = "ryu" -version = "1.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "serde" -version = "1.0.196" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.196" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.112" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d1bd37ce2324cf3bf85e5a25f96eb4baf0d5aa6eba43e7ae8958870c4ec48ed" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "serde_spanned" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" -dependencies = [ - "serde", -] - -[[package]] -name = "sha1" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sharded-slab" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "signal-hook-registry" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" - -[[package]] -name = "socket2" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" -dependencies = [ - "libc", - "windows-sys", -] - -[[package]] -name = "syn" -version = "2.0.48" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "thread_local" -version = "1.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" -dependencies = [ - "cfg-if", - "once_cell", -] - -[[package]] -name = "tiny-keccak" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" -dependencies = [ - "crunchy", -] - -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - -[[package]] -name = "tokio" -version = "1.35.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tokio-tungstenite" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" -dependencies = [ - "futures-util", - "log", - "tokio", - "tungstenite", -] - -[[package]] -name = "tokio-util" -version = "0.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", - "tracing", -] - -[[package]] -name = "toml" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6a4b9e8023eb94392d3dca65d717c53abc5dad49c07cb65bb8fcd87115fa325" -dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit", -] - -[[package]] -name = "toml_datetime" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" -dependencies = [ - "serde", -] - -[[package]] -name = "toml_edit" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" -dependencies = [ - "indexmap", - "serde", - "serde_spanned", - "toml_datetime", - "winnow", -] - -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tokio", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-layer" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" - -[[package]] -name = "tower-service" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" - -[[package]] -name = "tracing" -version = "0.1.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" -dependencies = [ - "log", - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tracing-core" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" -dependencies = [ - "once_cell", - "valuable", -] - -[[package]] -name = "tracing-log" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" -dependencies = [ - "log", - "once_cell", - "tracing-core", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" -dependencies = [ - "nu-ansi-term", - "sharded-slab", - "smallvec", - "thread_local", - "tracing-core", - "tracing-log", -] - -[[package]] -name = "try-lock" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" - -[[package]] -name = "tungstenite" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" -dependencies = [ - "byteorder", - "bytes", - "data-encoding", - "http", - "httparse", - "log", - "rand", - "sha1", - "thiserror", - "url", - "utf-8", -] - -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "ucd-trie" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" - -[[package]] -name = "unicode-bidi" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-normalization" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "url" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - -[[package]] -name = "utf-8" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" - -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "want" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" -dependencies = [ - "try-lock", -] - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "winnow" -version = "0.5.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7cad8365489051ae9f054164e459304af2e7e9bb407c958076c8bf4aef52da5" -dependencies = [ - "memchr", -] - -[[package]] -name = "yaml-rust" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" -dependencies = [ - "linked-hash-map", -] From 113775a6ef828760b1f881d2e359d8691ab40d2d Mon Sep 17 00:00:00 2001 From: paulobressan Date: Thu, 8 Feb 2024 15:10:23 -0300 Subject: [PATCH 04/23] docs(readme): adjusted readme --- operator/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/operator/README.md b/operator/README.md index c123ca9..e3212a9 100644 --- a/operator/README.md +++ b/operator/README.md @@ -1,6 +1,6 @@ # Ext Cardano Ogmios Operator -This operator allow demeter to run and expose ogmios +This operator allows demeter to run and expose ogmios ## Environment @@ -27,7 +27,7 @@ cargo run ## Metrics -to collect metrics for Prometheus, an http api will enable with the route /metrics. +to collect metrics for Prometheus, an HTTP API will enable the route /metrics. ``` /metrics From 2e4ca6dbe024ccc3707d97ba53d1e921191a3a3b Mon Sep 17 00:00:00 2001 From: paulobressan Date: Thu, 8 Feb 2024 18:54:35 -0300 Subject: [PATCH 05/23] feat(proxy): improved proxy and removed plugin modules --- proxy/Cargo.toml | 7 +- proxy/src/config.rs | 115 +++---------------------- proxy/src/main.rs | 54 ++++++++---- proxy/src/metrics.rs | 5 +- proxy/src/plugins/auth_dmtr.rs | 59 ------------- proxy/src/plugins/host_key_header.rs | 46 ---------- proxy/src/plugins/mod.rs | 38 --------- proxy/src/plugins/rate_limit.rs | 28 ------ proxy/src/proxy.rs | 122 ++++++--------------------- proxy/src/utils.rs | 30 ++++++- 10 files changed, 109 insertions(+), 395 deletions(-) delete mode 100644 proxy/src/plugins/auth_dmtr.rs delete mode 100644 proxy/src/plugins/host_key_header.rs delete mode 100644 proxy/src/plugins/mod.rs delete mode 100644 proxy/src/plugins/rate_limit.rs diff --git a/proxy/Cargo.toml b/proxy/Cargo.toml index 8d5de78..25db4f0 100644 --- a/proxy/Cargo.toml +++ b/proxy/Cargo.toml @@ -6,9 +6,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -async-trait = "0.1.77" +operator = { path = "../operator" } bytes = "1.5.0" -config = { version = "0.14.0", features = ["toml"] } +dotenv = "0.15.0" futures-channel = "0.3.30" futures-util = "0.3.30" http-body-util = "0.1.0" @@ -17,10 +17,9 @@ hyper-util = { version = "0.1.3", features = ["full"] } leaky-bucket = "1.0.1" prometheus = "0.13.3" regex = "1.10.3" -serde = { version = "1.0.196", features = ["derive"] } thiserror = "1.0.56" tokio = { version = "1.35.1", features = ["full"] } tokio-tungstenite = "0.21.0" tracing = "0.1.40" tracing-subscriber = "0.3.18" -url = "2.5.0" +url = "2.5.0" \ No newline at end of file diff --git a/proxy/src/config.rs b/proxy/src/config.rs index 373041a..0817f29 100644 --- a/proxy/src/config.rs +++ b/proxy/src/config.rs @@ -1,114 +1,21 @@ -use std::{env, error::Error}; +use std::env; -use serde::Deserialize; - -use crate::plugins::{ - auth_dmtr::AuthDmtrPlugin, host_key_header::HostKeyHeaderPlugin, rate_limit::RateLimiterPlugin, - Plugin, -}; - -#[derive(Debug, Clone, Deserialize)] -pub enum Protocol { - Http, - Websocket, -} - -#[derive(Debug, Clone, Deserialize)] -pub struct Route { - pub path: String, - pub host: String, - pub port: u16, - pub protocol: Protocol, -} - -#[derive(Debug, Clone, Deserialize, PartialEq, Eq, PartialOrd, Ord)] -#[serde(tag = "type", content = "priority")] -pub enum HttpPluginsAvailable { - AuthDmtrPlugin(u16), - RateLimiterPlugin(u16), - HostKeyHeaderPlugin(u16), -} -impl HttpPluginsAvailable { - pub fn priority(&self) -> u16 { - match self { - HttpPluginsAvailable::AuthDmtrPlugin(priority) => priority.clone(), - HttpPluginsAvailable::RateLimiterPlugin(priority) => priority.clone(), - HttpPluginsAvailable::HostKeyHeaderPlugin(priority) => priority.clone(), - } - } -} - -#[derive(Debug, Clone, Deserialize, PartialEq, Eq, PartialOrd, Ord)] -#[serde(tag = "type", content = "priority")] -pub enum WebsocketPluginsAvailable { - RateLimiterPlugin(u16), -} -impl WebsocketPluginsAvailable { - pub fn priority(&self) -> u16 { - match self { - WebsocketPluginsAvailable::RateLimiterPlugin(priority) => priority.clone(), - } - } -} - -#[derive(Debug, Clone, Deserialize)] +#[derive(Debug, Clone)] pub struct Config { pub proxy_addr: String, pub prometheus_addr: String, - pub routes: Vec, - pub http_plugins: Vec, - pub websocket_plugins: Vec, + pub ogmios_port: u16, } impl Config { - pub fn try_new() -> Result> { - let path = env::var("PROXY_CONFIG_PATH").unwrap_or("proxy.toml".into()); - - let config = config::Config::builder() - .add_source(config::File::with_name(&path).required(true)) - .build()? - .try_deserialize()?; - - Ok(config) - } - - pub fn match_route(&self, path: &str) -> Option<&Route> { - self.routes.iter().find(|r| r.path.eq(path)) - } - - pub fn mount_plugins(&self) -> (Vec>, Vec>) { - let mut http_plugins: Vec> = Vec::new(); - - let mut config_http_plugins = self.http_plugins.clone(); - config_http_plugins.sort_by_key(|p| p.priority()); - - for plugin in config_http_plugins.iter() { - match plugin { - HttpPluginsAvailable::AuthDmtrPlugin(_) => { - http_plugins.push(Box::new(AuthDmtrPlugin::new())) - } - HttpPluginsAvailable::RateLimiterPlugin(_) => { - http_plugins.push(Box::new(RateLimiterPlugin::new())) - } - HttpPluginsAvailable::HostKeyHeaderPlugin(_) => { - http_plugins.push(Box::new(HostKeyHeaderPlugin::new())) - } - } + pub fn new() -> Self { + Self { + proxy_addr: env::var("PROXY_ADDR").expect("PROXY_ADDR must be set"), + prometheus_addr: env::var("PROMETHEUS_ADDR").expect("PROMETHEUS_ADDR must be set"), + ogmios_port: env::var("OGMIOS_PORT") + .expect("OGMIOS_PORT must be set") + .parse() + .expect("OGMIOS_PORT must a number"), } - - let mut websocket_plugins: Vec> = Vec::new(); - - let mut config_websocket_plugins = self.websocket_plugins.clone(); - config_websocket_plugins.sort_by_key(|p| p.priority()); - - for plugin in self.websocket_plugins.iter() { - match plugin { - WebsocketPluginsAvailable::RateLimiterPlugin(_) => { - websocket_plugins.push(Box::new(RateLimiterPlugin::new())) - } - } - } - - (http_plugins, websocket_plugins) } } diff --git a/proxy/src/main.rs b/proxy/src/main.rs index 017b173..0462f7b 100644 --- a/proxy/src/main.rs +++ b/proxy/src/main.rs @@ -1,43 +1,63 @@ use config::Config; -use futures_util::future; +use dotenv::dotenv; use metrics::Metrics; use prometheus::Registry; +use regex::Regex; use std::error::Error; use std::sync::Arc; -use tokio::pin; use tracing::Level; mod config; mod metrics; -mod plugins; mod proxy; mod utils; +#[tokio::main] +async fn main() -> Result<(), Box> { + dotenv().ok(); + + tracing_subscriber::fmt().with_max_level(Level::INFO).init(); + + let state = Arc::new(State::try_new()?); + + let metrics = metrics::start(state.clone()); + let proxy_server = proxy::start(state.clone()); + + let result = tokio::join!(metrics, proxy_server); + result.0?; + result.1?; + + Ok(()) +} + #[derive(Debug, Clone)] pub struct State { config: Config, metrics: Metrics, + tools: Tools, } impl State { pub fn try_new() -> Result> { - let config = Config::try_new()?; + let config = Config::new(); let metrics = Metrics::try_new(Registry::default())?; + let tools = Tools::try_new()?; - Ok(Self { config, metrics }) + Ok(Self { + config, + metrics, + tools, + }) } } -#[tokio::main] -async fn main() -> Result<(), Box> { - tracing_subscriber::fmt().with_max_level(Level::INFO).init(); - - let state = Arc::new(State::try_new()?); - - let metrics = metrics::start(state.clone()); - let proxy_server = proxy::start(state.clone()); - pin!(metrics, proxy_server); - - future::select(metrics, proxy_server).await; +#[derive(Debug, Clone)] +pub struct Tools { + host_regex: Regex, +} +impl Tools { + pub fn try_new() -> Result> { + let host_regex = Regex::new(r"(dmtr_[\w\d-]+)?\.?([\w]+).+-([\w\d]+).+")?; - Ok(()) + Ok(Self { host_regex }) + } } diff --git a/proxy/src/metrics.rs b/proxy/src/metrics.rs index ef5d197..db17219 100644 --- a/proxy/src/metrics.rs +++ b/proxy/src/metrics.rs @@ -65,7 +65,10 @@ async fn api_get_metrics(state: &State) -> Result { Ok(res) } -async fn routes_match(req: Request, state: Arc) -> Result { +async fn routes_match( + req: Request, + state: Arc, +) -> Result { match (req.method(), req.uri().path()) { (&Method::GET, "/metrics") => api_get_metrics(&state).await, _ => Ok(Response::builder() diff --git a/proxy/src/plugins/auth_dmtr.rs b/proxy/src/plugins/auth_dmtr.rs deleted file mode 100644 index 5570106..0000000 --- a/proxy/src/plugins/auth_dmtr.rs +++ /dev/null @@ -1,59 +0,0 @@ -use std::collections::HashMap; - -use async_trait::async_trait; -use hyper::{body::Incoming, header::HeaderValue, Request, StatusCode}; - -use crate::utils::{full, DMTR_API_KEY, DMTR_PROJECT_ID}; - -use super::{Plugin, PluginError}; - -#[derive(Debug)] -pub struct DmtrConsumer { - project_id: String, -} - -pub struct AuthDmtrPlugin { - consumers: HashMap, -} -impl AuthDmtrPlugin { - pub fn new() -> Self { - let mut consumers = HashMap::new(); - - consumers.insert( - "dmtr_kupo1d988zmt0g4skjdt6xdxkg5zp23f55ttpxfmsemy6fa".into(), - DmtrConsumer { - project_id: "prj-xxxxx-xxxxx".into(), - }, - ); - - Self { consumers } - } -} - -#[async_trait] -impl Plugin for AuthDmtrPlugin { - fn execute<'a>( - &self, - req: &'a mut Request, - ) -> Result<&'a mut Request, PluginError> { - let dmtr_key = req - .headers() - .get(DMTR_API_KEY) - .map(|k| k.to_str().unwrap_or_default()) - .unwrap_or_default(); - - if let Some(costumer) = self.consumers.get(dmtr_key) { - req.headers_mut().insert( - DMTR_PROJECT_ID, - HeaderValue::from_str(&costumer.project_id).unwrap(), - ); - - return Ok(req); - } - - return Err(PluginError::Http( - StatusCode::UNAUTHORIZED, - full("Unauthorized"), - )); - } -} diff --git a/proxy/src/plugins/host_key_header.rs b/proxy/src/plugins/host_key_header.rs deleted file mode 100644 index 50963f8..0000000 --- a/proxy/src/plugins/host_key_header.rs +++ /dev/null @@ -1,46 +0,0 @@ -use async_trait::async_trait; -use hyper::{ - body::Incoming, - header::{HeaderValue, HOST}, - Request, -}; -use regex::Regex; - -use crate::utils::DMTR_API_KEY; - -use super::{Plugin, PluginError}; - -#[derive(Debug)] -pub struct HostKeyHeaderPlugin { - regex: Regex, -} -impl HostKeyHeaderPlugin { - pub fn new() -> Self { - let regex = Regex::new(r"(dmtr_[\w\d-]+)\.[\w+].+").unwrap(); - Self { regex } - } -} - -#[async_trait] -impl Plugin for HostKeyHeaderPlugin { - fn execute<'a>( - &self, - req: &'a mut Request, - ) -> Result<&'a mut Request, PluginError> { - let host = req - .headers() - .get(HOST) - .map(|k| k.to_str().unwrap_or_default()) - .unwrap_or_default() - .to_string(); - - if let Some(captures) = self.regex.captures(&host) { - let dmtr_key = captures.get(1).unwrap().as_str(); - - req.headers_mut() - .insert(DMTR_API_KEY, HeaderValue::from_str(dmtr_key).unwrap()); - } - - Ok(req) - } -} diff --git a/proxy/src/plugins/mod.rs b/proxy/src/plugins/mod.rs deleted file mode 100644 index 3e0ebea..0000000 --- a/proxy/src/plugins/mod.rs +++ /dev/null @@ -1,38 +0,0 @@ -use std::fmt::Debug; - -use async_trait::async_trait; -use hyper::{body::Incoming, Request, StatusCode}; -use thiserror::Error; - -use crate::utils::Body; - -pub mod auth_dmtr; -pub mod host_key_header; -pub mod rate_limit; - -#[derive(Debug, Error)] -pub enum PluginError { - #[error("Http Error: {0}")] - Http(StatusCode, Body), -} - -#[async_trait] -pub trait Plugin: Send + Sync { - fn execute<'a>( - &self, - req: &'a mut Request, - ) -> Result<&'a mut Request, PluginError>; -} - -pub fn execute_plugins<'a>( - req: &'a mut Request, - plugins: &[Box], -) -> Result<&'a mut Request, PluginError> { - for plugin in plugins.iter() { - if let Err(err) = plugin.execute(req) { - return Err(err); - } - } - - Ok(req) -} diff --git a/proxy/src/plugins/rate_limit.rs b/proxy/src/plugins/rate_limit.rs deleted file mode 100644 index 93c3442..0000000 --- a/proxy/src/plugins/rate_limit.rs +++ /dev/null @@ -1,28 +0,0 @@ -use std::collections::HashMap; - -use async_trait::async_trait; -use hyper::{body::Incoming, Request}; -use leaky_bucket::RateLimiter; - -use super::{Plugin, PluginError}; - -pub struct RateLimiterPlugin { - consumers: HashMap, -} -impl RateLimiterPlugin { - pub fn new() -> Self { - let consumers = HashMap::new(); - Self { consumers } - } -} - -#[async_trait] -impl Plugin for RateLimiterPlugin { - fn execute<'a>( - &self, - req: &'a mut Request, - ) -> Result<&'a mut Request, PluginError> { - // self.consumers.insert("k".into(), RateLimiter::builder().build()); - Ok(req) - } -} diff --git a/proxy/src/proxy.rs b/proxy/src/proxy.rs index b7dfbda..75b7669 100644 --- a/proxy/src/proxy.rs +++ b/proxy/src/proxy.rs @@ -2,10 +2,12 @@ use futures_util::{future, stream::TryStreamExt, StreamExt}; use http_body_util::{combinators::BoxBody, BodyExt}; use hyper::body::Incoming; use hyper::client::conn::http1 as http1_client; -use hyper::header::{HeaderValue, CONNECTION, SEC_WEBSOCKET_ACCEPT, SEC_WEBSOCKET_KEY, UPGRADE}; +use hyper::header::{ + HeaderValue, CONNECTION, HOST, SEC_WEBSOCKET_ACCEPT, SEC_WEBSOCKET_KEY, UPGRADE, +}; use hyper::server::conn::http1 as http1_server; use hyper::service::service_fn; -use hyper::{Method, Request, Response, StatusCode}; +use hyper::{Request, Response, StatusCode}; use hyper_util::rt::TokioIo; use std::net::SocketAddr; use std::str::FromStr; @@ -17,38 +19,23 @@ use tokio_tungstenite::{connect_async, WebSocketStream}; use tracing::{error, info}; use url::Url; -use crate::config::{Protocol, Route}; -use crate::plugins::{execute_plugins, Plugin, PluginError}; -use crate::utils::{full, ProxyResponse, DMTR_PROJECT_ID}; +use crate::utils::{get_header, Protocol, ProxyResponse, DMTR_API_KEY}; use crate::State; pub async fn start(state: Arc) -> Result<(), Box> { let addr = SocketAddr::from_str(&state.config.proxy_addr)?; let listener = TcpListener::bind(addr).await?; - info!(addr = state.config.proxy_addr, "proxy listening"); - let (http_plugins, websocket_plugins) = state.config.mount_plugins(); - let http_plugins = Arc::new(http_plugins); - let websocket_plugins = Arc::new(websocket_plugins); + info!(addr = state.config.proxy_addr, "proxy listening"); loop { let state = state.clone(); - let http_plugins = http_plugins.clone(); - let websocket_plugins = websocket_plugins.clone(); - let (stream, _) = listener.accept().await?; tokio::task::spawn(async move { let io = TokioIo::new(stream); - let service = service_fn(move |req| { - handle( - req, - state.clone(), - http_plugins.clone(), - websocket_plugins.clone(), - ) - }); + let service = service_fn(move |req| handle(req, state.clone())); if let Err(err) = http1_server::Builder::new() .serve_connection(io, service) @@ -64,52 +51,34 @@ pub async fn start(state: Arc) -> Result<(), Box> async fn handle( mut req: Request, state: Arc, - http_plugins: Arc>>, - websocket_plugins: Arc>>, ) -> Result { - if let Some(route) = state.config.match_route(req.uri().path()) { - if let Err(err) = execute_plugins(&mut req, &http_plugins) { - match err { - PluginError::Http(status, body) => { - let mut res = Response::new(body); - *res.status_mut() = status; - return Ok(res); - } - } - } + let port_host = get_header(&mut req, HOST.as_str()).unwrap().to_string(); - return match route.protocol { - Protocol::Http => handle_http(req, route, state.clone()).await, - Protocol::Websocket => { - handle_websocket(req, route, state.clone(), websocket_plugins.clone()).await - } - }; - } + let captures = state.tools.host_regex.captures(&port_host).unwrap(); + let network: &str = captures.get(2).unwrap().into(); + let version: &str = captures.get(3).unwrap().into(); + let ogmios_host = format!("ogmios-{network}-{version}:{}", state.config.ogmios_port); - let mut res = Response::new(full("Invalid path")); - *res.status_mut() = StatusCode::UNPROCESSABLE_ENTITY; + if let Some(key) = captures.get(1) { + req.headers_mut() + .insert(DMTR_API_KEY, HeaderValue::from_str(key.as_str()).unwrap()); + } - Ok(res) + match Protocol::match_protocol(&mut req) { + Protocol::Http => handle_http(req, state, &ogmios_host).await, + Protocol::Websocket => handle_websocket(req, state, &ogmios_host).await, + } } async fn handle_http( req: Request, - route: &Route, state: Arc, + ogmios_host: &str, ) -> Result { - let dmtr_project_id = req - .headers() - .get(DMTR_PROJECT_ID) - .map(|k| k.to_str().unwrap_or_default()) - .unwrap_or_default(); + state.metrics.count_http_total_request("dmtr_project_id"); - state.metrics.count_http_total_request(dmtr_project_id); - - let stream = TcpStream::connect((route.host.clone(), route.port)) - .await - .unwrap(); - - let io = TokioIo::new(stream); + let stream = TcpStream::connect(ogmios_host).await.unwrap(); + let io: TokioIo = TokioIo::new(stream); let (mut sender, conn) = http1_client::Builder::new() .preserve_header_case(true) @@ -129,60 +98,26 @@ async fn handle_http( async fn handle_websocket( mut req: Request, - route: &Route, state: Arc, - websocket_plugins: Arc>>, + ogmios_host: &str, ) -> Result { let headers = req.headers(); - - if req.method() != Method::GET - || !headers - .get(UPGRADE) - .and_then(|h| h.to_str().ok()) - .map(|h| h.eq_ignore_ascii_case("websocket")) - .unwrap_or(false) - { - let mut res = Response::new(full("Invalid websocket request")); - *res.status_mut() = StatusCode::RANGE_NOT_SATISFIABLE; - return Ok(res); - } - let upgrade = HeaderValue::from_static("Upgrade"); let websocket = HeaderValue::from_static("websocket"); - let key = headers.get(SEC_WEBSOCKET_KEY); let derived = key.map(|k| derive_accept_key(k.as_bytes())); let version = req.version(); - - let host = route.host.clone(); - let port = route.port; - - let dmtr_project_id = req - .headers() - .get(DMTR_PROJECT_ID) - .map(|k| k.to_str().unwrap_or_default()) - .unwrap_or_default() - .to_string(); + let ogmios_host = ogmios_host.to_string(); tokio::task::spawn(async move { match hyper::upgrade::on(&mut req).await { Ok(upgraded) => { let upgraded = TokioIo::new(upgraded); - dbg!(&upgraded); - let client_stream = WebSocketStream::from_raw_socket(upgraded, Role::Server, None).await; let (client_outgoing, client_incoming) = client_stream.split(); - let url_result = Url::parse(&format!("ws://{}:{}", host, port)); - if let Err(err) = url_result { - error!( - error = err.to_string(), - "host and port invalid to mount the url on route config" - ); - return; - } - let url = url_result.unwrap(); + let url = Url::parse(&format!("ws://{ogmios_host}")).unwrap(); let connection_result = connect_async(url).await; if let Err(err) = connection_result { @@ -194,8 +129,7 @@ async fn handle_websocket( let client_in = client_incoming .inspect_ok(|_| { - let _result = execute_plugins(&mut req, &websocket_plugins); - state.metrics.count_ws_total_frame(&dmtr_project_id); + state.metrics.count_ws_total_frame(""); }) .forward(host_outgoing); let host_in = host_incoming.forward(client_outgoing); diff --git a/proxy/src/utils.rs b/proxy/src/utils.rs index 62ff388..a9cb8ee 100644 --- a/proxy/src/utils.rs +++ b/proxy/src/utils.rs @@ -1,15 +1,37 @@ use bytes::Bytes; use http_body_util::{combinators::BoxBody, BodyExt, Full}; -use hyper::Response; +use hyper::{body::Incoming, header::UPGRADE, Request, Response}; + +pub const DMTR_API_KEY: &str = "dmtr-api-key"; pub type Body = BoxBody; pub type ProxyResponse = Response; -pub const DMTR_PROJECT_ID: &str = "dmtr-project-id"; -pub const DMTR_API_KEY: &str = "dmtr-api-key"; - pub fn full>(chunk: T) -> Body { Full::new(chunk.into()) .map_err(|never| match never {}) .boxed() } + +pub fn get_header(req: &mut Request, key: &str) -> Option { + req.headers() + .get(key) + .and_then(|h| h.to_str().ok().and_then(|v| Some(v.to_string()))) +} + +pub enum Protocol { + Http, + Websocket, +} +impl Protocol { + pub fn match_protocol(req: &mut Request) -> Self { + if get_header(req, UPGRADE.as_str()) + .map(|h| h.eq_ignore_ascii_case("websocket")) + .unwrap_or(false) + { + return Self::Websocket; + } + + Self::Http + } +} From 41e1ca5b42813639d8f277786e47c772bcf9f323 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Thu, 8 Feb 2024 22:15:04 -0300 Subject: [PATCH 06/23] feat(proxy): adjusted websocket path --- proxy/src/proxy.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/proxy/src/proxy.rs b/proxy/src/proxy.rs index 75b7669..43c94c1 100644 --- a/proxy/src/proxy.rs +++ b/proxy/src/proxy.rs @@ -117,8 +117,7 @@ async fn handle_websocket( WebSocketStream::from_raw_socket(upgraded, Role::Server, None).await; let (client_outgoing, client_incoming) = client_stream.split(); - let url = Url::parse(&format!("ws://{ogmios_host}")).unwrap(); - + let url = Url::parse(&format!("ws://{ogmios_host}{}", req.uri())).unwrap(); let connection_result = connect_async(url).await; if let Err(err) = connection_result { error!(error = err.to_string(), "fail to connect to the host"); From a1120653bce75fa9a04541aa21f686cde28e717f Mon Sep 17 00:00:00 2001 From: paulobressan Date: Thu, 8 Feb 2024 23:00:36 -0300 Subject: [PATCH 07/23] chore(operator): exposed kube lib in workspace --- operator/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/operator/src/lib.rs b/operator/src/lib.rs index f0900a3..847c119 100644 --- a/operator/src/lib.rs +++ b/operator/src/lib.rs @@ -5,6 +5,8 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use thiserror::Error; +pub use kube; + #[derive(Error, Debug)] pub enum Error { #[error("Kube Error: {0}")] From 0506fb0fa54525dc1d9e30c830ba44c4c7d6d801 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Thu, 8 Feb 2024 23:03:38 -0300 Subject: [PATCH 08/23] feat(proxy): added RwLock in state --- proxy/src/auth.rs | 7 +++++++ proxy/src/main.rs | 21 +++++---------------- proxy/src/metrics.rs | 14 +++++++++----- proxy/src/proxy.rs | 35 ++++++++++++++++++++++------------- proxy/src/utils.rs | 2 +- 5 files changed, 44 insertions(+), 35 deletions(-) create mode 100644 proxy/src/auth.rs diff --git a/proxy/src/auth.rs b/proxy/src/auth.rs new file mode 100644 index 0000000..fcd0129 --- /dev/null +++ b/proxy/src/auth.rs @@ -0,0 +1,7 @@ +use std::sync::Arc; + +use crate::State; + +pub async fn start(state: Arc) -> Result<(), Box> { + Ok(()) +} diff --git a/proxy/src/main.rs b/proxy/src/main.rs index 0462f7b..43a4091 100644 --- a/proxy/src/main.rs +++ b/proxy/src/main.rs @@ -5,6 +5,7 @@ use prometheus::Registry; use regex::Regex; use std::error::Error; use std::sync::Arc; +use tokio::sync::RwLock; use tracing::Level; mod config; @@ -18,7 +19,7 @@ async fn main() -> Result<(), Box> { tracing_subscriber::fmt().with_max_level(Level::INFO).init(); - let state = Arc::new(State::try_new()?); + let state = Arc::new(RwLock::new(State::try_new()?)); let metrics = metrics::start(state.clone()); let proxy_server = proxy::start(state.clone()); @@ -34,30 +35,18 @@ async fn main() -> Result<(), Box> { pub struct State { config: Config, metrics: Metrics, - tools: Tools, + host_regex: Regex, } impl State { pub fn try_new() -> Result> { let config = Config::new(); let metrics = Metrics::try_new(Registry::default())?; - let tools = Tools::try_new()?; + let host_regex = Regex::new(r"(dmtr_[\w\d-]+)?\.?([\w]+).+-([\w\d]+).+")?; Ok(Self { config, metrics, - tools, + host_regex, }) } } - -#[derive(Debug, Clone)] -pub struct Tools { - host_regex: Regex, -} -impl Tools { - pub fn try_new() -> Result> { - let host_regex = Regex::new(r"(dmtr_[\w\d-]+)?\.?([\w]+).+-([\w\d]+).+")?; - - Ok(Self { host_regex }) - } -} diff --git a/proxy/src/metrics.rs b/proxy/src/metrics.rs index db17219..613c342 100644 --- a/proxy/src/metrics.rs +++ b/proxy/src/metrics.rs @@ -7,6 +7,7 @@ use hyper::{body::Incoming, service::service_fn, Method, Request, Response, Stat use hyper_util::rt::TokioIo; use prometheus::{opts, Encoder, IntCounterVec, Registry, TextEncoder}; use tokio::net::TcpListener; +use tokio::sync::RwLock; use tracing::{error, info}; use crate::utils::{full, ProxyResponse}; @@ -67,10 +68,12 @@ async fn api_get_metrics(state: &State) -> Result { async fn routes_match( req: Request, - state: Arc, + state: Arc>, ) -> Result { + let r_state = state.read().await; + match (req.method(), req.uri().path()) { - (&Method::GET, "/metrics") => api_get_metrics(&state).await, + (&Method::GET, "/metrics") => api_get_metrics(&r_state).await, _ => Ok(Response::builder() .status(StatusCode::NOT_FOUND) .body(full("Not Found")) @@ -78,10 +81,11 @@ async fn routes_match( } } -pub async fn start(state: Arc) -> Result<(), Box> { - let addr = SocketAddr::from_str(&state.config.prometheus_addr)?; +pub async fn start(state: Arc>) -> Result<(), Box> { + let r_state = state.read().await; + let addr = SocketAddr::from_str(&r_state.config.prometheus_addr)?; let listener = TcpListener::bind(addr).await?; - info!(addr = state.config.prometheus_addr, "metrics listening"); + info!(addr = r_state.config.prometheus_addr, "metrics listening"); loop { let state = state.clone(); diff --git a/proxy/src/proxy.rs b/proxy/src/proxy.rs index 43c94c1..8d5c656 100644 --- a/proxy/src/proxy.rs +++ b/proxy/src/proxy.rs @@ -13,6 +13,7 @@ use std::net::SocketAddr; use std::str::FromStr; use std::sync::Arc; use tokio::net::{TcpListener, TcpStream}; +use tokio::sync::RwLock; use tokio_tungstenite::tungstenite::handshake::derive_accept_key; use tokio_tungstenite::tungstenite::protocol::Role; use tokio_tungstenite::{connect_async, WebSocketStream}; @@ -22,11 +23,13 @@ use url::Url; use crate::utils::{get_header, Protocol, ProxyResponse, DMTR_API_KEY}; use crate::State; -pub async fn start(state: Arc) -> Result<(), Box> { - let addr = SocketAddr::from_str(&state.config.proxy_addr)?; +pub async fn start(state: Arc>) -> Result<(), Box> { + let r_state = state.read().await; + + let addr = SocketAddr::from_str(&r_state.config.proxy_addr)?; let listener = TcpListener::bind(addr).await?; - info!(addr = state.config.proxy_addr, "proxy listening"); + info!(addr = r_state.config.proxy_addr, "proxy listening"); loop { let state = state.clone(); @@ -50,14 +53,16 @@ pub async fn start(state: Arc) -> Result<(), Box> async fn handle( mut req: Request, - state: Arc, + state: Arc>, ) -> Result { - let port_host = get_header(&mut req, HOST.as_str()).unwrap().to_string(); + let r_state = state.read().await; + + let port_host = get_header(&req, HOST.as_str()).unwrap().to_string(); - let captures = state.tools.host_regex.captures(&port_host).unwrap(); + let captures = r_state.host_regex.captures(&port_host).unwrap(); let network: &str = captures.get(2).unwrap().into(); let version: &str = captures.get(3).unwrap().into(); - let ogmios_host = format!("ogmios-{network}-{version}:{}", state.config.ogmios_port); + let ogmios_host = format!("ogmios-{network}-{version}:{}", r_state.config.ogmios_port); if let Some(key) = captures.get(1) { req.headers_mut() @@ -65,17 +70,19 @@ async fn handle( } match Protocol::match_protocol(&mut req) { - Protocol::Http => handle_http(req, state, &ogmios_host).await, - Protocol::Websocket => handle_websocket(req, state, &ogmios_host).await, + Protocol::Http => handle_http(req, state.clone(), &ogmios_host).await, + Protocol::Websocket => handle_websocket(req, state.clone(), &ogmios_host).await, } } async fn handle_http( req: Request, - state: Arc, + state: Arc>, ogmios_host: &str, ) -> Result { - state.metrics.count_http_total_request("dmtr_project_id"); + let r_state = state.read().await; + + r_state.metrics.count_http_total_request("dmtr_project_id"); let stream = TcpStream::connect(ogmios_host).await.unwrap(); let io: TokioIo = TokioIo::new(stream); @@ -98,7 +105,7 @@ async fn handle_http( async fn handle_websocket( mut req: Request, - state: Arc, + state: Arc>, ogmios_host: &str, ) -> Result { let headers = req.headers(); @@ -112,6 +119,8 @@ async fn handle_websocket( tokio::task::spawn(async move { match hyper::upgrade::on(&mut req).await { Ok(upgraded) => { + let r_state = state.read().await; + let upgraded = TokioIo::new(upgraded); let client_stream = WebSocketStream::from_raw_socket(upgraded, Role::Server, None).await; @@ -128,7 +137,7 @@ async fn handle_websocket( let client_in = client_incoming .inspect_ok(|_| { - state.metrics.count_ws_total_frame(""); + r_state.metrics.count_ws_total_frame(""); }) .forward(host_outgoing); let host_in = host_incoming.forward(client_outgoing); diff --git a/proxy/src/utils.rs b/proxy/src/utils.rs index a9cb8ee..c6674cd 100644 --- a/proxy/src/utils.rs +++ b/proxy/src/utils.rs @@ -13,7 +13,7 @@ pub fn full>(chunk: T) -> Body { .boxed() } -pub fn get_header(req: &mut Request, key: &str) -> Option { +pub fn get_header(req: &Request, key: &str) -> Option { req.headers() .get(key) .and_then(|h| h.to_str().ok().and_then(|v| Some(v.to_string()))) From 08124f978894d8a68c432756192f27c3b91b259a Mon Sep 17 00:00:00 2001 From: paulobressan Date: Fri, 9 Feb 2024 19:23:37 -0300 Subject: [PATCH 09/23] feat(proxy): added auth using kube resource --- proxy/src/auth.rs | 46 +++++++++++++++++++++++++++-- proxy/src/main.rs | 35 ++++++++++++++++++++-- proxy/src/metrics.rs | 45 ++++++++++++++++++++++------- proxy/src/proxy.rs | 69 ++++++++++++++++++++++++++++++-------------- 4 files changed, 158 insertions(+), 37 deletions(-) diff --git a/proxy/src/auth.rs b/proxy/src/auth.rs index fcd0129..6aa62fd 100644 --- a/proxy/src/auth.rs +++ b/proxy/src/auth.rs @@ -1,7 +1,49 @@ use std::sync::Arc; +use futures_util::TryStreamExt; +use operator::{ + kube::{ + api::ListParams, + runtime::{ + watcher::{self, Config}, + WatchStreamExt, + }, + Api, Client, + }, + OgmiosPort, +}; +use tokio::{pin, sync::RwLock}; +use tracing::error; + use crate::State; -pub async fn start(state: Arc) -> Result<(), Box> { - Ok(()) +pub async fn start(state: Arc>) { + let client = Client::try_default() + .await + .expect("failed to create kube client"); + + let api = Api::::all(client.clone()); + let result = api.list(&ListParams::default()).await; + if let Err(err) = result { + error!(error = err.to_string(), "error to get crds"); + std::process::exit(1); + } + + for crd in result.unwrap().items.iter() { + state.write().await.add_auth_token(crd); + } + + let stream = watcher::watcher(api, Config::default()).applied_objects(); + pin!(stream); + + loop { + let result = stream.try_next().await; + if let Err(err) = result { + error!(error = err.to_string(), "fail crd auth watcher"); + continue; + } + if let Some(crd) = result.unwrap() { + state.write().await.add_auth_token(&crd); + } + } } diff --git a/proxy/src/main.rs b/proxy/src/main.rs index 43a4091..74f89ab 100644 --- a/proxy/src/main.rs +++ b/proxy/src/main.rs @@ -1,13 +1,16 @@ use config::Config; use dotenv::dotenv; use metrics::Metrics; +use operator::OgmiosPort; use prometheus::Registry; use regex::Regex; +use std::collections::HashMap; use std::error::Error; use std::sync::Arc; use tokio::sync::RwLock; use tracing::Level; +mod auth; mod config; mod metrics; mod proxy; @@ -21,32 +24,58 @@ async fn main() -> Result<(), Box> { let state = Arc::new(RwLock::new(State::try_new()?)); + let auth = auth::start(state.clone()); let metrics = metrics::start(state.clone()); let proxy_server = proxy::start(state.clone()); - let result = tokio::join!(metrics, proxy_server); - result.0?; - result.1?; + tokio::join!(metrics, proxy_server, auth); Ok(()) } +#[derive(Debug, Clone)] +pub struct Consumer { + namespace: String, +} + #[derive(Debug, Clone)] pub struct State { config: Config, metrics: Metrics, host_regex: Regex, + consumers: HashMap, } impl State { pub fn try_new() -> Result> { let config = Config::new(); let metrics = Metrics::try_new(Registry::default())?; let host_regex = Regex::new(r"(dmtr_[\w\d-]+)?\.?([\w]+).+-([\w\d]+).+")?; + let consumers = HashMap::new(); Ok(Self { config, metrics, host_regex, + consumers, }) } + + pub fn add_auth_token(&mut self, crd: &OgmiosPort) { + if crd.status.is_some() { + let network = crd.spec.network.to_string(); + let version = crd.spec.version; + let auth_token = crd.status.as_ref().unwrap().auth_token.clone(); + let namespace = crd.metadata.namespace.as_ref().unwrap().clone(); + + let hash_key = format!("{}.{}.{}", network, version, auth_token); + let consumer = Consumer { namespace }; + + self.consumers.insert(hash_key, consumer); + } + } + + pub fn get_auth_token(&self, network: &str, version: &str, token: &str) -> Option { + let hash_key = format!("{}.{}.{}", network, version, token); + self.consumers.get(&hash_key).cloned() + } } diff --git a/proxy/src/metrics.rs b/proxy/src/metrics.rs index 613c342..ad4205b 100644 --- a/proxy/src/metrics.rs +++ b/proxy/src/metrics.rs @@ -58,6 +58,7 @@ impl Metrics { async fn api_get_metrics(state: &State) -> Result { let metrics = state.metrics.metrics_collected(); + let encoder = TextEncoder::new(); let mut buffer = vec![]; encoder.encode(&metrics, &mut buffer).unwrap(); @@ -68,12 +69,12 @@ async fn api_get_metrics(state: &State) -> Result { async fn routes_match( req: Request, - state: Arc>, + rw_state: Arc>, ) -> Result { - let r_state = state.read().await; + let state = rw_state.read().await.clone(); match (req.method(), req.uri().path()) { - (&Method::GET, "/metrics") => api_get_metrics(&r_state).await, + (&Method::GET, "/metrics") => api_get_metrics(&state).await, _ => Ok(Response::builder() .status(StatusCode::NOT_FOUND) .body(full("Not Found")) @@ -81,20 +82,42 @@ async fn routes_match( } } -pub async fn start(state: Arc>) -> Result<(), Box> { - let r_state = state.read().await; - let addr = SocketAddr::from_str(&r_state.config.prometheus_addr)?; - let listener = TcpListener::bind(addr).await?; - info!(addr = r_state.config.prometheus_addr, "metrics listening"); +pub async fn start(rw_state: Arc>) { + let state = rw_state.read().await.clone(); + + let addr_result = SocketAddr::from_str(&state.config.prometheus_addr); + if let Err(err) = addr_result { + error!(error = err.to_string(), "invalid prometheus addr"); + std::process::exit(1); + } + let addr = addr_result.unwrap(); + + let listener_result = TcpListener::bind(addr).await; + if let Err(err) = listener_result { + error!( + error = err.to_string(), + "fail to bind tcp prometheus server listener" + ); + std::process::exit(1); + } + let listener = listener_result.unwrap(); + + info!(addr = state.config.prometheus_addr, "metrics listening"); loop { - let state = state.clone(); + let rw_state = rw_state.clone(); + + let accept_result = listener.accept().await; + if let Err(err) = accept_result { + error!(error = err.to_string(), "accept client prometheus server"); + continue; + } + let (stream, _) = accept_result.unwrap(); - let (stream, _) = listener.accept().await.unwrap(); let io = TokioIo::new(stream); tokio::task::spawn(async move { - let service = service_fn(move |req| routes_match(req, state.clone())); + let service = service_fn(move |req| routes_match(req, rw_state.clone())); if let Err(err) = http1_server::Builder::new() .serve_connection(io, service) diff --git a/proxy/src/proxy.rs b/proxy/src/proxy.rs index 8d5c656..053afb2 100644 --- a/proxy/src/proxy.rs +++ b/proxy/src/proxy.rs @@ -20,25 +20,41 @@ use tokio_tungstenite::{connect_async, WebSocketStream}; use tracing::{error, info}; use url::Url; -use crate::utils::{get_header, Protocol, ProxyResponse, DMTR_API_KEY}; +use crate::utils::{full, get_header, Protocol, ProxyResponse, DMTR_API_KEY}; use crate::State; -pub async fn start(state: Arc>) -> Result<(), Box> { - let r_state = state.read().await; +pub async fn start(rw_state: Arc>) { + let state = rw_state.read().await.clone(); - let addr = SocketAddr::from_str(&r_state.config.proxy_addr)?; - let listener = TcpListener::bind(addr).await?; + let addr_result = SocketAddr::from_str(&state.config.proxy_addr); + if let Err(err) = addr_result { + error!(error = err.to_string(), "invalid proxy addr"); + std::process::exit(1); + } + let addr = addr_result.unwrap(); + + let listener_result = TcpListener::bind(addr).await; + if let Err(err) = listener_result { + error!(error = err.to_string(), "fail to bind tcp server listener"); + std::process::exit(1); + } + let listener = listener_result.unwrap(); - info!(addr = r_state.config.proxy_addr, "proxy listening"); + info!(addr = state.config.proxy_addr, "proxy listening"); loop { - let state = state.clone(); - let (stream, _) = listener.accept().await?; + let rw_state = rw_state.clone(); + let accept_result = listener.accept().await; + if let Err(err) = accept_result { + error!(error = err.to_string(), "fail to accept client"); + continue; + } + let (stream, _) = accept_result.unwrap(); tokio::task::spawn(async move { let io = TokioIo::new(stream); - let service = service_fn(move |req| handle(req, state.clone())); + let service = service_fn(move |req| handle(req, rw_state.clone())); if let Err(err) = http1_server::Builder::new() .serve_connection(io, service) @@ -53,36 +69,47 @@ pub async fn start(state: Arc>) -> Result<(), Box, - state: Arc>, + rw_state: Arc>, ) -> Result { - let r_state = state.read().await; + let state = rw_state.read().await.clone(); let port_host = get_header(&req, HOST.as_str()).unwrap().to_string(); - let captures = r_state.host_regex.captures(&port_host).unwrap(); + let captures = state.host_regex.captures(&port_host).unwrap(); let network: &str = captures.get(2).unwrap().into(); let version: &str = captures.get(3).unwrap().into(); - let ogmios_host = format!("ogmios-{network}-{version}:{}", r_state.config.ogmios_port); + let ogmios_host = format!("ogmios-{network}-{version}:{}", state.config.ogmios_port); if let Some(key) = captures.get(1) { req.headers_mut() .insert(DMTR_API_KEY, HeaderValue::from_str(key.as_str()).unwrap()); } + let token = get_header(&req, DMTR_API_KEY).unwrap_or_default(); + let consumer = state.get_auth_token(network, version, &token); + if consumer.is_none() { + return Ok(Response::builder() + .status(StatusCode::UNAUTHORIZED) + .body(full("Unauthorized")) + .unwrap()); + } + + dbg!(consumer.unwrap().namespace); + match Protocol::match_protocol(&mut req) { - Protocol::Http => handle_http(req, state.clone(), &ogmios_host).await, - Protocol::Websocket => handle_websocket(req, state.clone(), &ogmios_host).await, + Protocol::Http => handle_http(req, rw_state.clone(), &ogmios_host).await, + Protocol::Websocket => handle_websocket(req, rw_state.clone(), &ogmios_host).await, } } async fn handle_http( req: Request, - state: Arc>, + rw_state: Arc>, ogmios_host: &str, ) -> Result { - let r_state = state.read().await; + let state = rw_state.read().await.clone(); - r_state.metrics.count_http_total_request("dmtr_project_id"); + state.metrics.count_http_total_request("dmtr_project_id"); let stream = TcpStream::connect(ogmios_host).await.unwrap(); let io: TokioIo = TokioIo::new(stream); @@ -105,7 +132,7 @@ async fn handle_http( async fn handle_websocket( mut req: Request, - state: Arc>, + rw_state: Arc>, ogmios_host: &str, ) -> Result { let headers = req.headers(); @@ -119,7 +146,7 @@ async fn handle_websocket( tokio::task::spawn(async move { match hyper::upgrade::on(&mut req).await { Ok(upgraded) => { - let r_state = state.read().await; + let state = rw_state.read().await.clone(); let upgraded = TokioIo::new(upgraded); let client_stream = @@ -137,7 +164,7 @@ async fn handle_websocket( let client_in = client_incoming .inspect_ok(|_| { - r_state.metrics.count_ws_total_frame(""); + state.metrics.count_ws_total_frame(""); }) .forward(host_outgoing); let host_in = host_incoming.forward(client_outgoing); From c641fd2023d6a45a799f58a322ca63e65f16095c Mon Sep 17 00:00:00 2001 From: paulobressan Date: Fri, 9 Feb 2024 21:44:26 -0300 Subject: [PATCH 10/23] chore(operator): adjusted to use proxy auth --- operator/src/controller.rs | 5 +- operator/src/handlers/auth.rs | 166 ---------------------------------- operator/src/handlers/mod.rs | 1 - operator/src/helpers/mod.rs | 90 ------------------ operator/src/lib.rs | 7 +- operator/src/metrics.rs | 2 +- operator/src/utils.rs | 59 ++++++++++++ 7 files changed, 64 insertions(+), 266 deletions(-) delete mode 100644 operator/src/handlers/auth.rs delete mode 100644 operator/src/handlers/mod.rs delete mode 100644 operator/src/helpers/mod.rs create mode 100644 operator/src/utils.rs diff --git a/operator/src/controller.rs b/operator/src/controller.rs index c76b777..6242a27 100644 --- a/operator/src/controller.rs +++ b/operator/src/controller.rs @@ -10,8 +10,7 @@ use std::{sync::Arc, time::Duration}; use tracing::{error, info, instrument}; use crate::{ - auth::handle_auth, build_hostname, patch_resource_status, Error, Metrics, Network, Result, - State, + build_api_key, build_hostname, patch_resource_status, Error, Metrics, Network, Result, State, }; pub static OGMIOS_PORT_FINALIZER: &str = "ogmiosports.demeter.run"; @@ -56,7 +55,7 @@ impl Context { } async fn reconcile(crd: Arc, ctx: Arc) -> Result { - let key = handle_auth(&ctx.client, &crd).await?; + let key = build_api_key(&crd).await?; let (hostname, hostname_key) = build_hostname(&crd.spec.network, &key); diff --git a/operator/src/handlers/auth.rs b/operator/src/handlers/auth.rs deleted file mode 100644 index 3c8a309..0000000 --- a/operator/src/handlers/auth.rs +++ /dev/null @@ -1,166 +0,0 @@ -use argon2::Argon2; -use base64::{ - engine::general_purpose::{self}, - Engine, -}; -use bech32::ToBase32; -use k8s_openapi::{api::core::v1::Secret, apimachinery::pkg::apis::meta::v1::OwnerReference}; -use kube::{ - api::{Patch, PatchParams, PostParams}, - core::ObjectMeta, - Api, Client, Resource, ResourceExt, -}; -use serde::Deserialize; -use serde_json::{json, Value as JsonValue}; -use std::collections::BTreeMap; -use tracing::info; - -use crate::{ - create_resource, get_config, get_resource, kong_consumer, patch_resource, Error, OgmiosPort, -}; - -pub async fn handle_auth(client: &Client, crd: &OgmiosPort) -> Result { - let key = build_api_key(crd).await?; - - handle_secret(client, crd, &key).await?; - handle_consumer(client, crd).await?; - - Ok(key) -} - -async fn handle_secret(client: &Client, crd: &OgmiosPort, key: &str) -> Result<(), Error> { - let namespace = crd.namespace().unwrap(); - let name = build_auth_name(&crd.name_any()); - let secret = build_secret(crd, key); - - let api = Api::::namespaced(client.clone(), &namespace); - let result = api.get_opt(&name).await?; - - if result.is_some() { - info!(resource = crd.name_any(), "Updating auth secret"); - - let patch_params = PatchParams::default(); - let patch_data = Patch::Merge(secret); - - api.patch(&name, &patch_params, &patch_data).await?; - } else { - info!(resource = crd.name_any(), "Creating auth secret"); - - let post_params = PostParams::default(); - - api.create(&post_params, &secret).await?; - } - - Ok(()) -} - -async fn handle_consumer(client: &Client, crd: &OgmiosPort) -> Result<(), Error> { - let namespace = crd.namespace().unwrap(); - let name = build_auth_name(&crd.name_any()); - - let kong_consumer = kong_consumer(); - - let (metadata, data, raw) = build_consumer(crd)?; - - let result = get_resource(client.clone(), &namespace, &kong_consumer, &name).await?; - - if result.is_some() { - info!(resource = crd.name_any(), "Updating consumer"); - patch_resource(client.clone(), &namespace, kong_consumer, &name, raw).await?; - } else { - info!(resource = crd.name_any(), "Creating consumer"); - create_resource(client.clone(), &namespace, kong_consumer, metadata, data).await?; - } - Ok(()) -} - -async fn build_api_key(crd: &OgmiosPort) -> Result { - let namespace = crd.namespace().unwrap(); - let name = build_auth_name(&crd.name_any()); - - let password = format!("{}{}", name, namespace).as_bytes().to_vec(); - - let config = get_config(); - let salt = config.api_key_salt.as_bytes(); - - let mut output = vec![0; 16]; - - let argon2 = Argon2::default(); - argon2.hash_password_into(password.as_slice(), salt, &mut output)?; - - let base64 = general_purpose::URL_SAFE_NO_PAD.encode(output); - let with_bech = bech32::encode("dmtr_ogmios", base64.to_base32(), bech32::Variant::Bech32)?; - - Ok(with_bech) -} - -fn build_auth_name(name: &str) -> String { - format!("ogmios-auth-{name}") -} - -fn build_secret(crd: &OgmiosPort, api_key: &str) -> Secret { - let mut string_data = BTreeMap::new(); - string_data.insert("key".into(), api_key.into()); - - let mut labels = BTreeMap::new(); - labels.insert("konghq.com/credential".into(), "key-auth".into()); - - let metadata = ObjectMeta { - name: Some(build_auth_name(&crd.name_any())), - owner_references: Some(vec![OwnerReference { - api_version: OgmiosPort::api_version(&()).to_string(), - kind: OgmiosPort::kind(&()).to_string(), - name: crd.name_any(), - uid: crd.uid().unwrap(), - ..Default::default() - }]), - labels: Some(labels), - ..Default::default() - }; - - Secret { - type_: Some(String::from("Opaque")), - metadata, - string_data: Some(string_data), - ..Default::default() - } -} - -fn build_consumer(crd: &OgmiosPort) -> Result<(ObjectMeta, JsonValue, JsonValue), Error> { - let kong_consumer = kong_consumer(); - let config = get_config(); - - let name = crd.name_any(); - let namespace = crd.namespace().unwrap(); - let username = format!("{namespace}.{name}"); - - let metadata = ObjectMeta::deserialize(&json!({ - "name": build_auth_name(&crd.name_any()), - "annotations": { - "kubernetes.io/ingress.class": config.ingress_class, - }, - "ownerReferences": [ - { - "apiVersion": OgmiosPort::api_version(&()).to_string(), - "kind": OgmiosPort::kind(&()).to_string(), - "name": crd.name_any(), - "uid": crd.uid() - } - ] - }))?; - - let data = json!({ - "username": username, - "credentials": [build_auth_name(&crd.name_any())] - }); - - let raw = json!({ - "apiVersion": kong_consumer.api_version, - "kind": kong_consumer.kind, - "metadata": metadata, - "username": data["username"], - "credentials": data["credentials"] - }); - - Ok((metadata, data, raw)) -} diff --git a/operator/src/handlers/mod.rs b/operator/src/handlers/mod.rs deleted file mode 100644 index 0e4a05d..0000000 --- a/operator/src/handlers/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod auth; diff --git a/operator/src/helpers/mod.rs b/operator/src/helpers/mod.rs deleted file mode 100644 index 3efeecb..0000000 --- a/operator/src/helpers/mod.rs +++ /dev/null @@ -1,90 +0,0 @@ -use kube::{ - api::{Patch, PatchParams, PostParams}, - core::{DynamicObject, ObjectMeta}, - discovery::ApiResource, - Api, Client, -}; -use serde_json::json; - -use crate::{get_config, Network}; - -pub fn kong_consumer() -> ApiResource { - ApiResource { - group: "configuration.konghq.com".into(), - version: "v1".into(), - api_version: "configuration.konghq.com/v1".into(), - kind: "KongConsumer".into(), - plural: "kongconsumers".into(), - } -} - -pub async fn get_resource( - client: Client, - namespace: &str, - api_resource: &ApiResource, - name: &str, -) -> Result, kube::Error> { - let api: Api = Api::namespaced_with(client, namespace, api_resource); - - api.get_opt(name).await -} - -pub async fn create_resource( - client: Client, - namespace: &str, - api_resource: ApiResource, - metadata: ObjectMeta, - data: serde_json::Value, -) -> Result<(), kube::Error> { - let api: Api = Api::namespaced_with(client, namespace, &api_resource); - - let post_params = PostParams::default(); - - let mut dynamic = DynamicObject::new("", &api_resource); - dynamic.data = data; - dynamic.metadata = metadata; - api.create(&post_params, &dynamic).await?; - Ok(()) -} - -pub async fn patch_resource( - client: Client, - namespace: &str, - api_resource: ApiResource, - name: &str, - payload: serde_json::Value, -) -> Result<(), kube::Error> { - let api: Api = Api::namespaced_with(client, namespace, &api_resource); - - let patch_params = PatchParams::default(); - api.patch(name, &patch_params, &Patch::Merge(payload)) - .await?; - Ok(()) -} - -pub async fn patch_resource_status( - client: Client, - namespace: &str, - api_resource: ApiResource, - name: &str, - payload: serde_json::Value, -) -> Result<(), kube::Error> { - let api: Api = Api::namespaced_with(client, namespace, &api_resource); - - let status = json!({ "status": payload }); - let patch_params = PatchParams::default(); - api.patch_status(name, &patch_params, &Patch::Merge(status)) - .await?; - Ok(()) -} - -pub fn build_hostname(network: &Network, key: &str) -> (String, String) { - let config = get_config(); - let ingress_class = &config.ingress_class; - let dns_zone = &config.dns_zone; - - let hostname = format!("{network}.{ingress_class}.{dns_zone}"); - let hostname_key = format!("{key}.{network}.{ingress_class}.{dns_zone}"); - - (hostname, hostname_key) -} diff --git a/operator/src/lib.rs b/operator/src/lib.rs index 847c119..9042d51 100644 --- a/operator/src/lib.rs +++ b/operator/src/lib.rs @@ -102,11 +102,8 @@ pub use crate::controller::*; pub mod metrics; pub use metrics::*; -mod helpers; -pub use helpers::*; - -mod handlers; -pub use handlers::*; +mod utils; +pub use utils::*; mod config; pub use config::*; diff --git a/operator/src/metrics.rs b/operator/src/metrics.rs index d18e3d4..f54b740 100644 --- a/operator/src/metrics.rs +++ b/operator/src/metrics.rs @@ -12,7 +12,7 @@ impl Default for Metrics { fn default() -> Self { let reconcile_failures = IntCounterVec::new( opts!( - "crd_controller_reconciliation_errors_total", + "ogmios_operator_reconciliation_errors_total", "reconciliation errors", ), &["instance", "error"], diff --git a/operator/src/utils.rs b/operator/src/utils.rs new file mode 100644 index 0000000..9e47d8d --- /dev/null +++ b/operator/src/utils.rs @@ -0,0 +1,59 @@ +use argon2::Argon2; +use base64::{engine::general_purpose, Engine}; +use bech32::ToBase32; +use kube::{ + api::{Patch, PatchParams}, + core::DynamicObject, + discovery::ApiResource, + Api, Client, ResourceExt, +}; +use serde_json::json; + +use crate::{get_config, Error, Network, OgmiosPort}; + +pub async fn patch_resource_status( + client: Client, + namespace: &str, + api_resource: ApiResource, + name: &str, + payload: serde_json::Value, +) -> Result<(), kube::Error> { + let api: Api = Api::namespaced_with(client, namespace, &api_resource); + + let status = json!({ "status": payload }); + let patch_params = PatchParams::default(); + api.patch_status(name, &patch_params, &Patch::Merge(status)) + .await?; + Ok(()) +} + +pub fn build_hostname(network: &Network, key: &str) -> (String, String) { + let config = get_config(); + let ingress_class = &config.ingress_class; + let dns_zone = &config.dns_zone; + + let hostname = format!("{network}.{ingress_class}.{dns_zone}"); + let hostname_key = format!("{key}.{network}.{ingress_class}.{dns_zone}"); + + (hostname, hostname_key) +} + +pub async fn build_api_key(crd: &OgmiosPort) -> Result { + let namespace = crd.namespace().unwrap(); + let name = format!("ogmios-auth-{}", &crd.name_any()); + + let password = format!("{}{}", name, namespace).as_bytes().to_vec(); + + let config = get_config(); + let salt = config.api_key_salt.as_bytes(); + + let mut output = vec![0; 16]; + + let argon2 = Argon2::default(); + argon2.hash_password_into(password.as_slice(), salt, &mut output)?; + + let base64 = general_purpose::URL_SAFE_NO_PAD.encode(output); + let with_bech = bech32::encode("dmtr_ogmios", base64.to_base32(), bech32::Variant::Bech32)?; + + Ok(with_bech) +} From 19a4cc97eccaae992c271cebef3640ffb91cb636 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Fri, 9 Feb 2024 22:52:56 -0300 Subject: [PATCH 11/23] feat(proxy): added proxy structure req and ws connection metric --- proxy/src/metrics.rs | 26 ++++++--- proxy/src/proxy.rs | 124 ++++++++++++++++++++++++++++--------------- proxy/src/utils.rs | 21 +------- 3 files changed, 103 insertions(+), 68 deletions(-) diff --git a/proxy/src/metrics.rs b/proxy/src/metrics.rs index ad4205b..bf177ee 100644 --- a/proxy/src/metrics.rs +++ b/proxy/src/metrics.rs @@ -17,6 +17,7 @@ use crate::State; pub struct Metrics { registry: Registry, pub ws_total_frame: IntCounterVec, + pub ws_total_connection: IntCounterVec, pub http_total_request: IntCounterVec, } @@ -24,21 +25,30 @@ impl Metrics { pub fn try_new(registry: Registry) -> Result> { let ws_total_frame = IntCounterVec::new( opts!("proxy_ws_total_frame", "total of websocket frame",), - &["dmtr_key"], + &["namespace"], ) .unwrap(); + + let ws_total_connection = IntCounterVec::new( + opts!("proxy_ws_total_connection", "total of websocket connection",), + &["namespace"], + ) + .unwrap(); + let http_total_request = IntCounterVec::new( opts!("proxy_http_total_request", "total of http request",), - &["dmtr_key"], + &["namespace"], ) .unwrap(); registry.register(Box::new(ws_total_frame.clone()))?; + registry.register(Box::new(ws_total_connection.clone()))?; registry.register(Box::new(http_total_request.clone()))?; Ok(Metrics { registry, ws_total_frame, + ws_total_connection, http_total_request, }) } @@ -47,12 +57,16 @@ impl Metrics { self.registry.gather() } - pub fn count_ws_total_frame(&self, dmtr_key: &str) { - self.ws_total_frame.with_label_values(&[dmtr_key]).inc() + pub fn count_ws_total_frame(&self, namespace: &str) { + self.ws_total_frame.with_label_values(&[namespace]).inc() + } + + pub fn count_http_total_request(&self, namespace: &str) { + self.http_total_request.with_label_values(&[namespace]).inc() } - pub fn count_http_total_request(&self, dmtr_key: &str) { - self.http_total_request.with_label_values(&[dmtr_key]).inc() + pub fn count_ws_total_connection(&self, namespace: &str) { + self.ws_total_connection.with_label_values(&[namespace]).inc() } } diff --git a/proxy/src/proxy.rs b/proxy/src/proxy.rs index 053afb2..82b7220 100644 --- a/proxy/src/proxy.rs +++ b/proxy/src/proxy.rs @@ -20,8 +20,8 @@ use tokio_tungstenite::{connect_async, WebSocketStream}; use tracing::{error, info}; use url::Url; -use crate::utils::{full, get_header, Protocol, ProxyResponse, DMTR_API_KEY}; -use crate::State; +use crate::utils::{full, get_header, ProxyResponse, DMTR_API_KEY}; +use crate::{Consumer, State}; pub async fn start(rw_state: Arc>) { let state = rw_state.read().await.clone(); @@ -68,50 +68,30 @@ pub async fn start(rw_state: Arc>) { } async fn handle( - mut req: Request, + req: Request, rw_state: Arc>, ) -> Result { let state = rw_state.read().await.clone(); + let proxy_req = ProxyRequest::new(req, &state); - let port_host = get_header(&req, HOST.as_str()).unwrap().to_string(); - - let captures = state.host_regex.captures(&port_host).unwrap(); - let network: &str = captures.get(2).unwrap().into(); - let version: &str = captures.get(3).unwrap().into(); - let ogmios_host = format!("ogmios-{network}-{version}:{}", state.config.ogmios_port); - - if let Some(key) = captures.get(1) { - req.headers_mut() - .insert(DMTR_API_KEY, HeaderValue::from_str(key.as_str()).unwrap()); - } - - let token = get_header(&req, DMTR_API_KEY).unwrap_or_default(); - let consumer = state.get_auth_token(network, version, &token); - if consumer.is_none() { + if proxy_req.consumer.is_none() { return Ok(Response::builder() .status(StatusCode::UNAUTHORIZED) .body(full("Unauthorized")) .unwrap()); } - dbg!(consumer.unwrap().namespace); + let namespace = &proxy_req.consumer.as_ref().unwrap().namespace; + state.metrics.count_http_total_request(namespace); - match Protocol::match_protocol(&mut req) { - Protocol::Http => handle_http(req, rw_state.clone(), &ogmios_host).await, - Protocol::Websocket => handle_websocket(req, rw_state.clone(), &ogmios_host).await, + match proxy_req.protocol { + Protocol::Http => handle_http(proxy_req).await, + Protocol::Websocket => handle_websocket(proxy_req, rw_state).await, } } -async fn handle_http( - req: Request, - rw_state: Arc>, - ogmios_host: &str, -) -> Result { - let state = rw_state.read().await.clone(); - - state.metrics.count_http_total_request("dmtr_project_id"); - - let stream = TcpStream::connect(ogmios_host).await.unwrap(); +async fn handle_http(proxy_req: ProxyRequest) -> Result { + let stream = TcpStream::connect(proxy_req.instance_host).await.unwrap(); let io: TokioIo = TokioIo::new(stream); let (mut sender, conn) = http1_client::Builder::new() @@ -126,34 +106,39 @@ async fn handle_http( } }); - let resp = sender.send_request(req).await?; + let resp = sender.send_request(proxy_req.hyper_req).await?; Ok(resp.map(|b| b.boxed())) } async fn handle_websocket( - mut req: Request, + mut proxy_req: ProxyRequest, rw_state: Arc>, - ogmios_host: &str, ) -> Result { - let headers = req.headers(); + let headers = proxy_req.hyper_req.headers(); let upgrade = HeaderValue::from_static("Upgrade"); let websocket = HeaderValue::from_static("websocket"); let key = headers.get(SEC_WEBSOCKET_KEY); let derived = key.map(|k| derive_accept_key(k.as_bytes())); - let version = req.version(); - let ogmios_host = ogmios_host.to_string(); + let version = proxy_req.hyper_req.version(); + let instance_host = proxy_req.instance_host.to_string(); + let namespace = proxy_req.consumer.unwrap().namespace; + + let state = rw_state.read().await.clone(); + state.metrics.count_ws_total_connection(&namespace); tokio::task::spawn(async move { - match hyper::upgrade::on(&mut req).await { + match hyper::upgrade::on(&mut proxy_req.hyper_req).await { Ok(upgraded) => { - let state = rw_state.read().await.clone(); - let upgraded = TokioIo::new(upgraded); let client_stream = WebSocketStream::from_raw_socket(upgraded, Role::Server, None).await; let (client_outgoing, client_incoming) = client_stream.split(); - let url = Url::parse(&format!("ws://{ogmios_host}{}", req.uri())).unwrap(); + let url = Url::parse(&format!( + "ws://{instance_host}{}", + proxy_req.hyper_req.uri() + )) + .unwrap(); let connection_result = connect_async(url).await; if let Err(err) = connection_result { error!(error = err.to_string(), "fail to connect to the host"); @@ -164,7 +149,7 @@ async fn handle_websocket( let client_in = client_incoming .inspect_ok(|_| { - state.metrics.count_ws_total_frame(""); + state.metrics.count_ws_total_frame(&namespace); }) .forward(host_outgoing); let host_in = host_incoming.forward(client_outgoing); @@ -187,3 +172,56 @@ async fn handle_websocket( Ok(res) } + +#[derive(Debug)] +enum Protocol { + Http, + Websocket, +} + +#[derive(Debug)] +struct ProxyRequest { + hyper_req: Request, + instance_host: String, + consumer: Option, + protocol: Protocol, +} +impl ProxyRequest { + pub fn new(hyper_req: Request, state: &State) -> Self { + let port_host = get_header(&hyper_req, HOST.as_str()).unwrap().to_string(); + let captures = state.host_regex.captures(&port_host).unwrap(); + let network = captures.get(2).unwrap().as_str().to_string(); + let version = captures.get(3).unwrap().as_str().to_string(); + + let instance_host = format!("ogmios-{network}-{version}:{}", state.config.ogmios_port); + + let protocol = get_header(&hyper_req, UPGRADE.as_str()) + .map(|h| { + if h.eq_ignore_ascii_case("websocket") { + return Protocol::Websocket; + } + + Protocol::Http + }) + .unwrap_or(Protocol::Http); + + let mut proxy_req = Self { + hyper_req, + instance_host, + consumer: None, + protocol, + }; + + if let Some(key) = captures.get(1) { + proxy_req + .hyper_req + .headers_mut() + .insert(DMTR_API_KEY, HeaderValue::from_str(key.as_str()).unwrap()); + } + + let token = get_header(&proxy_req.hyper_req, DMTR_API_KEY).unwrap_or_default(); + proxy_req.consumer = state.get_auth_token(&network, &version, &token); + + proxy_req + } +} diff --git a/proxy/src/utils.rs b/proxy/src/utils.rs index c6674cd..4c99102 100644 --- a/proxy/src/utils.rs +++ b/proxy/src/utils.rs @@ -1,6 +1,6 @@ use bytes::Bytes; use http_body_util::{combinators::BoxBody, BodyExt, Full}; -use hyper::{body::Incoming, header::UPGRADE, Request, Response}; +use hyper::{body::Incoming, Request, Response}; pub const DMTR_API_KEY: &str = "dmtr-api-key"; @@ -16,22 +16,5 @@ pub fn full>(chunk: T) -> Body { pub fn get_header(req: &Request, key: &str) -> Option { req.headers() .get(key) - .and_then(|h| h.to_str().ok().and_then(|v| Some(v.to_string()))) -} - -pub enum Protocol { - Http, - Websocket, -} -impl Protocol { - pub fn match_protocol(req: &mut Request) -> Self { - if get_header(req, UPGRADE.as_str()) - .map(|h| h.eq_ignore_ascii_case("websocket")) - .unwrap_or(false) - { - return Self::Websocket; - } - - Self::Http - } + .and_then(|h| h.to_str().ok().map(|v| v.to_string())) } From 7e0b42b5e75cefb4946829ab9c2e78ef99970ad4 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Tue, 13 Feb 2024 11:28:26 -0300 Subject: [PATCH 12/23] feat(proxy): added ws/http metrics --- proxy/examples/README.md | 59 -------------- proxy/examples/docker-compose.yml | 33 -------- proxy/examples/proxy.toml | 30 -------- proxy/src/config.rs | 2 + proxy/src/main.rs | 21 ++++- proxy/src/metrics.rs | 69 ++++++++++++++--- proxy/src/proxy.rs | 123 +++++++++++++++++------------- 7 files changed, 152 insertions(+), 185 deletions(-) delete mode 100644 proxy/examples/README.md delete mode 100644 proxy/examples/docker-compose.yml delete mode 100644 proxy/examples/proxy.toml diff --git a/proxy/examples/README.md b/proxy/examples/README.md deleted file mode 100644 index ec3178d..0000000 --- a/proxy/examples/README.md +++ /dev/null @@ -1,59 +0,0 @@ -# Proxy Example - -execute docker compose up to run proxy container and a mock api, after that it's possible to request /headers of the mock api - - -in the proxy.toml file some plugins is enabled. - -## Metrics - -To access prometheus metrics, open the link below - -``` -http://0.0.0.0:5000/metrics -``` - -## Http - -the key on the host will be extract by the plugin and inject in the header. - -```bash -curl http://dmtr_kupo1d988zmt0g4skjdt6xdxkg5zp23f55ttpxfmsemy6fa.0.0.0.0.nip.io/headers -``` - -## Websocket - -Below a script to access the mock api using websocket. - -```nodejs -const WebSocket = require("ws"); - -const ws = new WebSocket("ws://0.0.0.0:80", { - headers: { - "dmtr-api-key": `dmtr_kupo1d988zmt0g4skjdt6xdxkg5zp23f55ttpxfmsemy6fa`, - }, -}); -let interval = 0; - -ws.on("open", () => { - console.log("Connected to WebSocket server"); - - interval = setInterval(() => { - ws.send(`Hello, WebSocket server! ${Math.random()}`); - }, 10); -}); - -ws.on("message", (message) => { - console.log(`Received message from server: ${message}`); -}); - -ws.on("close", () => { - console.log("Connection to WebSocket server closed"); - clearInterval(interval); -}); - -ws.on("error", (err) => { - console.error(err); -}); - -``` \ No newline at end of file diff --git a/proxy/examples/docker-compose.yml b/proxy/examples/docker-compose.yml deleted file mode 100644 index 485a1ce..0000000 --- a/proxy/examples/docker-compose.yml +++ /dev/null @@ -1,33 +0,0 @@ -version: "3.8" - -networks: - proxy-network: - driver: bridge - -services: - proxy: - container_name: proxy - build: ../ - networks: - - proxy-network - ports: - - "80:80" - - "5000:5000" - deploy: - restart_policy: - condition: any - environment: - - PROXY_CONFIG_PATH=/opt/proxy/proxy.toml - volumes: - - ./proxy.toml:/opt/proxy/proxy.toml - - mock_api: - container_name: mock_api - image: paulobressan/mock-api:1.0.0 - networks: - - proxy-network - deploy: - restart_policy: - condition: any - environment: - - PORT=80 diff --git a/proxy/examples/proxy.toml b/proxy/examples/proxy.toml deleted file mode 100644 index bb19e80..0000000 --- a/proxy/examples/proxy.toml +++ /dev/null @@ -1,30 +0,0 @@ -proxy_addr = "0.0.0.0:80" -prometheus_addr = "0.0.0.0:5000" - -[[routes]] -path = "/headers" -host = "mock_api" -port = 80 -protocol = "http" - -[[routes]] -path = "/" -host = "mock_api" -port = 80 -protocol = "websocket" - -[[http_plugins]] -type = "AuthDmtrPlugin" -priority = 1 - -[[http_plugins]] -type = "RateLimiterPlugin" -priority = 2 - -[[http_plugins]] -type = "HostKeyHeaderPlugin" -priority = 0 - -[[websocket_plugins]] -type = "RateLimiterPlugin" -priority = 0 \ No newline at end of file diff --git a/proxy/src/config.rs b/proxy/src/config.rs index 0817f29..5e2a8aa 100644 --- a/proxy/src/config.rs +++ b/proxy/src/config.rs @@ -3,6 +3,7 @@ use std::env; #[derive(Debug, Clone)] pub struct Config { pub proxy_addr: String, + pub proxy_namespace: String, pub prometheus_addr: String, pub ogmios_port: u16, } @@ -11,6 +12,7 @@ impl Config { pub fn new() -> Self { Self { proxy_addr: env::var("PROXY_ADDR").expect("PROXY_ADDR must be set"), + proxy_namespace: env::var("PROXY_NAMESPACE").unwrap_or("ftr-ogmios-v1".into()), prometheus_addr: env::var("PROMETHEUS_ADDR").expect("PROMETHEUS_ADDR must be set"), ogmios_port: env::var("OGMIOS_PORT") .expect("OGMIOS_PORT must be set") diff --git a/proxy/src/main.rs b/proxy/src/main.rs index 74f89ab..46b9b4b 100644 --- a/proxy/src/main.rs +++ b/proxy/src/main.rs @@ -1,11 +1,13 @@ use config::Config; use dotenv::dotenv; use metrics::Metrics; +use operator::kube::ResourceExt; use operator::OgmiosPort; use prometheus::Registry; use regex::Regex; use std::collections::HashMap; use std::error::Error; +use std::fmt::Display; use std::sync::Arc; use tokio::sync::RwLock; use tracing::Level; @@ -33,9 +35,23 @@ async fn main() -> Result<(), Box> { Ok(()) } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub struct Consumer { namespace: String, + port_name: String, +} +impl Consumer { + pub fn new(namespace: String, port_name: String) -> Self { + Self { + namespace, + port_name, + } + } +} +impl Display for Consumer { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}.{}", self.namespace, self.port_name) + } } #[derive(Debug, Clone)] @@ -66,9 +82,10 @@ impl State { let version = crd.spec.version; let auth_token = crd.status.as_ref().unwrap().auth_token.clone(); let namespace = crd.metadata.namespace.as_ref().unwrap().clone(); + let port_name = crd.name_any(); let hash_key = format!("{}.{}.{}", network, version, auth_token); - let consumer = Consumer { namespace }; + let consumer = Consumer::new(namespace, port_name); self.consumers.insert(hash_key, consumer); } diff --git a/proxy/src/metrics.rs b/proxy/src/metrics.rs index bf177ee..8ba3b2d 100644 --- a/proxy/src/metrics.rs +++ b/proxy/src/metrics.rs @@ -10,8 +10,9 @@ use tokio::net::TcpListener; use tokio::sync::RwLock; use tracing::{error, info}; +use crate::proxy::ProxyRequest; use crate::utils::{full, ProxyResponse}; -use crate::State; +use crate::{Consumer, State}; #[derive(Debug, Clone)] pub struct Metrics { @@ -25,19 +26,26 @@ impl Metrics { pub fn try_new(registry: Registry) -> Result> { let ws_total_frame = IntCounterVec::new( opts!("proxy_ws_total_frame", "total of websocket frame",), - &["namespace"], + &["namespace", "instance", "route", "consumer"], ) .unwrap(); let ws_total_connection = IntCounterVec::new( opts!("proxy_ws_total_connection", "total of websocket connection",), - &["namespace"], + &["namespace", "instance", "route", "consumer"], ) .unwrap(); let http_total_request = IntCounterVec::new( opts!("proxy_http_total_request", "total of http request",), - &["namespace"], + &[ + "namespace", + "instance", + "route", + "status_code", + "protocol", + "consumer", + ], ) .unwrap(); @@ -57,16 +65,57 @@ impl Metrics { self.registry.gather() } - pub fn count_ws_total_frame(&self, namespace: &str) { - self.ws_total_frame.with_label_values(&[namespace]).inc() + pub fn count_ws_total_frame(&self, proxy_req: &ProxyRequest) { + let consumer = proxy_req + .consumer + .as_ref() + .unwrap_or(&Consumer::default()) + .to_string(); + + self.ws_total_frame + .with_label_values(&[ + &proxy_req.namespace, + &proxy_req.instance, + &proxy_req.host, + &consumer, + ]) + .inc() } - pub fn count_http_total_request(&self, namespace: &str) { - self.http_total_request.with_label_values(&[namespace]).inc() + pub fn count_ws_total_connection(&self, proxy_req: &ProxyRequest) { + let consumer = proxy_req + .consumer + .as_ref() + .unwrap_or(&Consumer::default()) + .to_string(); + + self.ws_total_connection + .with_label_values(&[ + &proxy_req.namespace, + &proxy_req.instance, + &proxy_req.host, + &consumer, + ]) + .inc() } - pub fn count_ws_total_connection(&self, namespace: &str) { - self.ws_total_connection.with_label_values(&[namespace]).inc() + pub fn count_http_total_request(&self, proxy_req: &ProxyRequest, status_code: StatusCode) { + let consumer = proxy_req + .consumer + .as_ref() + .unwrap_or(&Consumer::default()) + .to_string(); + + self.http_total_request + .with_label_values(&[ + &proxy_req.namespace, + &proxy_req.instance, + &proxy_req.host, + &status_code.as_u16().to_string(), + &proxy_req.protocol.to_string(), + &consumer, + ]) + .inc() } } diff --git a/proxy/src/proxy.rs b/proxy/src/proxy.rs index 82b7220..8374b37 100644 --- a/proxy/src/proxy.rs +++ b/proxy/src/proxy.rs @@ -9,6 +9,7 @@ use hyper::server::conn::http1 as http1_server; use hyper::service::service_fn; use hyper::{Request, Response, StatusCode}; use hyper_util::rt::TokioIo; +use std::fmt::Display; use std::net::SocketAddr; use std::str::FromStr; use std::sync::Arc; @@ -68,11 +69,11 @@ pub async fn start(rw_state: Arc>) { } async fn handle( - req: Request, + mut hyper_req: Request, rw_state: Arc>, ) -> Result { let state = rw_state.read().await.clone(); - let proxy_req = ProxyRequest::new(req, &state); + let proxy_req = ProxyRequest::new(&mut hyper_req, &state); if proxy_req.consumer.is_none() { return Ok(Response::builder() @@ -81,17 +82,28 @@ async fn handle( .unwrap()); } - let namespace = &proxy_req.consumer.as_ref().unwrap().namespace; - state.metrics.count_http_total_request(namespace); + let response_result = match proxy_req.protocol { + Protocol::Http => handle_http(hyper_req, &proxy_req).await, + Protocol::Websocket => handle_websocket(hyper_req, &proxy_req, rw_state).await, + }; - match proxy_req.protocol { - Protocol::Http => handle_http(proxy_req).await, - Protocol::Websocket => handle_websocket(proxy_req, rw_state).await, - } + match &response_result { + Ok(response) => { + state + .metrics + .count_http_total_request(&proxy_req, response.status()); + } + Err(_) => todo!("send error to prometheus"), + }; + + response_result } -async fn handle_http(proxy_req: ProxyRequest) -> Result { - let stream = TcpStream::connect(proxy_req.instance_host).await.unwrap(); +async fn handle_http( + hyper_req: Request, + proxy_req: &ProxyRequest, +) -> Result { + let stream = TcpStream::connect(&proxy_req.instance).await.unwrap(); let io: TokioIo = TokioIo::new(stream); let (mut sender, conn) = http1_client::Builder::new() @@ -106,39 +118,34 @@ async fn handle_http(proxy_req: ProxyRequest) -> Result, + proxy_req: &ProxyRequest, rw_state: Arc>, ) -> Result { - let headers = proxy_req.hyper_req.headers(); + let headers = hyper_req.headers(); let upgrade = HeaderValue::from_static("Upgrade"); let websocket = HeaderValue::from_static("websocket"); let key = headers.get(SEC_WEBSOCKET_KEY); let derived = key.map(|k| derive_accept_key(k.as_bytes())); - let version = proxy_req.hyper_req.version(); - let instance_host = proxy_req.instance_host.to_string(); - let namespace = proxy_req.consumer.unwrap().namespace; + let version = hyper_req.version(); + let proxy_req = proxy_req.clone(); let state = rw_state.read().await.clone(); - state.metrics.count_ws_total_connection(&namespace); - tokio::task::spawn(async move { - match hyper::upgrade::on(&mut proxy_req.hyper_req).await { + match hyper::upgrade::on(&mut hyper_req).await { Ok(upgraded) => { let upgraded = TokioIo::new(upgraded); let client_stream = WebSocketStream::from_raw_socket(upgraded, Role::Server, None).await; let (client_outgoing, client_incoming) = client_stream.split(); - let url = Url::parse(&format!( - "ws://{instance_host}{}", - proxy_req.hyper_req.uri() - )) - .unwrap(); + let url = + Url::parse(&format!("ws://{}{}", proxy_req.instance, hyper_req.uri())).unwrap(); let connection_result = connect_async(url).await; if let Err(err) = connection_result { error!(error = err.to_string(), "fail to connect to the host"); @@ -149,11 +156,13 @@ async fn handle_websocket( let client_in = client_incoming .inspect_ok(|_| { - state.metrics.count_ws_total_frame(&namespace); + state.metrics.count_ws_total_frame(&proxy_req); }) .forward(host_outgoing); let host_in = host_incoming.forward(client_outgoing); + state.metrics.count_ws_total_connection(&proxy_req); + future::select(client_in, host_in).await; } Err(err) => { @@ -173,29 +182,41 @@ async fn handle_websocket( Ok(res) } -#[derive(Debug)] -enum Protocol { +#[derive(Debug, Clone)] +pub enum Protocol { Http, Websocket, } +impl Display for Protocol { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Protocol::Http => write!(f, "http"), + Protocol::Websocket => write!(f, "websocket"), + } + } +} -#[derive(Debug)] -struct ProxyRequest { - hyper_req: Request, - instance_host: String, - consumer: Option, - protocol: Protocol, +#[derive(Debug, Clone)] +pub struct ProxyRequest { + pub namespace: String, + pub host: String, + pub instance: String, + pub consumer: Option, + pub protocol: Protocol, } impl ProxyRequest { - pub fn new(hyper_req: Request, state: &State) -> Self { - let port_host = get_header(&hyper_req, HOST.as_str()).unwrap().to_string(); - let captures = state.host_regex.captures(&port_host).unwrap(); + pub fn new(hyper_req: &mut Request, state: &State) -> Self { + let mut host = get_header(hyper_req, HOST.as_str()).unwrap(); + let host_regex = host.clone(); + + let captures = state.host_regex.captures(&host_regex).unwrap(); let network = captures.get(2).unwrap().as_str().to_string(); let version = captures.get(3).unwrap().as_str().to_string(); - let instance_host = format!("ogmios-{network}-{version}:{}", state.config.ogmios_port); + let instance = format!("ogmios-{network}-{version}:{}", state.config.ogmios_port); + let namespace = state.config.proxy_namespace.clone(); - let protocol = get_header(&hyper_req, UPGRADE.as_str()) + let protocol = get_header(hyper_req, UPGRADE.as_str()) .map(|h| { if h.eq_ignore_ascii_case("websocket") { return Protocol::Websocket; @@ -205,23 +226,23 @@ impl ProxyRequest { }) .unwrap_or(Protocol::Http); - let mut proxy_req = Self { - hyper_req, - instance_host, - consumer: None, - protocol, - }; - if let Some(key) = captures.get(1) { - proxy_req - .hyper_req + let key = key.as_str(); + hyper_req .headers_mut() - .insert(DMTR_API_KEY, HeaderValue::from_str(key.as_str()).unwrap()); + .insert(DMTR_API_KEY, HeaderValue::from_str(key).unwrap()); + host = host.replace(&format!("{key}."), ""); } - let token = get_header(&proxy_req.hyper_req, DMTR_API_KEY).unwrap_or_default(); - proxy_req.consumer = state.get_auth_token(&network, &version, &token); + let token = get_header(hyper_req, DMTR_API_KEY).unwrap_or_default(); + let consumer = state.get_auth_token(&network, &version, &token); - proxy_req + Self { + namespace, + instance, + consumer, + protocol, + host, + } } } From 2bc02a9a87a89b4ea2e6a32ddcefea93a09bab95 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Wed, 14 Feb 2024 12:21:26 -0300 Subject: [PATCH 13/23] feat: added docker files to build each app --- docker/dockerfile.operator | 13 +++++++++++++ docker/dockerfile.proxy | 14 ++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 docker/dockerfile.operator create mode 100644 docker/dockerfile.proxy diff --git a/docker/dockerfile.operator b/docker/dockerfile.operator new file mode 100644 index 0000000..725f176 --- /dev/null +++ b/docker/dockerfile.operator @@ -0,0 +1,13 @@ +FROM rust:1.74-slim-buster as build + +WORKDIR /app + +COPY ./Cargo.toml ./Cargo.toml +COPY ./operator ./operator +COPY ./proxy ./proxy + +RUN cargo build --release + +FROM rust:1.74-slim-buster +COPY --from=build /app/target/release/controller . +CMD ["./controller"] \ No newline at end of file diff --git a/docker/dockerfile.proxy b/docker/dockerfile.proxy new file mode 100644 index 0000000..694e248 --- /dev/null +++ b/docker/dockerfile.proxy @@ -0,0 +1,14 @@ +FROM rust:1.74-slim-buster as build + +WORKDIR /app + +COPY ./Cargo.toml ./Cargo.toml +COPY ./operator ./operator +COPY ./proxy ./proxy + +RUN cargo build --release + +FROM rust:1.74-slim-buster +COPY --from=build /app/target/release/proxy . +CMD ["./proxy"] +LABEL service=proxy \ No newline at end of file From 75d603cea7a712184e8d8d3c0d47e9cc8fe69b80 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Wed, 14 Feb 2024 12:22:08 -0300 Subject: [PATCH 14/23] chore(proxy): added an example using k8s --- .gitignore | 3 +- proxy/Dockerfile | 15 -- proxy/examples/README.md | 30 ++++ proxy/examples/manifest.yaml | 307 +++++++++++++++++++++++++++++++++++ proxy/examples/setup | 22 +++ 5 files changed, 361 insertions(+), 16 deletions(-) delete mode 100644 proxy/Dockerfile create mode 100644 proxy/examples/README.md create mode 100644 proxy/examples/manifest.yaml create mode 100755 proxy/examples/setup diff --git a/.gitignore b/.gitignore index c41cc9e..7b7cd20 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/target \ No newline at end of file +/target +env-crd.yaml \ No newline at end of file diff --git a/proxy/Dockerfile b/proxy/Dockerfile deleted file mode 100644 index d5be2f6..0000000 --- a/proxy/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM rust:1.74-slim-buster as build - -WORKDIR /app - -COPY ./Cargo.lock ./Cargo.lock -COPY ./Cargo.toml ./Cargo.toml -COPY ./src ./src - -RUN cargo build --release - -FROM rust:1.74-slim-buster - -COPY --from=build /app/target/release/proxy . - -CMD ["./proxy"] \ No newline at end of file diff --git a/proxy/examples/README.md b/proxy/examples/README.md new file mode 100644 index 0000000..8069d77 --- /dev/null +++ b/proxy/examples/README.md @@ -0,0 +1,30 @@ +# Proxy Run Example + +This example shows how to run the proxy and all dependencies including the operator, Prometheus, and Grafana. + +## Setup + +The setup file will execute some commands to prepare the environment. This script needs `kind`, `docker`, and `kubectl`. This example uses a mock API to simulate the Ogmios instance and only to Mainnet. + +```sh +./setup +``` + +## Using + +To use the proxy, it's necessary to create a port forward and to use Grafana as well. In Grafana, to connect Prometheus it's necessary to use this endpoint `http://prometheus` + +For example, with a port forward created and using port 8080 it's possible to request the endpoint below. + +**HTTP** +`http://dmtr_ogmios1faekjknsx3gnwarjt9e5c3t3xa2hgcmdxdmste4k6h.mainnet.ogmios-1.localhost:8080/headers` + +**ws** +`http://dmtr_ogmios1faekjknsx3gnwarjt9e5c3t3xa2hgcmdxdmste4k6h.mainnet.ogmios-1.localhost:8080` + +the proxy will call a mock API. + +Port Keys available +- dmtr_ogmios1faekjknsx3gnwarjt9e5c3t3xa2hgcmdxdmste4k6h +- dmtr_ogmios124u5ga63wqc5u6je2f297azpvfvyxdtewpgslrdk79 + diff --git a/proxy/examples/manifest.yaml b/proxy/examples/manifest.yaml new file mode 100644 index 0000000..7a808cf --- /dev/null +++ b/proxy/examples/manifest.yaml @@ -0,0 +1,307 @@ +# Project namespace +apiVersion: v1 +kind: Namespace +metadata: + name: prj-mainnet-test +--- +# Access for the service account +kind: ClusterRole +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: kube-rs +rules: + - apiGroups: ["demeter.run"] + resources: ["ogmiosports", "ogmiosports/status", "ogmiosports/finalizers"] + verbs: ["get", "list", "watch", "patch", "update"] + - apiGroups: ["events.k8s.io"] + resources: ["events"] + verbs: ["create"] +--- +# Scoped service account +apiVersion: v1 +kind: ServiceAccount +metadata: + name: kube-rs + namespace: prj-mainnet-test +automountServiceAccountToken: true +--- +# Binding the role to the account +kind: ClusterRoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: kube-rs-binding + namespace: prj-mainnet-test +subjects: + - kind: ServiceAccount + namespace: prj-mainnet-test + name: kube-rs +roleRef: + kind: ClusterRole + name: kube-rs + apiGroup: rbac.authorization.k8s.io +--- +# Grafana dependence +apiVersion: apps/v1 +kind: Deployment +metadata: + name: grafana + namespace: prj-mainnet-test + labels: + app: grafana +spec: + selector: + matchLabels: + app: grafana + strategy: + type: Recreate + template: + metadata: + labels: + app: grafana + spec: + containers: + - name: grafana + image: grafana/grafana + ports: + - name: grafana + containerPort: 3000 +--- +apiVersion: v1 +kind: Service +metadata: + name: app + namespace: prj-mainnet-test + labels: + app: grafana +spec: + ports: + - port: 3000 + selector: + app: grafana + clusterIP: None +--- +# Prometheus dependence +apiVersion: v1 +data: + prometheus.yml: | + global: + scrape_interval: 30s + evaluation_interval: 30s + + scrape_configs: + - job_name: proxy + static_configs: + - targets: ["proxy:9187"] +kind: ConfigMap +metadata: + name: prometheus-vol + namespace: prj-mainnet-test +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: prometheus + namespace: prj-mainnet-test + labels: + app: prometheus +spec: + selector: + matchLabels: + app: prometheus + strategy: + type: Recreate + template: + metadata: + labels: + app: prometheus + spec: + containers: + - name: prometheus + image: prom/prometheus + ports: + - name: prometheus + containerPort: 9090 + volumeMounts: + - name: configs + mountPath: /etc/prometheus + volumes: + - name: configs + configMap: + name: prometheus-vol +--- +apiVersion: v1 +kind: Service +metadata: + name: prometheus + namespace: prj-mainnet-test + labels: + app: prometheus +spec: + selector: + app: prometheus + type: ClusterIP + ports: + - name: prometheus + port: 80 + targetPort: 9090 + protocol: TCP +--- +# Run proxy +apiVersion: apps/v1 +kind: Deployment +metadata: + name: proxy + namespace: prj-mainnet-test + labels: + app: proxy +spec: + selector: + matchLabels: + app: proxy + template: + metadata: + labels: + app: proxy + spec: + serviceAccountName: kube-rs + containers: + - name: proxy + image: proxy:1.0 + ports: + - containerPort: 80 + env: + - name: PROXY_ADDR + value: "0.0.0.0:80" + - name: PROMETHEUS_ADDR + value: "0.0.0.0:9187" + - name: OGMIOS_PORT + value: "80" +--- +apiVersion: v1 +kind: Service +metadata: + name: proxy + namespace: prj-mainnet-test + labels: + app: proxy +spec: + selector: + app: proxy + type: ClusterIP + ports: + - name: proxy + port: 80 + targetPort: 80 + protocol: TCP + - name: proxy-prometheus + port: 9187 + targetPort: 9187 + protocol: TCP +--- +# Run operator +apiVersion: apps/v1 +kind: Deployment +metadata: + name: operator + namespace: prj-mainnet-test + labels: + app: operator +spec: + selector: + matchLabels: + app: operator + template: + metadata: + labels: + app: operator + spec: + serviceAccountName: kube-rs + containers: + - name: operator + image: operator:1.0 + ports: + - containerPort: 9187 + env: + - name: ADDR + value: "0.0.0.0:9187" +--- +apiVersion: v1 +kind: Service +metadata: + name: operator + namespace: prj-mainnet-test + labels: + app: operator +spec: + selector: + app: operator + type: ClusterIP + ports: + - name: operator + port: 80 + targetPort: 9187 + protocol: TCP +--- +# Mock dependence +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ogmios-mainnet-1 + namespace: prj-mainnet-test + labels: + app: ogmios-mainnet-1 +spec: + selector: + matchLabels: + app: ogmios-mainnet-1 + strategy: + type: Recreate + template: + metadata: + labels: + app: ogmios-mainnet-1 + spec: + containers: + - name: ogmios-mainnet-1 + image: paulobressan/mock-api:1.0.0 + ports: + - containerPort: 80 + env: + - name: PORT + value: "80" +--- +apiVersion: v1 +kind: Service +metadata: + name: ogmios-mainnet-1 + namespace: prj-mainnet-test + labels: + app: ogmios-mainnet-1 +spec: + selector: + app: ogmios-mainnet-1 + type: ClusterIP + ports: + - port: 80 + targetPort: 80 + protocol: TCP +--- +# Ogmios Port 1 +apiVersion: demeter.run/v1alpha1 +kind: OgmiosPort +metadata: + name: mainnet-user-1 + namespace: prj-mainnet-test +spec: + network: "mainnet" + version: 1 +--- +# Ogmios Port 2 +apiVersion: demeter.run/v1alpha1 +kind: OgmiosPort +metadata: + name: mainnet-user-2 + namespace: prj-mainnet-test +spec: + network: "mainnet" + version: 1 \ No newline at end of file diff --git a/proxy/examples/setup b/proxy/examples/setup new file mode 100755 index 0000000..bc6ecbe --- /dev/null +++ b/proxy/examples/setup @@ -0,0 +1,22 @@ +#!/bin/bash + +~/go/bin/kind create cluster + +echo "Building operator CRD" +cargo run --bin=crdgen >> env-crd.yaml --manifest-path ../../operator/Cargo.toml + +kubectl apply -f env-crd.yaml + +echo "Building proxy image" +docker build -t proxy:1.0 -f ../../docker/dockerfile.proxy ../../ + +echo "Building operator image" +docker build -t operator:1.0 -f ../../docker/dockerfile.operator ../../ + +echo "Loading proxy image" +~/go/bin/kind load docker-image proxy:1.0 + +echo "Loading operator image" +~/go/bin/kind load docker-image operator:1.0 + +kubectl apply -f manifest.yaml \ No newline at end of file From 5550e50ad051e365a75c38e19ea76ffcae6b320d Mon Sep 17 00:00:00 2001 From: paulobressan Date: Wed, 14 Feb 2024 16:12:56 -0300 Subject: [PATCH 15/23] feat(operator): added thread to metrics collector --- operator/src/main.rs | 5 +++-- operator/src/metrics.rs | 13 ++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/operator/src/main.rs b/operator/src/main.rs index f06d4aa..b6b6c5d 100644 --- a/operator/src/main.rs +++ b/operator/src/main.rs @@ -6,7 +6,7 @@ use prometheus::{Encoder, TextEncoder}; use std::{io, sync::Arc}; use tracing::{info, Level}; -use operator::{controller, State}; +use operator::{controller, metrics as metrics_collector, State}; #[get("/metrics")] async fn metrics(c: Data>, _req: HttpRequest) -> impl Responder { @@ -31,6 +31,7 @@ async fn main() -> io::Result<()> { let state = Arc::new(State::default()); let controller = controller::run(state.clone()); + let metrics_collector = metrics_collector::run_metrics_collector(state.clone()); let addr = std::env::var("ADDR").unwrap_or("0.0.0.0:8080".into()); @@ -44,7 +45,7 @@ async fn main() -> io::Result<()> { .bind(&addr)?; info!({ addr }, "metrics server running"); - tokio::join!(server.run(), controller,).0?; + tokio::join!(server.run(), controller, metrics_collector).0?; Ok(()) } diff --git a/operator/src/metrics.rs b/operator/src/metrics.rs index f54b740..1f90923 100644 --- a/operator/src/metrics.rs +++ b/operator/src/metrics.rs @@ -1,7 +1,10 @@ +use std::sync::Arc; + use kube::ResourceExt; use prometheus::{opts, IntCounterVec, Registry}; +use tracing::{info, instrument}; -use crate::{Error, OgmiosPort}; +use crate::{Error, OgmiosPort, State}; #[derive(Clone)] pub struct Metrics { @@ -36,3 +39,11 @@ impl Metrics { .inc() } } + +#[instrument("metrics collector run", skip_all)] +pub async fn run_metrics_collector(_state: Arc) { + tokio::spawn(async move { + info!("collecting metrics running"); + }); +} + From 6959d8a8be212092e26db96be3d6bdc2382d2cd7 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Wed, 14 Feb 2024 16:51:00 -0300 Subject: [PATCH 16/23] chore(docker): fixed docker image --- docker/dockerfile.operator | 3 +++ docker/dockerfile.proxy | 3 +++ 2 files changed, 6 insertions(+) diff --git a/docker/dockerfile.operator b/docker/dockerfile.operator index 725f176..05688c1 100644 --- a/docker/dockerfile.operator +++ b/docker/dockerfile.operator @@ -2,6 +2,9 @@ FROM rust:1.74-slim-buster as build WORKDIR /app +RUN apt update +RUN apt install -y pkg-config libssl-dev + COPY ./Cargo.toml ./Cargo.toml COPY ./operator ./operator COPY ./proxy ./proxy diff --git a/docker/dockerfile.proxy b/docker/dockerfile.proxy index 694e248..2c12356 100644 --- a/docker/dockerfile.proxy +++ b/docker/dockerfile.proxy @@ -2,6 +2,9 @@ FROM rust:1.74-slim-buster as build WORKDIR /app +RUN apt update +RUN apt install -y pkg-config libssl-dev + COPY ./Cargo.toml ./Cargo.toml COPY ./operator ./operator COPY ./proxy ./proxy From a1e955a7facb498e908073d1029447ae12a9e552 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Wed, 14 Feb 2024 18:52:58 -0300 Subject: [PATCH 17/23] chore(proxy): adjusted metrics name --- proxy/src/metrics.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/proxy/src/metrics.rs b/proxy/src/metrics.rs index 8ba3b2d..5fad374 100644 --- a/proxy/src/metrics.rs +++ b/proxy/src/metrics.rs @@ -25,19 +25,22 @@ pub struct Metrics { impl Metrics { pub fn try_new(registry: Registry) -> Result> { let ws_total_frame = IntCounterVec::new( - opts!("proxy_ws_total_frame", "total of websocket frame",), + opts!("ogmios_proxy_ws_total_frame", "total of websocket frame",), &["namespace", "instance", "route", "consumer"], ) .unwrap(); let ws_total_connection = IntCounterVec::new( - opts!("proxy_ws_total_connection", "total of websocket connection",), + opts!( + "ogmios_proxy_ws_total_connection", + "total of websocket connection", + ), &["namespace", "instance", "route", "consumer"], ) .unwrap(); let http_total_request = IntCounterVec::new( - opts!("proxy_http_total_request", "total of http request",), + opts!("ogmios_proxy_http_total_request", "total of http request",), &[ "namespace", "instance", From 714b5e91cdb6810d5dbe3f27d47f988636e97bef Mon Sep 17 00:00:00 2001 From: paulobressan Date: Wed, 14 Feb 2024 18:54:29 -0300 Subject: [PATCH 18/23] feat(operator): added metrics collector --- Cargo.lock | 262 +++++++++++++++++++++++++++++++++++++++- operator/Cargo.toml | 3 + operator/src/config.rs | 38 +++++- operator/src/lib.rs | 6 + operator/src/main.rs | 2 +- operator/src/metrics.rs | 174 +++++++++++++++++++++++++- 6 files changed, 473 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 66504db..96c58d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -423,14 +423,16 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.33" +version = "0.4.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f13690e35a5e4ace198e7beea2895d29f3a9cc55015fcebe6336bd2010af9eb" +checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" dependencies = [ "android-tzdata", "iana-time-zone", + "js-sys", "num-traits", "serde", + "wasm-bindgen", "windows-targets 0.52.0", ] @@ -613,6 +615,22 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + [[package]] name = "flate2" version = "1.0.28" @@ -629,6 +647,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -901,6 +934,7 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", + "h2 0.3.24", "http 0.2.11", "http-body 0.4.6", "httparse", @@ -962,6 +996,19 @@ dependencies = [ "tokio-io-timeout", ] +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper 0.14.28", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "hyper-util" version = "0.1.3" @@ -1040,6 +1087,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "ipnet" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" + [[package]] name = "itoa" version = "1.0.10" @@ -1238,6 +1291,12 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + [[package]] name = "local-channel" version = "0.1.5" @@ -1304,6 +1363,24 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -1354,12 +1431,50 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "openssl" +version = "0.10.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15c9d69dd87a29568d4d017cfe8ec518706046a05184e5aea92d0af890b803c8" +dependencies = [ + "bitflags 2.4.2", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "openssl-sys" +version = "0.9.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22e1bf214306098e4832460f797824c05d25aacdf896f64a985fb0fd992454ae" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "operator" version = "0.1.0" @@ -1368,12 +1483,15 @@ dependencies = [ "argon2", "base64", "bech32", + "chrono", "dotenv", "futures", "k8s-openapi", "kube", "lazy_static", "prometheus", + "regex", + "reqwest", "schemars", "serde", "serde_json", @@ -1680,6 +1798,46 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +[[package]] +name = "reqwest" +version = "0.11.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6920094eb85afde5e4a138be3f2de8bbdf28000f0029e72c45025a56b042251" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2 0.3.24", + "http 0.2.11", + "http-body 0.4.6", + "hyper 0.14.28", + "hyper-tls", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "ring" version = "0.17.7" @@ -1709,6 +1867,19 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +dependencies = [ + "bitflags 2.4.2", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + [[package]] name = "rustls" version = "0.21.10" @@ -2028,6 +2199,45 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a365e8cd18e44762ef95d87f284f4b5cd04107fec2ff3052bd6a3e6069669e67" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys 0.52.0", +] + [[package]] name = "thiserror" version = "1.0.56" @@ -2144,6 +2354,16 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.24.1" @@ -2391,6 +2611,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.4" @@ -2437,6 +2663,18 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877b9c3f61ceea0e56331985743b13f3d25c406a7098d45180fb5f09bc19ed97" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.91" @@ -2466,6 +2704,16 @@ version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" +[[package]] +name = "web-sys" +version = "0.3.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96565907687f7aceb35bc5fc03770a8a0471d82e479f25832f54a0e3f4b28446" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "winapi" version = "0.3.9" @@ -2629,6 +2877,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + [[package]] name = "zerocopy" version = "0.7.32" diff --git a/operator/Cargo.toml b/operator/Cargo.toml index 0f722b3..dff25ec 100644 --- a/operator/Cargo.toml +++ b/operator/Cargo.toml @@ -11,12 +11,15 @@ actix-web = "4.4.0" argon2 = "0.5.2" base64 = "0.21.5" bech32 = "0.9.1" +chrono = "0.4.34" dotenv = "0.15.0" futures = "0.3.29" k8s-openapi = { version = "0.20.0", features = ["latest"] } kube = { version = "0.87.1", features = ["runtime", "client", "derive"] } lazy_static = "1.4.0" prometheus = "0.13.3" +regex = "1.10.3" +reqwest = { version = "0.11.24", features = ["json"] } schemars = "0.8.16" serde = { version = "1.0.193", features = ["derive"] } serde_json = "1.0.108" diff --git a/operator/src/config.rs b/operator/src/config.rs index e53226f..626330c 100644 --- a/operator/src/config.rs +++ b/operator/src/config.rs @@ -1,5 +1,5 @@ use lazy_static::lazy_static; -use std::env; +use std::{collections::HashMap, env, time::Duration}; lazy_static! { static ref CONTROLLER_CONFIG: Config = Config::from_env(); @@ -14,14 +14,44 @@ pub struct Config { pub dns_zone: String, pub ingress_class: String, pub api_key_salt: String, + pub dcu_per_frame: HashMap, + pub metrics_delay: Duration, + pub prometheus_url: String, } impl Config { pub fn from_env() -> Self { + let dns_zone = env::var("DNS_ZONE").unwrap_or("demeter.run".into()); + let ingress_class = env::var("INGRESS_CLASS").unwrap_or("ogmios-v1".into()); + let api_key_salt = env::var("API_KEY_SALT").unwrap_or("ogmios-salt".into()); + let dcu_per_frame = env::var("DCU_PER_FRAME") + .expect("DCU_PER_FRAME must be set") + .split(',') + .map(|pair| { + let parts: Vec<&str> = pair.split('=').collect(); + let dcu = parts[1] + .parse::() + .expect("DCU_PER_FRAME must be NETWORK=NUMBER"); + + (parts[0].into(), dcu) + }) + .collect(); + + let metrics_delay = Duration::from_secs( + env::var("METRICS_DELAY") + .expect("METRICS_DELAY must be set") + .parse::() + .expect("METRICS_DELAY must be a number"), + ); + let prometheus_url = env::var("PROMETHEUS_URL").expect("PROMETHEUS_URL must be set"); + Self { - dns_zone: env::var("DNS_ZONE").unwrap_or("demeter.run".into()), - ingress_class: env::var("INGRESS_CLASS").unwrap_or("ogmios-v1".into()), - api_key_salt: env::var("API_KEY_SALT").unwrap_or("ogmios-salt".into()), + dns_zone, + ingress_class, + api_key_salt, + dcu_per_frame, + metrics_delay, + prometheus_url, } } } diff --git a/operator/src/lib.rs b/operator/src/lib.rs index 9042d51..6097a27 100644 --- a/operator/src/lib.rs +++ b/operator/src/lib.rs @@ -23,6 +23,12 @@ pub enum Error { #[error("Parse Int error: {0}")] ParseIntError(#[source] std::num::ParseIntError), + + #[error("Http Request error: {0}")] + HttpError(String), + + #[error("Config Error: {0}")] + ConfigError(String), } impl Error { pub fn metric_label(&self) -> String { diff --git a/operator/src/main.rs b/operator/src/main.rs index b6b6c5d..bca24ae 100644 --- a/operator/src/main.rs +++ b/operator/src/main.rs @@ -28,7 +28,7 @@ async fn main() -> io::Result<()> { tracing_subscriber::fmt().with_max_level(Level::INFO).init(); - let state = Arc::new(State::default()); + let state = Arc::new(State::new()); let controller = controller::run(state.clone()); let metrics_collector = metrics_collector::run_metrics_collector(state.clone()); diff --git a/operator/src/metrics.rs b/operator/src/metrics.rs index 1f90923..0dba270 100644 --- a/operator/src/metrics.rs +++ b/operator/src/metrics.rs @@ -1,18 +1,29 @@ use std::sync::Arc; -use kube::ResourceExt; +use chrono::Utc; +use kube::{Resource, ResourceExt}; use prometheus::{opts, IntCounterVec, Registry}; -use tracing::{info, instrument}; +use regex::Regex; +use serde::{Deserialize, Deserializer}; +use tracing::{error, info, instrument}; -use crate::{Error, OgmiosPort, State}; +use crate::{get_config, Error, OgmiosPort, State}; #[derive(Clone)] pub struct Metrics { + pub dcu: IntCounterVec, pub reconcile_failures: IntCounterVec, + pub metrics_failures: IntCounterVec, } impl Default for Metrics { fn default() -> Self { + let dcu = IntCounterVec::new( + opts!("dmtr_consumed_dcus", "quantity of dcu consumed",), + &["project", "service", "service_type", "tenancy"], + ) + .unwrap(); + let reconcile_failures = IntCounterVec::new( opts!( "ogmios_operator_reconciliation_errors_total", @@ -22,12 +33,27 @@ impl Default for Metrics { ) .unwrap(); - Metrics { reconcile_failures } + let metrics_failures = IntCounterVec::new( + opts!( + "ogmios_metrics_controller_errors_total", + "errors to calculation metrics", + ), + &["error"], + ) + .unwrap(); + + Metrics { + reconcile_failures, + dcu, + metrics_failures, + } } } impl Metrics { pub fn register(self, registry: &Registry) -> Result { + registry.register(Box::new(self.dcu.clone()))?; + registry.register(Box::new(self.metrics_failures.clone()))?; registry.register(Box::new(self.reconcile_failures.clone()))?; Ok(self) @@ -38,12 +64,150 @@ impl Metrics { .with_label_values(&[crd.name_any().as_ref(), e.metric_label().as_ref()]) .inc() } + + pub fn metrics_failure(&self, e: &Error) { + self.metrics_failures + .with_label_values(&[e.metric_label().as_ref()]) + .inc() + } + + pub fn count_dcu_consumed(&self, project: &str, network: &str, dcu: f64) { + let service = format!("{}-{}", OgmiosPort::kind(&()), network); + let service_type = format!("{}.{}", OgmiosPort::plural(&()), OgmiosPort::group(&())); + let tenancy = "proxy"; + + let dcu: u64 = dcu.ceil() as u64; + + self.dcu + .with_label_values(&[project, &service, &service_type, tenancy]) + .inc_by(dcu); + } } #[instrument("metrics collector run", skip_all)] -pub async fn run_metrics_collector(_state: Arc) { +pub async fn run_metrics_collector(state: Arc) { tokio::spawn(async move { info!("collecting metrics running"); + + let config = get_config(); + let client = reqwest::Client::builder().build().unwrap(); + let project_regex = Regex::new(r"prj-(.+)\..+").unwrap(); + let network_regex = Regex::new(r"([\w]+)\..+").unwrap(); + let mut last_execution = Utc::now(); + + loop { + tokio::time::sleep(config.metrics_delay).await; + + let end = Utc::now(); + let start = (end - last_execution).num_seconds(); + + last_execution = end; + + let query = format!( + "sum by (consumer, route) (increase(ogmios_proxy_ws_total_frame[{start}s] @ {}))", + end.timestamp_millis() / 1000 + ); + + let result = client + .get(format!("{}/query?query={query}", config.prometheus_url)) + .send() + .await; + + if let Err(err) = result { + error!(error = err.to_string(), "error to make prometheus request"); + state + .metrics + .metrics_failure(&Error::HttpError(err.to_string())); + continue; + } + + let response = result.unwrap(); + let status = response.status(); + if status.is_client_error() || status.is_server_error() { + error!(status = status.to_string(), "request status code fail"); + state.metrics.metrics_failure(&Error::HttpError(format!( + "Prometheus request error. Status: {} Query: {}", + status, query + ))); + continue; + } + + let response = response.json::().await.unwrap(); + for result in response.data.result { + if result.value == 0.0 + || result.metric.consumer.is_none() + || result.metric.route.is_none() + { + continue; + } + + let consumer = result.metric.consumer.unwrap(); + let project_captures = project_regex.captures(&consumer); + if project_captures.is_none() { + continue; + } + let project_captures = project_captures.unwrap(); + let project = project_captures.get(1).unwrap().as_str(); + + let route = result.metric.route.unwrap(); + let network_captures = network_regex.captures(&route); + if network_captures.is_none() { + continue; + } + let network_captures = network_captures.unwrap(); + let network = network_captures.get(1).unwrap().as_str(); + + let dcu_per_frame = config.dcu_per_frame.get(network); + if dcu_per_frame.is_none() { + let error = Error::ConfigError(format!( + "dcu_per_frame not configured to {} network", + network + )); + error!(error = error.to_string()); + state.metrics.metrics_failure(&error); + continue; + } + let dcu_per_frame = dcu_per_frame.unwrap(); + + let dcu = result.value * dcu_per_frame; + state.metrics.count_dcu_consumed(project, network, dcu); + } + } }); } +#[derive(Debug, Deserialize)] +struct PrometheusDataResultMetric { + consumer: Option, + route: Option, +} + +#[derive(Debug, Deserialize)] +struct PrometheusDataResult { + metric: PrometheusDataResultMetric, + #[serde(deserialize_with = "deserialize_value")] + value: f64, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +struct PrometheusData { + result: Vec, +} + +#[derive(Debug, Deserialize)] +struct PrometheusResponse { + data: PrometheusData, +} + +fn deserialize_value<'de, D>(deserializer: D) -> Result +where + D: Deserializer<'de>, +{ + let value: Vec = Deserialize::deserialize(deserializer)?; + Ok(value.into_iter().as_slice()[1] + .as_str() + .unwrap() + .parse::() + .unwrap()) +} From 140a6ce4da621ad0a22166ee8af40f5fef229a68 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Thu, 15 Feb 2024 16:34:49 -0300 Subject: [PATCH 19/23] docs(proxy): added readme --- proxy/README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 proxy/README.md diff --git a/proxy/README.md b/proxy/README.md new file mode 100644 index 0000000..6fcd57c --- /dev/null +++ b/proxy/README.md @@ -0,0 +1,37 @@ +# Ext Cardano Ogmios Proxy + +The proxy will manage the connection to the Ogmios, when a user makes a request, the proxy will decide which Ogmios instance will be requested using the hostname. + +An example about how the proxy will decide which instance will be requested. + +| Host | Instance | +| ---------------------------- | ---------------- | +| mainnet.ogmios-1.demeter.run | ogmios-mainnet-1 | + + +The proxy exposes metrics about HTTP requests and WebSocket frames. + +## Environment + +| Key | Value | +| --------------- | -------------- | +| PROXY_ADDR | "0.0.0.0:8100" | +| PROMETHEUS_ADDR | "0.0.0.0:5000" | +| OGMIOS_PORT | - | + + +## Commands + +Execute the proxy + +```bash +cargo run +``` + +## Metrics + +to collect metrics for Prometheus, an HTTP API will enable the route /metrics. + +``` +/metrics +``` From c9e098c146eae5d20daf987eb9ec3037492df6fc Mon Sep 17 00:00:00 2001 From: paulobressan Date: Thu, 15 Feb 2024 16:39:20 -0300 Subject: [PATCH 20/23] chore(ci/cd): adjusted controller github workflow to use docker/dockerfile.operator --- .github/workflows/controller.yml | 8 ++++---- operator/Dockerfile | 15 --------------- 2 files changed, 4 insertions(+), 19 deletions(-) delete mode 100644 operator/Dockerfile diff --git a/.github/workflows/controller.yml b/.github/workflows/controller.yml index a273964..c22ae83 100644 --- a/.github/workflows/controller.yml +++ b/.github/workflows/controller.yml @@ -7,16 +7,16 @@ on: paths: - ".github/workflows/controller.yml" - "operator/**" - + jobs: build-images: strategy: fail-fast: false matrix: include: - - context: operator - file: operator/Dockerfile - endpoint: demeter-run/ext-cardano-ogmios + - context: . + file: docker/dockerfile.operator + endpoint: demeter-run/ext-cardano-ogmios-operator continue-on-error: true runs-on: ubuntu-latest diff --git a/operator/Dockerfile b/operator/Dockerfile deleted file mode 100644 index 1091c66..0000000 --- a/operator/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM rust:1.74-slim-buster as build - -WORKDIR /app - -COPY ./Cargo.lock ./Cargo.lock -COPY ./Cargo.toml ./Cargo.toml -COPY ./src ./src - -RUN cargo build --release - -FROM rust:1.74-slim-buster - -COPY --from=build /app/target/release/controller . - -CMD ["./controller"] \ No newline at end of file From 646502349470e899eedc370503b3389735461828 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Thu, 15 Feb 2024 16:39:41 -0300 Subject: [PATCH 21/23] feat(ci/cd): added proxy build github workflow --- .github/workflows/proxy.yml | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/proxy.yml diff --git a/.github/workflows/proxy.yml b/.github/workflows/proxy.yml new file mode 100644 index 0000000..0837b8a --- /dev/null +++ b/.github/workflows/proxy.yml @@ -0,0 +1,40 @@ +name: Proxy + +on: + push: + branches: + - "main" + paths: + - ".github/workflows/proxy.yml" + - "proxy/**" + +jobs: + build-images: + strategy: + fail-fast: false + matrix: + include: + - context: . + file: docker/dockerfile.proxy + endpoint: demeter-run/ext-cardano-ogmios-proxy + + continue-on-error: true + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2.3.3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: ${{ matrix.context }} + file: ${{ matrix.file }} + platforms: linux/amd64 + push: true + tags: ghcr.io/${{ matrix.endpoint }},ghcr.io/${{ matrix.endpoint }}:${{ github.sha }} From 61a7802bd6651fd27313e4288d957ea2455fffed Mon Sep 17 00:00:00 2001 From: paulobressan Date: Mon, 19 Feb 2024 14:33:36 -0300 Subject: [PATCH 22/23] feat(proxy): updated regex to get values from hostname --- proxy/examples/manifest.yaml | 6 ++++++ proxy/examples/setup | 2 +- proxy/src/main.rs | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/proxy/examples/manifest.yaml b/proxy/examples/manifest.yaml index 7a808cf..ca17514 100644 --- a/proxy/examples/manifest.yaml +++ b/proxy/examples/manifest.yaml @@ -224,6 +224,12 @@ spec: env: - name: ADDR value: "0.0.0.0:9187" + - name: DCU_PER_FRAME + value: "preview=5,preprod=5,mainnet=5" + - name: METRICS_DELAY + value: "40" + - name: PROMETHEUS_URL + value: "http://prometheus/api/v1" --- apiVersion: v1 kind: Service diff --git a/proxy/examples/setup b/proxy/examples/setup index bc6ecbe..580f634 100755 --- a/proxy/examples/setup +++ b/proxy/examples/setup @@ -3,7 +3,7 @@ ~/go/bin/kind create cluster echo "Building operator CRD" -cargo run --bin=crdgen >> env-crd.yaml --manifest-path ../../operator/Cargo.toml +cargo run --bin=crdgen > env-crd.yaml --manifest-path ../../operator/Cargo.toml kubectl apply -f env-crd.yaml diff --git a/proxy/src/main.rs b/proxy/src/main.rs index 46b9b4b..3f6a940 100644 --- a/proxy/src/main.rs +++ b/proxy/src/main.rs @@ -65,7 +65,7 @@ impl State { pub fn try_new() -> Result> { let config = Config::new(); let metrics = Metrics::try_new(Registry::default())?; - let host_regex = Regex::new(r"(dmtr_[\w\d-]+)?\.?([\w]+).+-([\w\d]+).+")?; + let host_regex = Regex::new(r"(dmtr_[\w\d-]+)?\.?([\w]+)-([\d]).+")?; let consumers = HashMap::new(); Ok(Self { From 2ad53d970b802a67329317d2be282ee98dcb5437 Mon Sep 17 00:00:00 2001 From: paulobressan Date: Mon, 19 Feb 2024 14:39:42 -0300 Subject: [PATCH 23/23] chore(operator): added version on the URL --- operator/src/controller.rs | 2 +- operator/src/utils.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/operator/src/controller.rs b/operator/src/controller.rs index 6242a27..bbba041 100644 --- a/operator/src/controller.rs +++ b/operator/src/controller.rs @@ -57,7 +57,7 @@ impl Context { async fn reconcile(crd: Arc, ctx: Arc) -> Result { let key = build_api_key(&crd).await?; - let (hostname, hostname_key) = build_hostname(&crd.spec.network, &key); + let (hostname, hostname_key) = build_hostname(&crd.spec.network, &crd.spec.version, &key); let status = OgmiosPortStatus { endpoint_url: format!("https://{hostname}",), diff --git a/operator/src/utils.rs b/operator/src/utils.rs index 9e47d8d..9ccb9aa 100644 --- a/operator/src/utils.rs +++ b/operator/src/utils.rs @@ -27,13 +27,13 @@ pub async fn patch_resource_status( Ok(()) } -pub fn build_hostname(network: &Network, key: &str) -> (String, String) { +pub fn build_hostname(network: &Network, version: &u8, key: &str) -> (String, String) { let config = get_config(); let ingress_class = &config.ingress_class; let dns_zone = &config.dns_zone; - let hostname = format!("{network}.{ingress_class}.{dns_zone}"); - let hostname_key = format!("{key}.{network}.{ingress_class}.{dns_zone}"); + let hostname = format!("{network}-{version}.{ingress_class}.{dns_zone}"); + let hostname_key = format!("{key}.{network}-{version}.{ingress_class}.{dns_zone}"); (hostname, hostname_key) }