Skip to content

Commit

Permalink
Changes to how authentication failure is handled.
Browse files Browse the repository at this point in the history
When authentication fails, it used to completely throw out both username
and password and force a re-authentication.  It will now retain
username.
  • Loading branch information
compenguy committed Apr 5, 2020
1 parent a799539 commit 9315ae0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
22 changes: 4 additions & 18 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};

use anyhow::{Context, Result};
use clap::crate_name;
use log::{debug, trace, warn};
use log::{debug, trace};
use serde_derive::{Deserialize, Serialize};

use crate::errors::Error;
Expand Down Expand Up @@ -69,8 +69,6 @@ pub(crate) enum Credentials {
ConfigFile(String, String),
#[serde(with = "serde_session")]
Session(Option<String>, Option<String>),
#[serde(skip)]
Invalid(String),
}

impl Credentials {
Expand All @@ -91,8 +89,6 @@ impl Credentials {
None
}
Credentials::Session(o_u, _) => o_u.clone(),
Credentials::Invalid(u) if u.is_empty() => None,
Credentials::Invalid(u) => Some(u.clone()),
}
}

Expand All @@ -110,7 +106,6 @@ impl Credentials {
Ok(None)
}
Credentials::Session(_, o_p) => Ok(o_p.clone()),
Credentials::Invalid(_) => Ok(None),
}
}

Expand All @@ -132,9 +127,6 @@ impl Credentials {
Some(username)
};
}
Credentials::Invalid(ref mut u) => {
*u = username;
}
}
dup
}
Expand All @@ -160,9 +152,6 @@ impl Credentials {
Some(password.to_string())
};
}
Credentials::Invalid(_) => {
warn!("Ignoring request to update password on Invalid type credentials.");
}
}
Ok(dup)
}
Expand Down Expand Up @@ -209,11 +198,9 @@ impl Credentials {
#[must_use = "Credentials may not be converted between variants in-place. Calling \"as_<type>\" creates a copy as another variant."]
pub(crate) fn as_invalid(&self) -> Credentials {
match self {
Self::Invalid(_) => self.clone(),
c => {
let username = c.username().unwrap_or_default();
Self::Invalid(username)
}
Self::Session(u, _) => Self::Session(u.clone().map(String::from), None),
Self::ConfigFile(u, _) => Self::ConfigFile(u.to_string(), String::new()),
Self::Keyring(_) => self.clone(),
}
}

Expand Down Expand Up @@ -255,7 +242,6 @@ impl std::fmt::Debug for Credentials {
Self::Session(Some(u), None) => write!(f, "ConfigFile({}, [missing])", u),
Self::Session(None, Some(_)) => write!(f, "ConfigFile([missing], ******)"),
Self::Session(None, None) => write!(f, "ConfigFile([missing], [missing])"),
Self::Invalid(u) => write!(f, "Invalid({})", u),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/term_ui/dialogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ impl From<Credentials> for Store {
Credentials::Keyring(_) => Self::Keyring,
Credentials::ConfigFile(_, _) => Self::ConfigFile,
Credentials::Session(_, _) => Self::Session,
Credentials::Invalid(_) => Self::Session,
}
}
}
Expand Down

0 comments on commit 9315ae0

Please sign in to comment.