444 - client's config URI missing and more file open handling (#446)

This commit is contained in:
James Hodgkinson 2021-05-21 15:19:36 +10:00 committed by GitHub
parent 78f780910e
commit 1f98018513
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 8 deletions

View file

@ -158,7 +158,10 @@ impl KanidmClientBuilder {
debug!("Attempting to load configuration from {:#?}", &config_path); debug!("Attempting to load configuration from {:#?}", &config_path);
// If the file does not exist, we skip this function. // If the file does not exist, we skip this function.
let mut f = match File::open(&config_path) { let mut f = match File::open(&config_path) {
Ok(f) => f, Ok(f) => {
debug!("Successfully opened configuration file {:#?}", &config_path);
f
}
Err(e) => { Err(e) => {
match e.kind() { match e.kind() {
ErrorKind::NotFound => { ErrorKind::NotFound => {
@ -292,7 +295,7 @@ impl KanidmClientBuilder {
let address = match &self.address { let address = match &self.address {
Some(a) => a.clone(), Some(a) => a.clone(),
None => { None => {
eprintln!("uri (-H) missing, can not proceed"); eprintln!("Configuration option 'uri' missing, cannot continue client startup.");
unimplemented!(); unimplemented!();
} }
}; };

View file

@ -5,7 +5,7 @@ use crate::constants::{
}; };
use serde_derive::Deserialize; use serde_derive::Deserialize;
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::{ErrorKind, Read};
use std::path::Path; use std::path::Path;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
@ -81,13 +81,33 @@ impl KanidmUnixdConfig {
self, self,
config_path: P, config_path: P,
) -> Result<Self, ()> { ) -> Result<Self, ()> {
debug!("Attempting to load configuration from {:#?}", &config_path);
let mut f = match File::open(&config_path) { let mut f = match File::open(&config_path) {
Ok(f) => f, Ok(f) => {
debug!("Successfully opened configuration file {:#?}", &config_path);
f
}
Err(e) => { Err(e) => {
debug!( match e.kind() {
"Unable to open config file {:#?} [{:?}], skipping ...", ErrorKind::NotFound => {
&config_path, e debug!(
); "Configuration file {:#?} not found, skipping.",
&config_path
);
}
ErrorKind::PermissionDenied => {
warn!(
"Permission denied loading configuration file {:#?}, skipping.",
&config_path
);
}
_ => {
debug!(
"Unable to open config file {:#?} [{:?}], skipping ...",
&config_path, e
);
}
};
return Ok(self); return Ok(self);
} }
}; };