Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcb609be

Browse files
committed
Defer username default
1 parent75cc986 commitcb609be

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

‎postgres/src/config.rs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,8 @@ impl Config {
158158
self
159159
}
160160

161-
/// Gets the user to authenticate with.
162-
///
163-
/// If no user has been configured with the [`user`](Config::user) method,
164-
/// then this defaults to the user executing this process. It always
165-
/// returns `Some`.
166-
// FIXME remove option
161+
/// Gets the user to authenticate with, if one has been configured with
162+
/// the `user` method.
167163
pubfnget_user(&self) ->Option<&str>{
168164
self.config.get_user()
169165
}

‎tokio-postgres/src/config.rs‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub enum Host {
190190
/// ```
191191
#[derive(Clone,PartialEq,Eq)]
192192
pubstructConfig{
193-
pub(crate)user:String,
193+
pub(crate)user:Option<String>,
194194
pub(crate)password:Option<Vec<u8>>,
195195
pub(crate)dbname:Option<String>,
196196
pub(crate)options:Option<String>,
@@ -219,7 +219,7 @@ impl Config {
219219
/// Creates a new configuration.
220220
pubfnnew() ->Config{
221221
Config{
222-
user:whoami::username(),
222+
user:None,
223223
password:None,
224224
dbname:None,
225225
options:None,
@@ -247,18 +247,14 @@ impl Config {
247247
///
248248
/// Defaults to the user executing this process.
249249
pubfnuser(&mutself,user:&str) ->&mutConfig{
250-
self.user = user.to_string();
250+
self.user =Some(user.to_string());
251251
self
252252
}
253253

254-
/// Gets the user to authenticate with.
255-
///
256-
/// If no user has been configured with the [`user`](Config::user) method,
257-
/// then this defaults to the user executing this process. It always
258-
/// returns `Some`.
259-
// FIXME remove option
254+
/// Gets the user to authenticate with, if one has been configured with
255+
/// the `user` method.
260256
pubfnget_user(&self) ->Option<&str>{
261-
Some(&self.user)
257+
self.user.as_deref()
262258
}
263259

264260
/// Sets the password to authenticate with.

‎tokio-postgres/src/connect_raw.rs‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ where
9696
delayed:VecDeque::new(),
9797
};
9898

99-
startup(&mut stream, config).await?;
100-
authenticate(&mut stream, config).await?;
99+
let user = config.user.clone().unwrap_or_else(whoami::username);
100+
101+
startup(&mut stream, config,&user).await?;
102+
authenticate(&mut stream, config,&user).await?;
101103
let(process_id, secret_key, parameters) =read_info(&mut stream).await?;
102104

103105
let(sender, receiver) = mpsc::unbounded();
@@ -107,13 +109,17 @@ where
107109
Ok((client, connection))
108110
}
109111

110-
asyncfnstartup<S,T>(stream:&mutStartupStream<S,T>,config:&Config) ->Result<(),Error>
112+
asyncfnstartup<S,T>(
113+
stream:&mutStartupStream<S,T>,
114+
config:&Config,
115+
user:&str,
116+
) ->Result<(),Error>
111117
where
112118
S:AsyncRead +AsyncWrite +Unpin,
113119
T:AsyncRead +AsyncWrite +Unpin,
114120
{
115121
letmut params =vec![("client_encoding","UTF8")];
116-
params.push(("user",&config.user));
122+
params.push(("user", user));
117123
ifletSome(dbname) =&config.dbname{
118124
params.push(("database",&**dbname));
119125
}
@@ -133,7 +139,11 @@ where
133139
.map_err(Error::io)
134140
}
135141

136-
asyncfnauthenticate<S,T>(stream:&mutStartupStream<S,T>,config:&Config) ->Result<(),Error>
142+
asyncfnauthenticate<S,T>(
143+
stream:&mutStartupStream<S,T>,
144+
config:&Config,
145+
user:&str,
146+
) ->Result<(),Error>
137147
where
138148
S:AsyncRead +AsyncWrite +Unpin,
139149
T:TlsStream +Unpin,
@@ -156,7 +166,6 @@ where
156166
Some(Message::AuthenticationMd5Password(body)) =>{
157167
can_skip_channel_binding(config)?;
158168

159-
let user =&config.user;
160169
let pass = config
161170
.password
162171
.as_ref()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp