Skip to content

Commit f627ccb

Browse files
committed
Merge #36: refactor(client): Refactor Client::with_auth method
c47665b refactor(client): Refactor Client::with_auth mthd (Vihiga Tyonum) Pull request description: <!-- You can erase any parts of this template not applicable to your Pull Request. --> ### Description This PR simplifies the `Client::auth_with` method to use `Auth::get_user_pass()` instead of a `match` expression for authentication. Fixes #17 <!-- Describe the purpose of this PR, what's being adding and/or fixed --> ### Notes to the reviewers <!-- In this section you can include notes directed to the reviewers, like explaining why some parts of the PR were done in a specific way --> ## Changelog notice <!-- Notice the release manager should include in the release tag message changelog --> <!-- See https://keepachangelog.com/en/1.0.0/ for examples --> ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: ValuedMammal: ACK c47665b; ran the tests locally Tree-SHA512: aed0fc0c2d259694cfdf41b323aa35d66bc2932e2752d34d38d1f0ce8e73683fbadd54a56c50fbbc42c1304985dae71889f7b353e27a750078d5807c9c388968
2 parents bbb7560 + c47665b commit f627ccb

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

src/client.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,11 @@ impl Client {
8383
.map_err(|e| Error::InvalidUrl(format!("{e}")))?
8484
.timeout(std::time::Duration::from_secs(60));
8585

86-
builder = match auth {
87-
Auth::UserPass(user, pass) => builder.basic_auth(user, Some(pass)),
88-
Auth::CookieFile(path) => {
89-
let cookie = std::fs::read_to_string(path)
90-
.map_err(|_| Error::InvalidCookieFile)?
91-
.trim()
92-
.to_string();
93-
builder.cookie_auth(cookie)
94-
}
95-
};
86+
let (user, pass) = auth.get_user_pass()?;
9687

88+
if let Some(username) = user {
89+
builder = builder.basic_auth(username, pass);
90+
}
9791
Ok(Self {
9892
inner: jsonrpc::Client::with_transport(builder.build()),
9993
})
@@ -307,7 +301,6 @@ mod test_auth {
307301
let cookie_path = PathBuf::from("/nonexistent/path/to/cookie");
308302

309303
let result = Client::with_auth(dummy_url, Auth::CookieFile(cookie_path));
310-
311-
assert!(matches!(result, Err(Error::InvalidCookieFile)));
304+
assert!(matches!(result, Err(Error::Io(_))));
312305
}
313306
}

0 commit comments

Comments
 (0)