diff --git a/Cargo.lock b/Cargo.lock index 2316328a6..bdaec117f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -604,6 +604,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[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 = "core-foundation" version = "0.9.4" @@ -924,7 +933,7 @@ version = "0.99.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ - "convert_case", + "convert_case 0.4.0", "proc-macro2", "quote", "rustc_version", @@ -2876,6 +2885,7 @@ dependencies = [ "clap", "clap_complete", "comfy-table", + "convert_case 0.6.0", "dav-server", "dialoguer", "dircmp", @@ -4046,6 +4056,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + [[package]] name = "unicode-width" version = "0.1.11" diff --git a/Cargo.toml b/Cargo.toml index a5dfe243c..3321e5756 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,6 +77,7 @@ simplelog = "0.12" bytesize = "1" clap = { version = "4", features = ["derive", "env", "wrap_help"] } clap_complete = "4" +convert_case = "0.6.0" dialoguer = "0.11.0" directories = "5" gethostname = "0.4" diff --git a/config/full.toml b/config/full.toml index 7b5def19f..cc84108e3 100644 --- a/config/full.toml +++ b/config/full.toml @@ -36,7 +36,9 @@ warm-up = false warm-up-command = "warmup.sh %id" # Default: not set warm-up-wait = "10min" # Default: not set -# Additional repository options - depending on backend. These can be only set in the config file. +# Additional repository options - depending on backend. These can be only set in the config file or using env variables. +# For env variables use upper snake case and prefix with "RUSTIC_REPO_OPT_", e.g. `use-passwort = "true"` becomes +# `RUSTIC_REPO_OPT_USE_PASSWORT=true` [repository.options] post-create-command = "par2create -qq -n1 -r5 %file" # Only local backend; Default: not set post-delete-command = "sh -c \"rm -f %file*.par2\"" # Only local backend; Default: not set @@ -48,11 +50,15 @@ rest-url = "http://localhost:8000" # Only rclone; Default: determine REST URL fr # Note that opendal backends use several service-dependent options which may be specified here, see # https://opendal.apache.org/docs/rust/opendal/services/index.html -# Additional repository options for the hot part - depending on backend. These can be only set in the config file. +# Additional repository options for the hot part - depending on backend. These can be only set in the config file or +# using env variables. +# For env variables use upper snake case and prefix with "RUSTIC_REPO_OPTHOT_" [repository.options-hot] # see [repository.options] -# Additional repository options for the cold part - depending on backend. These can be only set in the config file. +# Additional repository options for the cold part - depending on backend. These can be only set in the config file or +# using env variables. +# For env variables use upper snake case and prefix with "RUSTIC_REPO_OPTCOLD_" [repository.options-cold] # see [repository.options] diff --git a/config/services/b2.toml b/config/services/b2.toml index 99026f544..080b954b0 100644 --- a/config/services/b2.toml +++ b/config/services/b2.toml @@ -9,7 +9,7 @@ password = "" [repository.options] # Here, we give the required b2 options, see https://opendal.apache.org/docs/rust/opendal/services/struct.B2.html application_key_id = "my_id" # B2 application key ID -application_key = "my_key" # B2 application key secret +application_key = "my_key" # B2 application key secret. Can be also set using OPENDAL_APPLICATION_KEY bucket = "bucket_name" # B2 bucket name bucket_id = "bucket_id" # B2 bucket ID -# root = "/" # Set a repository root directory if not using the root directory of the bucket +# root = "/" # Set a repository root directory if not using the root directory of the bucket diff --git a/src/commands.rs b/src/commands.rs index bb4653c60..33d1db3fe 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -52,6 +52,7 @@ use clap::builder::{ styling::{AnsiColor, Effects}, Styles, }; +use convert_case::{Case, Casing}; use dialoguer::Password; use human_panic::setup_panic; use log::{log, Level}; @@ -185,6 +186,23 @@ impl Configurable for EntryPoint { // That's why it says `_config`, because it's not read at all and therefore not needed. let mut config = self.config.clone(); + // collect "RUSTIC_REPO_OPT*" and "OPENDAL_*" env variables + for (var, value) in std::env::vars() { + if let Some(var) = var.strip_prefix("RUSTIC_REPO_OPT_") { + let var = var.from_case(Case::UpperSnake).to_case(Case::Kebab); + _ = config.repository.be.options.insert(var, value); + } else if let Some(var) = var.strip_prefix("OPENDAL_") { + let var = var.from_case(Case::UpperSnake).to_case(Case::Snake); + _ = config.repository.be.options.insert(var, value); + } else if let Some(var) = var.strip_prefix("RUSTIC_REPO_OPTHOT_") { + let var = var.from_case(Case::UpperSnake).to_case(Case::Kebab); + _ = config.repository.be.options_hot.insert(var, value); + } else if let Some(var) = var.strip_prefix("RUSTIC_REPO_OPTCOLD_") { + let var = var.from_case(Case::UpperSnake).to_case(Case::Kebab); + _ = config.repository.be.options_cold.insert(var, value); + } + } + // collect logs during merging as we start the logger *after* merging let mut merge_logs = Vec::new();