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)?
|
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 {
|
Ok(Self {
|
||||||
client,
|
client,
|
||||||
server: String::from(server),
|
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>,
|
client: Client<HttpsConnector>,
|
||||||
server: String,
|
server: String,
|
||||||
username: String,
|
username: String,
|
||||||
password: String,
|
password: String,
|
||||||
) -> Box<dyn Future<Output = Result<AuthInfo, Error>> + Send> {
|
) -> Result<AuthInfo, Error> {
|
||||||
Box::new(async move {
|
|
||||||
let data = json!({ "username": username, "password": password });
|
let data = json!({ "username": username, "password": password });
|
||||||
let req = Self::request_builder(&server, "POST", "/api2/json/access/ticket", Some(data)).unwrap();
|
let req = Self::request_builder(&server, "POST", "/api2/json/access/ticket", Some(data)).unwrap();
|
||||||
let cred = Self::api_request(client, req).await?;
|
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);
|
let _ = store_ticket_info(&server, &auth.username, &auth.ticket, &auth.token);
|
||||||
|
|
||||||
Ok(auth)
|
Ok(auth)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn api_response(response: Response<Body>) -> Result<Value, Error> {
|
async fn api_response(response: Response<Body>) -> Result<Value, Error> {
|
||||||
|
Loading…
Reference in New Issue
Block a user