adding env vars, making clippy happier, cleaning up some error messages (#438)

This commit is contained in:
James Hodgkinson 2021-05-09 22:06:58 +10:00 committed by GitHub
parent e88ac01aca
commit 1229669785
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 32 additions and 31 deletions

View file

@ -60,7 +60,7 @@ impl KanidmAsyncClient {
// format doesn't work in async ?! // format doesn't work in async ?!
// let dest = format!("{}{}", self.addr, dest); // let dest = format!("{}{}", self.addr, dest);
let req_string = serde_json::to_string(&request).map_err(ClientError::JSONEncode)?; let req_string = serde_json::to_string(&request).map_err(ClientError::JsonEncode)?;
let response = self let response = self
.client .client
@ -120,7 +120,7 @@ impl KanidmAsyncClient {
response response
.json() .json()
.await .await
.map_err(|e| ClientError::JSONDecode(e, opid)) .map_err(|e| ClientError::JsonDecode(e, opid))
} }
async fn perform_post_request<R: Serialize, T: DeserializeOwned>( async fn perform_post_request<R: Serialize, T: DeserializeOwned>(
@ -133,7 +133,7 @@ impl KanidmAsyncClient {
// format doesn't work in async ?! // format doesn't work in async ?!
// let dest = format!("{}{}", self.addr, dest); // let dest = format!("{}{}", self.addr, dest);
let req_string = serde_json::to_string(&request).map_err(ClientError::JSONEncode)?; let req_string = serde_json::to_string(&request).map_err(ClientError::JsonEncode)?;
let response = self let response = self
.client .client
.post(dest.as_str()) .post(dest.as_str())
@ -172,7 +172,7 @@ impl KanidmAsyncClient {
response response
.json() .json()
.await .await
.map_err(|e| ClientError::JSONDecode(e, opid)) .map_err(|e| ClientError::JsonDecode(e, opid))
} }
async fn perform_put_request<R: Serialize, T: DeserializeOwned>( async fn perform_put_request<R: Serialize, T: DeserializeOwned>(
@ -185,7 +185,7 @@ impl KanidmAsyncClient {
// format doesn't work in async ?! // format doesn't work in async ?!
// let dest = format!("{}{}", self.addr, dest); // let dest = format!("{}{}", self.addr, dest);
let req_string = serde_json::to_string(&request).map_err(ClientError::JSONEncode)?; let req_string = serde_json::to_string(&request).map_err(ClientError::JsonEncode)?;
let response = self let response = self
.client .client
@ -228,7 +228,7 @@ impl KanidmAsyncClient {
response response
.json() .json()
.await .await
.map_err(|e| ClientError::JSONDecode(e, opid)) .map_err(|e| ClientError::JsonDecode(e, opid))
} }
async fn perform_get_request<T: DeserializeOwned>(&self, dest: &str) -> Result<T, ClientError> { async fn perform_get_request<T: DeserializeOwned>(&self, dest: &str) -> Result<T, ClientError> {
@ -270,7 +270,7 @@ impl KanidmAsyncClient {
response response
.json() .json()
.await .await
.map_err(|e| ClientError::JSONDecode(e, opid)) .map_err(|e| ClientError::JsonDecode(e, opid))
} }
async fn perform_delete_request(&self, dest: &str) -> Result<bool, ClientError> { async fn perform_delete_request(&self, dest: &str) -> Result<bool, ClientError> {
@ -313,7 +313,7 @@ impl KanidmAsyncClient {
response response
.json() .json()
.await .await
.map_err(|e| ClientError::JSONDecode(e, opid)) .map_err(|e| ClientError::JsonDecode(e, opid))
} }
async fn perform_delete_request_with_body<R: Serialize>( async fn perform_delete_request_with_body<R: Serialize>(
&self, &self,
@ -322,7 +322,7 @@ impl KanidmAsyncClient {
) -> Result<bool, ClientError> { ) -> Result<bool, ClientError> {
let dest = format!("{}{}", self.addr, dest); let dest = format!("{}{}", self.addr, dest);
let req_string = serde_json::to_string(&request).map_err(ClientError::JSONEncode)?; let req_string = serde_json::to_string(&request).map_err(ClientError::JsonEncode)?;
let response = self let response = self
.client .client
.delete(dest.as_str()) .delete(dest.as_str())
@ -361,7 +361,7 @@ impl KanidmAsyncClient {
response response
.json() .json()
.await .await
.map_err(|e| ClientError::JSONDecode(e, opid)) .map_err(|e| ClientError::JsonDecode(e, opid))
} }
pub async fn auth_step_init(&self, ident: &str) -> Result<Set<AuthMech>, ClientError> { pub async fn auth_step_init(&self, ident: &str) -> Result<Set<AuthMech>, ClientError> {
@ -644,7 +644,7 @@ impl KanidmAsyncClient {
let r: WhoamiResponse = response let r: WhoamiResponse = response
.json() .json()
.await .await
.map_err(|e| ClientError::JSONDecode(e, opid))?; .map_err(|e| ClientError::JsonDecode(e, opid))?;
Ok(Some((r.youare, r.uat))) Ok(Some((r.youare, r.uat)))
} }

View file

@ -50,8 +50,8 @@ pub enum ClientError {
AuthenticationFailed, AuthenticationFailed,
EmptyResponse, EmptyResponse,
TotpVerifyFailed(Uuid, TotpSecret), TotpVerifyFailed(Uuid, TotpSecret),
JSONDecode(reqwest::Error, String), JsonDecode(reqwest::Error, String),
JSONEncode(SerdeJsonError), JsonEncode(SerdeJsonError),
SystemError, SystemError,
} }
@ -151,6 +151,7 @@ impl KanidmClientBuilder {
self, self,
config_path: P, config_path: P,
) -> Result<Self, ()> { ) -> Result<Self, ()> {
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) => f,
@ -158,13 +159,13 @@ impl KanidmClientBuilder {
match e.kind() { match e.kind() {
ErrorKind::NotFound => { ErrorKind::NotFound => {
debug!( debug!(
"Configuration file {:#?} not found, skipping ...", "Configuration file {:#?} not found, skipping.",
&config_path &config_path
); );
} }
ErrorKind::PermissionDenied => { ErrorKind::PermissionDenied => {
warn!( warn!(
"Permission denied loading configuration file {:#?}, skipping ...", "Permission denied loading configuration file {:#?}, skipping.",
&config_path &config_path
); );
} }

View file

@ -79,7 +79,7 @@ pub enum OperationError {
InvalidState, InvalidState,
InvalidEntryState, InvalidEntryState,
InvalidUuid, InvalidUuid,
InvalidReplCID, InvalidReplChangeId,
InvalidAcpState(String), InvalidAcpState(String),
InvalidSchemaState(String), InvalidSchemaState(String),
InvalidAccountState(String), InvalidAccountState(String),

View file

@ -6,14 +6,14 @@ impl CommonOpt {
pub fn to_unauth_client(&self) -> KanidmClient { pub fn to_unauth_client(&self) -> KanidmClient {
let config_path: String = shellexpand::tilde("~/.config/kanidm").into_owned(); let config_path: String = shellexpand::tilde("~/.config/kanidm").into_owned();
debug!("Attempting to use config {}", "/etc/kanidm/config");
let client_builder = match KanidmClientBuilder::new() let client_builder = match KanidmClientBuilder::new()
.read_options_from_optional_config("/etc/kanidm/config") .read_options_from_optional_config("/etc/kanidm/config")
.and_then(|cb| { .and_then(|cb| cb.read_options_from_optional_config(&config_path))
debug!("Attempting to use config {}", config_path); {
cb.read_options_from_optional_config(config_path) Ok(c) => {
}) { debug!("Successfully read configuration from {}", &config_path);
Ok(c) => c, c
}
Err(e) => { Err(e) => {
error!("Failed to parse config (if present) -- {:?}", e); error!("Failed to parse config (if present) -- {:?}", e);
std::process::exit(1); std::process::exit(1);

View file

@ -8,13 +8,13 @@ pub struct Named {
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
pub struct CommonOpt { pub struct CommonOpt {
#[structopt(short = "d", long = "debug")] #[structopt(short = "d", long = "debug", env = "KANIDM_DEBUG")]
pub debug: bool, pub debug: bool,
#[structopt(short = "H", long = "url")] #[structopt(short = "H", long = "url", env = "KANIDM_URL")]
pub addr: Option<String>, pub addr: Option<String>,
#[structopt(short = "D", long = "name")] #[structopt(short = "D", long = "name", env = "KANIDM_NAME")]
pub username: Option<String>, pub username: Option<String>,
#[structopt(parse(from_os_str), short = "C", long = "ca")] #[structopt(parse(from_os_str), short = "C", long = "ca", env = "KANIDM_CA_PATH")]
pub ca_path: Option<PathBuf>, pub ca_path: Option<PathBuf>,
} }

View file

@ -29,7 +29,7 @@ impl FromStr for LogLevel {
"perfbasic" => Ok(LogLevel::PerfBasic), "perfbasic" => Ok(LogLevel::PerfBasic),
"perffull" => Ok(LogLevel::PerfFull), "perffull" => Ok(LogLevel::PerfFull),
"fulltrace" => Ok(LogLevel::FullTrace), "fulltrace" => Ok(LogLevel::FullTrace),
_ => Err("Could not parse loglevel"), _ => Err("Could not parse loglevel, should be one of (default|quiet|filter|verbose|perfbasic|perffull|fulltrace)"),
} }
} }
} }

View file

@ -45,7 +45,7 @@ impl Cid {
.expect("Invalid compiled s_uuid"), .expect("Invalid compiled s_uuid"),
ts: r, ts: r,
}) })
.ok_or(OperationError::InvalidReplCID) .ok_or(OperationError::InvalidReplChangeId)
} }
} }

View file

@ -1,9 +1,9 @@
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
struct CommonOpt { struct CommonOpt {
#[structopt(short = "d", long = "debug")] #[structopt(short = "d", long = "debug", env = "KANIDM_DEBUG")]
/// Logging level. quiet, default, filter, verbose, perffull /// Logging level. quiet, default, filter, verbose, perffull
debug: Option<LogLevel>, debug: Option<LogLevel>,
#[structopt(parse(from_os_str), short = "c", long = "config")] #[structopt(parse(from_os_str), short = "c", long = "config", env = "KANIDM_CONFIG")]
/// Path to the server's configuration file. If it does not exist, it will be created. /// Path to the server's configuration file. If it does not exist, it will be created.
config_path: PathBuf, config_path: PathBuf,
} }
@ -20,7 +20,7 @@ struct BackupOpt {
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
struct RestoreOpt { struct RestoreOpt {
#[structopt(parse(from_os_str))] #[structopt(parse(from_os_str))]
/// Restore from this path. Should be created with "backupu". /// Restore from this path. Should be created with "backup".
path: PathBuf, path: PathBuf,
#[structopt(flatten)] #[structopt(flatten)]
commonopts: CommonOpt, commonopts: CommonOpt,