Skip to content

Commit

Permalink
Restore back compat
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Aug 19, 2023
1 parent f777f74 commit a454378
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
7 changes: 5 additions & 2 deletions postgres/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,12 @@ impl Config {
}

/// Gets the user to authenticate with.
///
/// If no user has been configured with the [`user`](Config::user) method,
/// then this defaults to the user executing this process.
pub fn get_user(&self) -> &str {
/// then this defaults to the user executing this process. It always
/// returns `Some`.
// FIXME remove option
pub fn get_user(&self) -> Option<&str> {
self.config.get_user()
}

Expand Down
15 changes: 9 additions & 6 deletions tokio-postgres/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub enum Host {
/// ```
#[derive(Clone, PartialEq, Eq)]
pub struct Config {
user: String,
pub(crate) user: String,
pub(crate) password: Option<Vec<u8>>,
pub(crate) dbname: Option<String>,
pub(crate) options: Option<String>,
Expand Down Expand Up @@ -245,17 +245,20 @@ impl Config {

/// Sets the user to authenticate with.
///
/// If the user is not set, then this defaults to the user executing this process.
/// Defaults to the user executing this process.
pub fn user(&mut self, user: &str) -> &mut Config {
self.user = user.to_string();
self
}

/// Gets the user to authenticate with.
///
/// If no user has been configured with the [`user`](Config::user) method,
/// then this defaults to the user executing this process.
pub fn get_user(&self) -> &str {
&self.user
/// then this defaults to the user executing this process. It always
/// returns `Some`.
// FIXME remove option
pub fn get_user(&self) -> Option<&str> {
Some(&self.user)
}

/// Sets the password to authenticate with.
Expand Down Expand Up @@ -1125,7 +1128,7 @@ mod tests {
fn test_simple_parsing() {
let s = "user=pass_user dbname=postgres host=host1,host2 hostaddr=127.0.0.1,127.0.0.2 port=26257";
let config = s.parse::<Config>().unwrap();
assert_eq!("pass_user", config.get_user());
assert_eq!(Some("pass_user"), config.get_user());
assert_eq!(Some("postgres"), config.get_dbname());
assert_eq!(
[
Expand Down
4 changes: 2 additions & 2 deletions tokio-postgres/src/connect_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ where
T: AsyncRead + AsyncWrite + Unpin,
{
let mut params = vec![("client_encoding", "UTF8")];
params.push(("user", config.get_user()));
params.push(("user", &config.user));
if let Some(dbname) = &config.dbname {
params.push(("database", &**dbname));
}
Expand Down Expand Up @@ -156,7 +156,7 @@ where
Some(Message::AuthenticationMd5Password(body)) => {
can_skip_channel_binding(config)?;

let user = config.get_user();
let user = &config.user;
let pass = config
.password
.as_ref()
Expand Down

0 comments on commit a454378

Please sign in to comment.