src/client/http_client.rs: use async for credentials
This commit is contained in:
parent
d2267b112d
commit
9d35dbbb8f
@ -134,12 +134,12 @@ impl HttpClient {
|
||||
Self::get_password(&username)?
|
||||
};
|
||||
|
||||
let login = Self::credentials(client.clone(), server.to_owned(), username.to_owned(), password);
|
||||
let login_future = Self::credentials(client.clone(), server.to_owned(), username.to_owned(), password);
|
||||
|
||||
Ok(Self {
|
||||
client,
|
||||
server: String::from(server),
|
||||
auth: BroadcastFuture::new(login),
|
||||
auth: BroadcastFuture::new(Box::new(login)),
|
||||
})
|
||||
}
|
||||
|
||||
@ -410,13 +410,12 @@ impl HttpClient {
|
||||
})
|
||||
}
|
||||
|
||||
fn credentials(
|
||||
async fn credentials(
|
||||
client: Client<HttpsConnector>,
|
||||
server: String,
|
||||
username: String,
|
||||
password: String,
|
||||
) -> Box<dyn Future<Output = Result<AuthInfo, Error>> + Send> {
|
||||
Box::new(async move {
|
||||
) -> Result<AuthInfo, Error> {
|
||||
let data = json!({ "username": username, "password": password });
|
||||
let req = Self::request_builder(&server, "POST", "/api2/json/access/ticket", Some(data)).unwrap();
|
||||
let cred = Self::api_request(client, req).await?;
|
||||
@ -429,7 +428,6 @@ impl HttpClient {
|
||||
let _ = store_ticket_info(&server, &auth.username, &auth.ticket, &auth.token);
|
||||
|
||||
Ok(auth)
|
||||
})
|
||||
}
|
||||
|
||||
async fn api_response(response: Response<Body>) -> Result<Value, Error> {
|
||||
|
Loading…
Reference in New Issue
Block a user