aboutsummaryrefslogtreecommitdiff
path: root/src/garage/main.rs
diff options
context:
space:
mode:
authorAlex <alex@adnab.me>2024-02-13 10:04:49 +0000
committerAlex <alex@adnab.me>2024-02-13 10:04:49 +0000
commit823078b4cdaf93e09de0847c5eaa75beb7b26b7f (patch)
treeb7ff8f713f9cc8a897c15f4332e1ea6b71e8d889 /src/garage/main.rs
parentea09b483fe7482f834d0ec8f8410325f6faf55a2 (diff)
parentbf283c99240787c7ffeba8ff3222283ee9fc61aa (diff)
downloadgarage-823078b4cdaf93e09de0847c5eaa75beb7b26b7f.tar.gz
garage-823078b4cdaf93e09de0847c5eaa75beb7b26b7f.zip
Merge pull request 'small fixes to config/secrets handling' (#715) from fix-secrets-695 into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/715
Diffstat (limited to 'src/garage/main.rs')
-rw-r--r--src/garage/main.rs23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/garage/main.rs b/src/garage/main.rs
index 5c92dae4..1a6a6e32 100644
--- a/src/garage/main.rs
+++ b/src/garage/main.rs
@@ -174,7 +174,9 @@ async fn main() {
}
async fn cli_command(opt: Opt) -> Result<(), Error> {
- let config = if opt.secrets.rpc_secret.is_none() || opt.rpc_host.is_none() {
+ let config = if (opt.secrets.rpc_secret.is_none() && opt.secrets.rpc_secret_file.is_none())
+ || opt.rpc_host.is_none()
+ {
Some(garage_util::config::read_config(opt.config_file.clone())
.err_context(format!("Unable to read configuration file {}. Configuration file is needed because -h or -s is not provided on the command line.", opt.config_file.to_string_lossy()))?)
} else {
@@ -182,14 +184,19 @@ async fn cli_command(opt: Opt) -> Result<(), Error> {
};
// Find and parse network RPC secret
- let net_key_hex_str = opt
- .secrets
- .rpc_secret
- .as_ref()
- .or_else(|| config.as_ref().and_then(|c| c.rpc_secret.as_ref()))
- .ok_or("No RPC secret provided")?;
+ let mut rpc_secret = config.as_ref().and_then(|c| c.rpc_secret.clone());
+ secrets::fill_secret(
+ &mut rpc_secret,
+ &config.as_ref().and_then(|c| c.rpc_secret_file.clone()),
+ &opt.secrets.rpc_secret,
+ &opt.secrets.rpc_secret_file,
+ "rpc_secret",
+ true,
+ )?;
+
+ let net_key_hex_str = rpc_secret.ok_or("No RPC secret provided")?;
let network_key = NetworkKey::from_slice(
- &hex::decode(net_key_hex_str).err_context("Invalid RPC secret key (bad hex)")?[..],
+ &hex::decode(&net_key_hex_str).err_context("Invalid RPC secret key (bad hex)")?[..],
)
.ok_or("Invalid RPC secret provided (wrong length)")?;