From c783194e8b8c3263fad579a85ea07d62e63b16be Mon Sep 17 00:00:00 2001 From: Jonathan Davies Date: Tue, 9 May 2023 20:49:34 +0100 Subject: *: apply clippy recommendations. --- src/util/config.rs | 2 +- src/util/forwarded_headers.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/util') diff --git a/src/util/config.rs b/src/util/config.rs index 2176353e..95835bbb 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -223,7 +223,7 @@ fn secret_from_file( #[cfg(unix)] if std::env::var("GARAGE_ALLOW_WORLD_READABLE_SECRETS").as_deref() != Ok("true") { use std::os::unix::fs::MetadataExt; - let metadata = std::fs::metadata(&file_path)?; + let metadata = std::fs::metadata(file_path)?; if metadata.mode() & 0o077 != 0 { return Err(format!("File {} is world-readable! (mode: 0{:o}, expected 0600)\nRefusing to start until this is fixed, or environment variable GARAGE_ALLOW_WORLD_READABLE_SECRETS is set to true.", file_path, metadata.mode()).into()); } diff --git a/src/util/forwarded_headers.rs b/src/util/forwarded_headers.rs index 6ae275aa..12f76434 100644 --- a/src/util/forwarded_headers.rs +++ b/src/util/forwarded_headers.rs @@ -13,7 +13,7 @@ pub fn handle_forwarded_for_headers(headers: &HeaderMap) -> Result< .to_str() .ok_or_message("Error parsing X-Forwarded-For header")?; - let client_ip = IpAddr::from_str(&forwarded_for_ip_str) + let client_ip = IpAddr::from_str(forwarded_for_ip_str) .ok_or_message("Valid IP address not found in X-Forwarded-For header")?; Ok(client_ip.to_string()) -- cgit v1.2.3 From a1cec2cd60d64208caa2cbd11d8e6f885e80f630 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 17 May 2023 13:01:37 +0200 Subject: Split format_table into separate crate and reduce k2v-client dependencies --- src/util/formater.rs | 32 -------------------------------- src/util/lib.rs | 1 - 2 files changed, 33 deletions(-) delete mode 100644 src/util/formater.rs (limited to 'src/util') diff --git a/src/util/formater.rs b/src/util/formater.rs deleted file mode 100644 index 2ea53ebb..00000000 --- a/src/util/formater.rs +++ /dev/null @@ -1,32 +0,0 @@ -pub fn format_table_to_string(data: Vec) -> String { - let data = data - .iter() - .map(|s| s.split('\t').collect::>()) - .collect::>(); - - let columns = data.iter().map(|row| row.len()).fold(0, std::cmp::max); - let mut column_size = vec![0; columns]; - - let mut out = String::new(); - - for row in data.iter() { - for (i, col) in row.iter().enumerate() { - column_size[i] = std::cmp::max(column_size[i], col.chars().count()); - } - } - - for row in data.iter() { - for (col, col_len) in row[..row.len() - 1].iter().zip(column_size.iter()) { - out.push_str(col); - (0..col_len - col.chars().count() + 2).for_each(|_| out.push(' ')); - } - out.push_str(row[row.len() - 1]); - out.push('\n'); - } - - out -} - -pub fn format_table(data: Vec) { - print!("{}", format_table_to_string(data)); -} diff --git a/src/util/lib.rs b/src/util/lib.rs index c9110fb2..15f0f829 100644 --- a/src/util/lib.rs +++ b/src/util/lib.rs @@ -10,7 +10,6 @@ pub mod crdt; pub mod data; pub mod encode; pub mod error; -pub mod formater; pub mod forwarded_headers; pub mod metrics; pub mod migrate; -- cgit v1.2.3 From 02ba9016ab6eca5bb4964549de002573d5a3a07a Mon Sep 17 00:00:00 2001 From: Roberto Hidalgo Date: Fri, 5 May 2023 16:18:24 -0600 Subject: register consul services against local agent instead of catalog api --- src/util/config.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/util') diff --git a/src/util/config.rs b/src/util/config.rs index 95835bbb..4b32f8ba 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -56,6 +56,9 @@ pub struct Config { /// Configuration for automatic node discovery through Consul #[serde(default)] pub consul_discovery: Option, + /// Configuration for automatic node discovery through Consul + #[serde(default)] + pub consul_service_discovery: Option, /// Configuration for automatic node discovery through Kubernetes #[serde(default)] pub kubernetes_discovery: Option, @@ -152,6 +155,24 @@ pub struct ConsulDiscoveryConfig { pub tls_skip_verify: bool, } +#[derive(Deserialize, Debug, Clone)] +pub struct ConsulServiceConfig { + /// Consul http or https address to connect to to discover more peers + pub consul_http_addr: String, + /// Token to use for connecting to consul + pub consul_http_token: Option, + /// Consul service name to use + pub service_name: String, + /// CA TLS certificate to use when connecting to Consul + pub ca_cert: Option, + // Additional tags to add to the service + #[serde(default)] + pub tags: Vec, + /// Skip TLS hostname verification + #[serde(default)] + pub tls_skip_verify: bool, +} + #[derive(Deserialize, Debug, Clone)] pub struct KubernetesDiscoveryConfig { /// Kubernetes namespace the service discovery resources are be created in @@ -344,7 +365,7 @@ mod tests { replication_mode = "3" rpc_bind_addr = "[::]:3901" rpc_secret_file = "{}" - + [s3_api] s3_region = "garage" api_bind_addr = "[::]:3900" @@ -388,7 +409,7 @@ mod tests { rpc_bind_addr = "[::]:3901" rpc_secret= "dummy" rpc_secret_file = "dummy" - + [s3_api] s3_region = "garage" api_bind_addr = "[::]:3900" -- cgit v1.2.3 From bd6485565e78c0bbb9ee830c4e5b114c6248dc97 Mon Sep 17 00:00:00 2001 From: Roberto Hidalgo Date: Mon, 8 May 2023 19:29:47 -0600 Subject: allow additional ServiceMeta, docs --- src/util/config.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/util') diff --git a/src/util/config.rs b/src/util/config.rs index 4b32f8ba..84a8e34f 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -168,6 +168,9 @@ pub struct ConsulServiceConfig { // Additional tags to add to the service #[serde(default)] pub tags: Vec, + // Additional service metadata to add + #[serde(default)] + pub meta: Option>, /// Skip TLS hostname verification #[serde(default)] pub tls_skip_verify: bool, -- cgit v1.2.3 From fd7dbea5b86ed8757e76e1114e2154538c5a3c16 Mon Sep 17 00:00:00 2001 From: Roberto Hidalgo Date: Wed, 10 May 2023 13:20:39 -0600 Subject: follow feedback, fold into existing feature --- src/util/config.rs | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'src/util') diff --git a/src/util/config.rs b/src/util/config.rs index 84a8e34f..632d22ef 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -56,9 +56,6 @@ pub struct Config { /// Configuration for automatic node discovery through Consul #[serde(default)] pub consul_discovery: Option, - /// Configuration for automatic node discovery through Consul - #[serde(default)] - pub consul_service_discovery: Option, /// Configuration for automatic node discovery through Kubernetes #[serde(default)] pub kubernetes_discovery: Option, @@ -138,8 +135,23 @@ pub struct AdminConfig { pub trace_sink: Option, } +#[derive(Deserialize, Debug, Clone)] +pub enum ConsulDiscoveryMode { + #[serde(rename_all = "lowercase")] + Node, + Service, +} +impl ConsulDiscoveryMode { + fn default() -> Self { + ConsulDiscoveryMode::Node + } +} + #[derive(Deserialize, Debug, Clone)] pub struct ConsulDiscoveryConfig { + /// Mode of consul operation: either `node` (the default) or `service` + #[serde(default = "ConsulDiscoveryMode::default")] + pub mode: ConsulDiscoveryMode, /// Consul http or https address to connect to to discover more peers pub consul_http_addr: String, /// Consul service name to use @@ -150,30 +162,17 @@ pub struct ConsulDiscoveryConfig { pub client_cert: Option, /// Client TLS key to use when connecting to Consul pub client_key: Option, + /// /// Token to use for connecting to consul + pub consul_http_token: Option, /// Skip TLS hostname verification #[serde(default)] pub tls_skip_verify: bool, -} - -#[derive(Deserialize, Debug, Clone)] -pub struct ConsulServiceConfig { - /// Consul http or https address to connect to to discover more peers - pub consul_http_addr: String, - /// Token to use for connecting to consul - pub consul_http_token: Option, - /// Consul service name to use - pub service_name: String, - /// CA TLS certificate to use when connecting to Consul - pub ca_cert: Option, - // Additional tags to add to the service + /// Additional tags to add to the service #[serde(default)] pub tags: Vec, - // Additional service metadata to add + /// Additional service metadata to add #[serde(default)] pub meta: Option>, - /// Skip TLS hostname verification - #[serde(default)] - pub tls_skip_verify: bool, } #[derive(Deserialize, Debug, Clone)] -- cgit v1.2.3 From 6b69404f1a53b927b4ce3cabdbb41f58e832a963 Mon Sep 17 00:00:00 2001 From: Roberto Hidalgo Date: Wed, 10 May 2023 20:11:14 -0600 Subject: rename mode to consul_http_api --- src/util/config.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/util') diff --git a/src/util/config.rs b/src/util/config.rs index 632d22ef..8b723e47 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -136,22 +136,22 @@ pub struct AdminConfig { } #[derive(Deserialize, Debug, Clone)] -pub enum ConsulDiscoveryMode { +pub enum ConsulDiscoveryAPI { #[serde(rename_all = "lowercase")] - Node, - Service, + Catalog, + Agent, } -impl ConsulDiscoveryMode { +impl ConsulDiscoveryAPI { fn default() -> Self { - ConsulDiscoveryMode::Node + ConsulDiscoveryAPI::Catalog } } #[derive(Deserialize, Debug, Clone)] pub struct ConsulDiscoveryConfig { - /// Mode of consul operation: either `node` (the default) or `service` - #[serde(default = "ConsulDiscoveryMode::default")] - pub mode: ConsulDiscoveryMode, + /// The consul api to use when registering: either `catalog` (the default) or `agent` + #[serde(default = "ConsulDiscoveryAPI::default")] + pub consul_http_api: ConsulDiscoveryAPI, /// Consul http or https address to connect to to discover more peers pub consul_http_addr: String, /// Consul service name to use -- cgit v1.2.3 From b7705041268e49f2a5ba9a719372048f85c3de83 Mon Sep 17 00:00:00 2001 From: Roberto Hidalgo Date: Mon, 15 May 2023 16:15:56 -0600 Subject: simplify code according to feedback --- src/util/config.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src/util') diff --git a/src/util/config.rs b/src/util/config.rs index 8b723e47..647c2659 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -135,23 +135,18 @@ pub struct AdminConfig { pub trace_sink: Option, } -#[derive(Deserialize, Debug, Clone)] +#[derive(Deserialize, Debug, Clone, Default)] +#[serde(rename_all = "lowercase")] pub enum ConsulDiscoveryAPI { - #[serde(rename_all = "lowercase")] + #[default] Catalog, Agent, } -impl ConsulDiscoveryAPI { - fn default() -> Self { - ConsulDiscoveryAPI::Catalog - } -} #[derive(Deserialize, Debug, Clone)] pub struct ConsulDiscoveryConfig { /// The consul api to use when registering: either `catalog` (the default) or `agent` - #[serde(default = "ConsulDiscoveryAPI::default")] - pub consul_http_api: ConsulDiscoveryAPI, + pub api: ConsulDiscoveryAPI, /// Consul http or https address to connect to to discover more peers pub consul_http_addr: String, /// Consul service name to use @@ -163,7 +158,7 @@ pub struct ConsulDiscoveryConfig { /// Client TLS key to use when connecting to Consul pub client_key: Option, /// /// Token to use for connecting to consul - pub consul_http_token: Option, + pub token: Option, /// Skip TLS hostname verification #[serde(default)] pub tls_skip_verify: bool, -- cgit v1.2.3 From ef8a7add0865b593836736af64b8577c5375d531 Mon Sep 17 00:00:00 2001 From: Roberto Hidalgo Date: Sat, 20 May 2023 21:25:57 -0600 Subject: set default for [consul-services] api --- src/util/config.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/util') diff --git a/src/util/config.rs b/src/util/config.rs index 647c2659..1da95b2f 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -146,6 +146,7 @@ pub enum ConsulDiscoveryAPI { #[derive(Deserialize, Debug, Clone)] pub struct ConsulDiscoveryConfig { /// The consul api to use when registering: either `catalog` (the default) or `agent` + #[serde(default)] pub api: ConsulDiscoveryAPI, /// Consul http or https address to connect to to discover more peers pub consul_http_addr: String, -- cgit v1.2.3