[][src]Struct osauth::Adapter

pub struct Adapter<Srv> { /* fields omitted */ }

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]

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]

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 from_session(session: Session, service: Srv) -> Adapter<Srv>[src]

Create a new adapter from a Session.

pub fn auth_type(&self) -> &dyn AuthType[src]

Get a reference to the authentication type in use.

pub fn default_api_version(&self) -> Option<ApiVersion>[src]

Default API version used when no version is specified.

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 session(&self) -> &Session[src]

Session used for this adapter.

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_default_api_version(&mut self, api_version: Option<ApiVersion>)[src]

Set the default API version.

This version will be used when no version is specified. No checks are done against this version inside of this call. If it is not valid, the subsequent request calls will fail.

pub fn set_endpoint_interface<S>(&mut self, endpoint_interface: S) where
    S: Into<String>, 
[src]

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]

Convert this adapter into one using the given authentication.

pub fn with_default_api_version(
    self,
    api_version: Option<ApiVersion>
) -> Adapter<Srv>
[src]

Convert this adapter into one using the given default API version.

pub fn with_endpoint_interface<S>(self, endpoint_interface: S) -> Adapter<Srv> where
    S: Into<String>, 
[src]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

Issue a DELETE request.

See request for an explanation of the parameters.

Trait Implementations

impl<Srv: Clone> Clone for Adapter<Srv>[src]

impl<Srv> From<Adapter<Srv>> for Session[src]

impl<Srv: Debug> Debug for Adapter<Srv>[src]

Auto Trait Implementations

impl<Srv> Send for Adapter<Srv> where
    Srv: Send

impl<Srv> Unpin for Adapter<Srv> where
    Srv: Unpin

impl<Srv> Sync for Adapter<Srv> where
    Srv: Sync

impl<Srv> !UnwindSafe for Adapter<Srv>

impl<Srv> !RefUnwindSafe for Adapter<Srv>

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Err = <U as TryFrom<T>>::Err