aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Cargo.toml3
-rw-r--r--src/util/config.rs25
-rw-r--r--src/util/formater.rs32
-rw-r--r--src/util/forwarded_headers.rs2
-rw-r--r--src/util/lib.rs1
-rw-r--r--src/util/migrate.rs2
-rw-r--r--src/util/version.rs12
7 files changed, 29 insertions, 48 deletions
diff --git a/src/util/Cargo.toml b/src/util/Cargo.toml
index 2e6231f6..f72051b9 100644
--- a/src/util/Cargo.toml
+++ b/src/util/Cargo.toml
@@ -14,7 +14,7 @@ path = "lib.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-garage_db = { version = "0.8.2", path = "../db" }
+garage_db.workspace = true
arc-swap = "1.0"
async-trait = "0.1"
@@ -22,7 +22,6 @@ blake2 = "0.10"
bytes = "1.0"
digest = "0.10"
err-derive = "0.3"
-git-version = "0.3.4"
hexdump = "0.1"
xxhash-rust = { version = "0.8", default-features = false, features = ["xxh3"] }
hex = "0.4"
diff --git a/src/util/config.rs b/src/util/config.rs
index 2176353e..1da95b2f 100644
--- a/src/util/config.rs
+++ b/src/util/config.rs
@@ -135,8 +135,19 @@ pub struct AdminConfig {
pub trace_sink: Option<String>,
}
+#[derive(Deserialize, Debug, Clone, Default)]
+#[serde(rename_all = "lowercase")]
+pub enum ConsulDiscoveryAPI {
+ #[default]
+ Catalog,
+ Agent,
+}
+
#[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,
/// Consul service name to use
@@ -147,9 +158,17 @@ pub struct ConsulDiscoveryConfig {
pub client_cert: Option<String>,
/// Client TLS key to use when connecting to Consul
pub client_key: Option<String>,
+ /// /// Token to use for connecting to consul
+ pub token: Option<String>,
/// Skip TLS hostname verification
#[serde(default)]
pub tls_skip_verify: bool,
+ /// Additional tags to add to the service
+ #[serde(default)]
+ pub tags: Vec<String>,
+ /// Additional service metadata to add
+ #[serde(default)]
+ pub meta: Option<std::collections::HashMap<String, String>>,
}
#[derive(Deserialize, Debug, Clone)]
@@ -223,7 +242,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());
}
@@ -344,7 +363,7 @@ mod tests {
replication_mode = "3"
rpc_bind_addr = "[::]:3901"
rpc_secret_file = "{}"
-
+
[s3_api]
s3_region = "garage"
api_bind_addr = "[::]:3900"
@@ -388,7 +407,7 @@ mod tests {
rpc_bind_addr = "[::]:3901"
rpc_secret= "dummy"
rpc_secret_file = "dummy"
-
+
[s3_api]
s3_region = "garage"
api_bind_addr = "[::]:3900"
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>) -> String {
- let data = data
- .iter()
- .map(|s| s.split('\t').collect::<Vec<_>>())
- .collect::<Vec<_>>();
-
- 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<String>) {
- print!("{}", format_table_to_string(data));
-}
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<HeaderValue>) -> 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())
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;
diff --git a/src/util/migrate.rs b/src/util/migrate.rs
index 1229fd9c..b9cce08a 100644
--- a/src/util/migrate.rs
+++ b/src/util/migrate.rs
@@ -27,7 +27,7 @@ pub trait Migrate: Serialize + for<'de> Deserialize<'de> + 'static {
Self::Previous::decode(bytes).map(Self::migrate)
}
- /// Encode this type with optionnal version marker
+ /// Encode this type with optional version marker
fn encode(&self) -> Result<Vec<u8>, rmp_serde::encode::Error> {
let mut wr = Vec::with_capacity(128);
wr.extend_from_slice(Self::VERSION_MARKER);
diff --git a/src/util/version.rs b/src/util/version.rs
index 2b2ea271..19907ed1 100644
--- a/src/util/version.rs
+++ b/src/util/version.rs
@@ -1,18 +1,14 @@
use std::sync::Arc;
-use arc_swap::{ArcSwap, ArcSwapOption};
+use arc_swap::ArcSwapOption;
lazy_static::lazy_static! {
- static ref VERSION: ArcSwap<&'static str> = ArcSwap::new(Arc::new(git_version::git_version!(
- prefix = "git:",
- cargo_prefix = "cargo:",
- fallback = "unknown"
- )));
+ static ref VERSION: ArcSwapOption<&'static str> = ArcSwapOption::new(None);
static ref FEATURES: ArcSwapOption<&'static [&'static str]> = ArcSwapOption::new(None);
}
pub fn garage_version() -> &'static str {
- &VERSION.load()
+ VERSION.load().as_ref().unwrap()
}
pub fn garage_features() -> Option<&'static [&'static str]> {
@@ -20,7 +16,7 @@ pub fn garage_features() -> Option<&'static [&'static str]> {
}
pub fn init_version(version: &'static str) {
- VERSION.store(Arc::new(version));
+ VERSION.store(Some(Arc::new(version)));
}
pub fn init_features(features: &'static [&'static str]) {