[−][src]Struct osauth::Adapter
Adapter for a specific service.
An Adapter
is very similar to a Session, but is tied to a specific
service, and thus does not require passing a service
argument to all calls.
Methods
impl<Srv> Adapter<Srv>
[src]
pub fn new<Auth: AuthType + 'static>(
auth_type: Auth,
service: Srv
) -> Adapter<Srv>
[src]
auth_type: Auth,
service: Srv
) -> Adapter<Srv>
Create a new adapter with a given authentication plugin.
pub fn from_config<S: AsRef<str>>(
cloud_name: S,
service: Srv
) -> Result<Adapter<Srv>, Error>
[src]
cloud_name: S,
service: Srv
) -> Result<Adapter<Srv>, Error>
Create a new adapter from a clouds.yaml
configuration file.
pub fn from_env(service: Srv) -> Result<Adapter<Srv>, Error>
[src]
Create a new adapter with information from environment variables.
Uses some of OS_*
variables recognized by python-openstackclient
.
pub fn auth_type(&self) -> &dyn AuthType
[src]
Get a reference to the authentication type in use.
pub fn endpoint_interface(&self) -> &Option<String>
[src]
Endpoint interface in use (if any).
pub fn refresh(&mut self) -> impl Future<Item = (), Error = Error> + Send
[src]
Update the authentication and purges cached endpoint information.
Warning
Authentication will also be updated for clones of this Adapter
and its parent Session
,
since they share the same authentication object.
pub fn set_auth_type<Auth: AuthType + 'static>(&mut self, auth_type: Auth)
[src]
Set a new authentication for this Adapter
.
This call clears the cached service information for this Adapter
.
It does not, however, affect clones of this Adapter
.
pub fn set_endpoint_interface<S>(&mut self, endpoint_interface: S) where
S: Into<String>,
[src]
S: Into<String>,
Set endpoint interface to use.
This call clears the cached service information for this Adapter
.
It does not, however, affect clones of this Adapter
.
pub fn with_auth_type<Auth: AuthType + 'static>(
self,
auth_method: Auth
) -> Adapter<Srv>
[src]
self,
auth_method: Auth
) -> Adapter<Srv>
Convert this adapter into one using the given authentication.
pub fn with_endpoint_interface<S>(self, endpoint_interface: S) -> Adapter<Srv> where
S: Into<String>,
[src]
S: Into<String>,
Convert this adapter into one using the given endpoint interface.
impl<Srv: ServiceType + Send + Clone> Adapter<Srv>
[src]
pub fn get_api_versions(
&self
) -> impl Future<Item = Option<(ApiVersion, ApiVersion)>, Error = Error> + Send
[src]
&self
) -> impl Future<Item = Option<(ApiVersion, ApiVersion)>, Error = Error> + Send
Get minimum/maximum API (micro)version information.
Returns None
if the range cannot be determined, which usually means
that microversioning is not supported.
use futures::Future; let adapter = osauth::Adapter::from_env(osauth::services::COMPUTE) .expect("Failed to create an identity provider from the environment"); let future = adapter .get_api_versions() .map(|maybe_versions| { if let Some((min, max)) = maybe_versions { println!("The compute service supports versions {} to {}", min, max); } else { println!("The compute service does not support microversioning"); } });
pub fn get_endpoint<I>(
&self,
path: I
) -> impl Future<Item = Url, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
[src]
&self,
path: I
) -> impl Future<Item = Url, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Construct an endpoint from the path;
You won't need to use this call most of the time, since all request calls can fetch the endpoint automatically.
pub fn get_major_version(
&self
) -> impl Future<Item = Option<ApiVersion>, Error = Error> + Send
[src]
&self
) -> impl Future<Item = Option<ApiVersion>, Error = Error> + Send
Get the currently used major version from the given service.
Can return None
if the service does not support API version discovery at all.
pub fn pick_api_version<I>(
&self,
versions: I
) -> impl Future<Item = Option<ApiVersion>, Error = Error> + Send where
I: IntoIterator<Item = ApiVersion>,
I::IntoIter: Send,
[src]
&self,
versions: I
) -> impl Future<Item = Option<ApiVersion>, Error = Error> + Send where
I: IntoIterator<Item = ApiVersion>,
I::IntoIter: Send,
Pick the highest API version supported by the service.
Returns None
if none of the requested versions are available.
use futures::Future; let adapter = osauth::Adapter::from_env(osauth::services::COMPUTE) .expect("Failed to create an identity provider from the environment"); let candidates = vec![osauth::ApiVersion(1, 2), osauth::ApiVersion(1, 42)]; let future = adapter .pick_api_version(candidates) .and_then(|maybe_version| { if let Some(version) = maybe_version { println!("Using version {}", version); } else { println!("Using the base version"); } adapter.get(&["servers"], maybe_version) });
pub fn supports_api_version(
&self,
version: ApiVersion
) -> impl Future<Item = bool, Error = Error> + Send
[src]
&self,
version: ApiVersion
) -> impl Future<Item = bool, Error = Error> + Send
Check if the service supports the API version.
pub fn request<I>(
&self,
method: Method,
path: I,
api_version: Option<ApiVersion>
) -> impl Future<Item = RequestBuilder, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
[src]
&self,
method: Method,
path: I,
api_version: Option<ApiVersion>
) -> impl Future<Item = RequestBuilder, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Make an HTTP request.
The path
argument is a URL path without the service endpoint (e.g. /servers/1234
).
If api_version
is set, it is send with the request to enable a higher API version.
Otherwise the base API version is used. You can use
pick_api_version to choose an API version to use.
The result is a RequestBuilder
that can be customized further. Error checking and response
parsing can be done using functions from the request module.
use futures::Future; use reqwest::Method; let adapter = osauth::Adapter::from_env(osauth::services::COMPUTE) .expect("Failed to create an identity provider from the environment"); let future = adapter .request(Method::HEAD, &["servers", "1234"], None) .then(osauth::request::send_checked) .map(|response| { println!("Response: {:?}", response); });
This is the most generic call to make a request. You may prefer to use more specific get
,
post
, put
or delete
calls instead.
pub fn start_get<I>(
&self,
path: I,
api_version: Option<ApiVersion>
) -> impl Future<Item = RequestBuilder, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
[src]
&self,
path: I,
api_version: Option<ApiVersion>
) -> impl Future<Item = RequestBuilder, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Start a GET request.
Use this call if you need some advanced features of the resulting RequestBuilder
.
Otherwise use:
- get to issue a generic GET without a query.
- get_query to issue a generic GET with a query.
- get_json to issue GET and parse a JSON result.
- get_json_query to issue GET with a query and parse a JSON result.
See request for an explanation of the parameters.
pub fn get<I>(
&self,
path: I,
api_version: Option<ApiVersion>
) -> impl Future<Item = Response, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
[src]
&self,
path: I,
api_version: Option<ApiVersion>
) -> impl Future<Item = Response, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Issue a GET request.
See request for an explanation of the parameters.
pub fn get_json<I, T>(
&self,
path: I,
api_version: Option<ApiVersion>
) -> impl Future<Item = T, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
T: DeserializeOwned + Send,
[src]
&self,
path: I,
api_version: Option<ApiVersion>
) -> impl Future<Item = T, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
T: DeserializeOwned + Send,
Fetch a JSON using the GET request.
use futures::Future; use serde::Deserialize; #[derive(Debug, Deserialize)] pub struct Server { pub id: String, pub name: String, } #[derive(Debug, Deserialize)] pub struct ServersRoot { pub servers: Vec<Server>, } let adapter = osauth::from_env() .expect("Failed to create an identity provider from the environment") .into_adapter(osauth::services::COMPUTE); let future = adapter .get_json(&["servers"], None) .map(|servers: ServersRoot| { for srv in servers.servers { println!("ID = {}, Name = {}", srv.id, srv.name); } });
See request for an explanation of the parameters.
pub fn get_json_query<I, Q, T>(
&self,
path: I,
query: Q,
api_version: Option<ApiVersion>
) -> impl Future<Item = T, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Q: Serialize + Send,
T: DeserializeOwned + Send,
[src]
&self,
path: I,
query: Q,
api_version: Option<ApiVersion>
) -> impl Future<Item = T, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Q: Serialize + Send,
T: DeserializeOwned + Send,
Fetch a JSON using the GET request with a query.
See reqwest
crate documentation for how to define a query.
See request for an explanation of the parameters.
pub fn get_query<I, Q>(
&self,
path: I,
query: Q,
api_version: Option<ApiVersion>
) -> impl Future<Item = Response, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Q: Serialize + Send,
[src]
&self,
path: I,
query: Q,
api_version: Option<ApiVersion>
) -> impl Future<Item = Response, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Q: Serialize + Send,
Issue a GET request with a query
See reqwest
crate documentation for how to define a query.
See request for an explanation of the parameters.
pub fn start_post<I>(
&self,
path: I,
api_version: Option<ApiVersion>
) -> impl Future<Item = RequestBuilder, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
[src]
&self,
path: I,
api_version: Option<ApiVersion>
) -> impl Future<Item = RequestBuilder, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Start a POST request.
See request for an explanation of the parameters.
pub fn post<I, T>(
&self,
path: I,
body: T,
api_version: Option<ApiVersion>
) -> impl Future<Item = Response, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
T: Serialize + Send,
[src]
&self,
path: I,
body: T,
api_version: Option<ApiVersion>
) -> impl Future<Item = Response, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
T: Serialize + Send,
POST a JSON object.
The body
argument is anything that can be serialized into JSON.
See request for an explanation of the other parameters.
pub fn post_json<I, T, R>(
&self,
path: I,
body: T,
api_version: Option<ApiVersion>
) -> impl Future<Item = R, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
T: Serialize + Send,
R: DeserializeOwned + Send,
[src]
&self,
path: I,
body: T,
api_version: Option<ApiVersion>
) -> impl Future<Item = R, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
T: Serialize + Send,
R: DeserializeOwned + Send,
POST a JSON object and receive a JSON back.
The body
argument is anything that can be serialized into JSON.
See request for an explanation of the other parameters.
pub fn start_put<I>(
&self,
path: I,
api_version: Option<ApiVersion>
) -> impl Future<Item = RequestBuilder, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
[src]
&self,
path: I,
api_version: Option<ApiVersion>
) -> impl Future<Item = RequestBuilder, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Start a PUT request.
See request for an explanation of the parameters.
pub fn put<I, T>(
&self,
path: I,
body: T,
api_version: Option<ApiVersion>
) -> impl Future<Item = Response, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
T: Serialize + Send,
[src]
&self,
path: I,
body: T,
api_version: Option<ApiVersion>
) -> impl Future<Item = Response, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
T: Serialize + Send,
PUT a JSON object.
The body
argument is anything that can be serialized into JSON.
See request for an explanation of the other parameters.
pub fn put_empty<I>(
&self,
path: I,
api_version: Option<ApiVersion>
) -> impl Future<Item = Response, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
[src]
&self,
path: I,
api_version: Option<ApiVersion>
) -> impl Future<Item = Response, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Issue an empty PUT request.
See request for an explanation of the parameters.
pub fn put_json<I, T, R>(
&self,
path: I,
body: T,
api_version: Option<ApiVersion>
) -> impl Future<Item = R, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
T: Serialize + Send,
R: DeserializeOwned + Send,
[src]
&self,
path: I,
body: T,
api_version: Option<ApiVersion>
) -> impl Future<Item = R, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
T: Serialize + Send,
R: DeserializeOwned + Send,
PUT a JSON object and receive a JSON back.
The body
argument is anything that can be serialized into JSON.
See request for an explanation of the other parameters.
pub fn start_delete<I>(
&self,
path: I,
api_version: Option<ApiVersion>
) -> impl Future<Item = RequestBuilder, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
[src]
&self,
path: I,
api_version: Option<ApiVersion>
) -> impl Future<Item = RequestBuilder, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Start a DELETE request.
See request for an explanation of the parameters.
pub fn delete<I>(
&self,
path: I,
api_version: Option<ApiVersion>
) -> impl Future<Item = Response, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
[src]
&self,
path: I,
api_version: Option<ApiVersion>
) -> impl Future<Item = Response, Error = Error> + Send where
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Issue a DELETE request.
See request for an explanation of the parameters.
Trait Implementations
impl<Srv: Clone> Clone for Adapter<Srv>
[src]
fn clone(&self) -> Adapter<Srv>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<Srv: Debug> Debug for Adapter<Srv>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Erased for T
impl<T, U> TryInto for T where
U: TryFrom<T>,
U: TryFrom<T>,