Minor upgrade fixes (#2722)

This commit is contained in:
Firstyear 2024-04-24 17:21:45 +10:00 committed by GitHub
parent acc800f00e
commit 58cfc8bdf9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 38 additions and 7 deletions

View file

@ -186,7 +186,11 @@ impl ServerConfig {
} else { } else {
eprintln!("📜 No config file found at {:?}", config_path.as_ref()); eprintln!("📜 No config file found at {:?}", config_path.as_ref());
} }
} } else {
eprintln!(
"WARNING: No configuration path was provided, relying on environment variables."
);
};
// build from the environment variables // build from the environment variables
let res = config.try_from_env().map_err(|e| { let res = config.try_from_env().map_err(|e| {

View file

@ -24,6 +24,7 @@ use sketching::LogLevel;
use std::os::unix::fs::MetadataExt; use std::os::unix::fs::MetadataExt;
use std::path::PathBuf; use std::path::PathBuf;
use std::process::ExitCode; use std::process::ExitCode;
use std::str::FromStr;
use clap::{Args, Parser, Subcommand}; use clap::{Args, Parser, Subcommand};
use futures::{SinkExt, StreamExt}; use futures::{SinkExt, StreamExt};
@ -319,7 +320,26 @@ async fn kanidm_main() -> ExitCode {
let mut config_error: Vec<String> = Vec::new(); let mut config_error: Vec<String> = Vec::new();
let mut config = Configuration::new(); let mut config = Configuration::new();
let sconfig = match ServerConfig::new(opt.config_path()) { let Ok(default_config_path) = PathBuf::from_str(env!("KANIDM_DEFAULT_CONFIG_PATH")) else {
eprintln!("CRITICAL: Kanidmd was not built correctly and is missing a valid KANIDM_DEFAULT_CONFIG_PATH value");
return ExitCode::FAILURE;
};
let maybe_config_path = if let Some(p) = opt.config_path() {
Some(p)
} else {
// The user didn't ask for a file, lets check if the default path exists?
if default_config_path.exists() {
// It does, lets use it.
Some(default_config_path)
} else {
// No default config, and no config specified, lets assume the user
// has selected environment variables.
None
}
};
let sconfig = match ServerConfig::new(maybe_config_path) {
Ok(c) => Some(c), Ok(c) => Some(c),
Err(e) => { Err(e) => {
config_error.push(format!("Config Parse failure {:?}", e)); config_error.push(format!("Config Parse failure {:?}", e));

View file

@ -100,16 +100,20 @@ impl TokenInstance {
#[derive(Debug, Serialize, Clone, Deserialize, Default)] #[derive(Debug, Serialize, Clone, Deserialize, Default)]
pub struct TokenStore { pub struct TokenStore {
instances: BTreeMap<Option<String>, TokenInstance>, instances: BTreeMap<String, TokenInstance>,
} }
impl TokenStore { impl TokenStore {
pub fn instances(&self, name: &Option<String>) -> Option<&TokenInstance> { pub fn instances(&self, name: &Option<String>) -> Option<&TokenInstance> {
self.instances.get(name) let n_lookup = name.clone().unwrap_or_else(|| "".to_string());
self.instances.get(&n_lookup)
} }
pub fn instances_mut(&mut self, name: &Option<String>) -> Option<&mut TokenInstance> { pub fn instances_mut(&mut self, name: &Option<String>) -> Option<&mut TokenInstance> {
self.instances.get_mut(name) let n_lookup = name.clone().unwrap_or_else(|| "".to_string());
self.instances.get_mut(&n_lookup)
} }
} }
@ -409,7 +413,8 @@ async fn process_auth_state(
let mut tokens = read_tokens(&client.get_token_cache_path()).unwrap_or_default(); let mut tokens = read_tokens(&client.get_token_cache_path()).unwrap_or_default();
// Select our token instance. Create it if empty. // Select our token instance. Create it if empty.
let token_instance = tokens.instances.entry(instance_name.clone()).or_default(); let n_lookup = instance_name.clone().unwrap_or_else(|| "".to_string());
let token_instance = tokens.instances.entry(n_lookup).or_default();
// Add our new one // Add our new one
let (spn, tonk) = match client.get_token().await { let (spn, tonk) = match client.get_token().await {
@ -480,6 +485,7 @@ async fn process_auth_state(
// write them out. // write them out.
if write_tokens(&tokens, &client.get_token_cache_path()).is_err() { if write_tokens(&tokens, &client.get_token_cache_path()).is_err() {
trace!(?tokens);
error!("Error persisting authentication token store"); error!("Error persisting authentication token store");
std::process::exit(1); std::process::exit(1);
}; };
@ -669,7 +675,8 @@ impl LogoutOpt {
std::process::exit(1); std::process::exit(1);
}); });
let Some(token_instance) = tokens.instances.get_mut(instance_name) else { let n_lookup = instance_name.clone().unwrap_or_else(|| "".to_string());
let Some(token_instance) = tokens.instances.get_mut(&n_lookup) else {
println!("No sessions for {}", spn); println!("No sessions for {}", spn);
return; return;
}; };