mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-07 07:38:59 +00:00
client: impl HttpApiClient for refs, Arcs and Rcs
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
a3322e49b9
commit
dff830ba04
@ -21,7 +21,7 @@ pub use client::{Client, TlsOptions};
|
|||||||
|
|
||||||
/// HTTP client backend trait. This should be implemented for a HTTP client capable of making
|
/// HTTP client backend trait. This should be implemented for a HTTP client capable of making
|
||||||
/// *authenticated* API requests to a proxmox HTTP API.
|
/// *authenticated* API requests to a proxmox HTTP API.
|
||||||
pub trait HttpApiClient: Send + Sync {
|
pub trait HttpApiClient {
|
||||||
/// An API call should return a status code and the raw body.
|
/// An API call should return a status code and the raw body.
|
||||||
type ResponseFuture<'a>: Future<Output = Result<HttpApiResponse, Error>> + 'a
|
type ResponseFuture<'a>: Future<Output = Result<HttpApiResponse, Error>> + 'a
|
||||||
where
|
where
|
||||||
@ -160,3 +160,108 @@ impl<T> RawApiResponse<T> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'c, C> HttpApiClient for &'c C
|
||||||
|
where
|
||||||
|
C: HttpApiClient,
|
||||||
|
{
|
||||||
|
type ResponseFuture<'a> = C::ResponseFuture<'a>
|
||||||
|
where
|
||||||
|
Self: 'a;
|
||||||
|
|
||||||
|
fn get<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
|
||||||
|
C::get(self, path_and_query)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn post<'a, T>(&'a self, path_and_query: &'a str, params: &T) -> Self::ResponseFuture<'a>
|
||||||
|
where
|
||||||
|
T: ?Sized + Serialize,
|
||||||
|
{
|
||||||
|
C::post(self, path_and_query, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn put<'a, T>(&'a self, path_and_query: &'a str, params: &T) -> Self::ResponseFuture<'a>
|
||||||
|
where
|
||||||
|
T: ?Sized + Serialize,
|
||||||
|
{
|
||||||
|
C::put(self, path_and_query, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn put_without_body<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
|
||||||
|
C::put_without_body(self, path_and_query)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
|
||||||
|
C::delete(self, path_and_query)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<C> HttpApiClient for std::sync::Arc<C>
|
||||||
|
where
|
||||||
|
C: HttpApiClient,
|
||||||
|
{
|
||||||
|
type ResponseFuture<'a> = C::ResponseFuture<'a>
|
||||||
|
where
|
||||||
|
Self: 'a;
|
||||||
|
|
||||||
|
fn get<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
|
||||||
|
C::get(self, path_and_query)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn post<'a, T>(&'a self, path_and_query: &'a str, params: &T) -> Self::ResponseFuture<'a>
|
||||||
|
where
|
||||||
|
T: ?Sized + Serialize,
|
||||||
|
{
|
||||||
|
C::post(self, path_and_query, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn put<'a, T>(&'a self, path_and_query: &'a str, params: &T) -> Self::ResponseFuture<'a>
|
||||||
|
where
|
||||||
|
T: ?Sized + Serialize,
|
||||||
|
{
|
||||||
|
C::put(self, path_and_query, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn put_without_body<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
|
||||||
|
C::put_without_body(self, path_and_query)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
|
||||||
|
C::delete(self, path_and_query)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<C> HttpApiClient for std::rc::Rc<C>
|
||||||
|
where
|
||||||
|
C: HttpApiClient,
|
||||||
|
{
|
||||||
|
type ResponseFuture<'a> = C::ResponseFuture<'a>
|
||||||
|
where
|
||||||
|
Self: 'a;
|
||||||
|
|
||||||
|
fn get<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
|
||||||
|
C::get(self, path_and_query)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn post<'a, T>(&'a self, path_and_query: &'a str, params: &T) -> Self::ResponseFuture<'a>
|
||||||
|
where
|
||||||
|
T: ?Sized + Serialize,
|
||||||
|
{
|
||||||
|
C::post(self, path_and_query, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn put<'a, T>(&'a self, path_and_query: &'a str, params: &T) -> Self::ResponseFuture<'a>
|
||||||
|
where
|
||||||
|
T: ?Sized + Serialize,
|
||||||
|
{
|
||||||
|
C::put(self, path_and_query, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn put_without_body<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
|
||||||
|
C::put_without_body(self, path_and_query)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
|
||||||
|
C::delete(self, path_and_query)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user