[][src]Struct openstack::session::Session

pub struct Session { /* fields omitted */ }

A synchronous wrapper for an asynchronous session.

Implementations

impl SyncSession[src]

pub fn new(session: Session) -> SyncSession[src]

Create a new synchronous wrapper.

Panics if unable to create a single-threaded runtime.

pub fn from_config<S>(cloud_name: S) -> Result<SyncSession, Error> where
    S: AsRef<str>, 
[src]

Create a SyncSession from a clouds.yaml configuration file.

See Session::from_config for details.

pub fn from_env() -> Result<SyncSession, Error>[src]

Create a SyncSession from environment variables.

See Session::from_env for details.

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

Get a reference to the authentication type in use.

pub fn endpoint_filters(&self) -> &EndpointFilters[src]

Endpoint interface in use (if any).

pub fn endpoint_filters_mut(&mut self) -> &mut EndpointFilters[src]

Modify endpoint filters.

This call clears the cached service information for this Session. It does not, however, affect clones of this Session.

pub fn refresh(&mut self) -> Result<(), Error>[src]

Refresh the session.

pub fn session(&self) -> &Session[src]

Reference to the asynchronous session used.

pub fn set_auth_type<Auth>(&mut self, auth_type: Auth) where
    Auth: 'static + AuthType
[src]

Set a new authentication for this Session.

This call clears the cached service information for this Session. It does not, however, affect clones of this Session.

pub fn set_endpoint_interface(&mut self, endpoint_interface: InterfaceType)[src]

A convenience call to set an endpoint interface.

This call clears the cached service information for this Session. It does not, however, affect clones of this Session.

pub fn with_auth_type<Auth>(self, auth_method: Auth) -> SyncSession where
    Auth: 'static + AuthType
[src]

Convert this session into one using the given authentication.

pub fn with_endpoint_filters(
    self,
    endpoint_filters: EndpointFilters
) -> SyncSession
[src]

Convert this session into one using the given endpoint filters.

pub fn with_endpoint_interface(
    self,
    endpoint_interface: InterfaceType
) -> SyncSession
[src]

Convert this session into one using the given endpoint filters.

pub fn get_api_versions<Srv>(
    &self,
    service: Srv
) -> Result<Option<(ApiVersion, ApiVersion)>, Error> where
    Srv: ServiceType + 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.

let session = osauth::sync::SyncSession::from_env()
    .expect("Failed to create an identity provider from the environment");
let maybe_versions = session
    .get_api_versions(osauth::services::COMPUTE)
    .expect("Cannot determine supported API 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<Srv, I>(&self, service: Srv, path: I) -> Result<Url, Error> where
    I: IntoIterator,
    Srv: ServiceType + Send,
    <I as IntoIterator>::Item: AsRef<str>,
    <I as IntoIterator>::IntoIter: Send
[src]

Construct and endpoint for the given service 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<Srv>(
    &self,
    service: Srv
) -> Result<Option<ApiVersion>, Error> where
    Srv: ServiceType + 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<Srv, I>(
    &self,
    service: Srv,
    versions: I
) -> Result<Option<ApiVersion>, Error> where
    I: IntoIterator<Item = ApiVersion>,
    Srv: ServiceType + Send,
    <I as IntoIterator>::IntoIter: Send
[src]

Pick the highest API version supported by the service.

Returns None if none of the requested versions are available.

let session = osauth::sync::SyncSession::from_env()
    .expect("Failed to create an identity provider from the environment");
let candidates = vec![osauth::ApiVersion(1, 2), osauth::ApiVersion(1, 42)];
let maybe_version = session
    .pick_api_version(osauth::services::COMPUTE, candidates)
    .expect("Cannot negotiate an API version");
if let Some(version) = maybe_version {
    println!("Using version {}", version);
} else {
    println!("Using the base version");
}

pub fn supports_api_version<Srv>(
    &self,
    service: Srv,
    version: ApiVersion
) -> Result<bool, Error> where
    Srv: ServiceType + Send
[src]

Check if the service supports the API version.

pub fn request<Srv, I>(
    &self,
    service: Srv,
    method: Method,
    path: I,
    api_version: Option<ApiVersion>
) -> Result<RequestBuilder, Error> where
    I: IntoIterator,
    Srv: ServiceType + Send + Clone,
    <I as IntoIterator>::Item: AsRef<str>,
    <I as IntoIterator>::IntoIter: Send
[src]

Make an HTTP request to the given service.

The service argument is an object implementing the ServiceType trait. Some known service types are available in the services module.

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 e.g. send_checked or fetch_json.

use reqwest::Method;

let session = osauth::sync::SyncSession::from_env()
    .expect("Failed to create an identity provider from the environment");
session
    .request(osauth::services::COMPUTE, Method::HEAD, &["servers", "1234"], None)
    .and_then(|builder| session.send_checked(builder))
    .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 get<Srv, I>(
    &self,
    service: Srv,
    path: I,
    api_version: Option<ApiVersion>
) -> Result<Response, Error> where
    I: IntoIterator,
    Srv: ServiceType + Send + Clone,
    <I as IntoIterator>::Item: AsRef<str>,
    <I as IntoIterator>::IntoIter: Send
[src]

Issue a GET request.

See request for an explanation of the parameters.

pub fn get_json<Srv, I, T>(
    &self,
    service: Srv,
    path: I,
    api_version: Option<ApiVersion>
) -> Result<T, Error> where
    I: IntoIterator,
    Srv: ServiceType + Send + Clone,
    T: DeserializeOwned + Send,
    <I as IntoIterator>::Item: AsRef<str>,
    <I as IntoIterator>::IntoIter: Send
[src]

Fetch a JSON using the GET request.

use osproto::common::IdAndName;
use serde::Deserialize;

#[derive(Debug, Deserialize)]
pub struct ServersRoot {
    pub servers: Vec<IdAndName>,
}

let session = osauth::sync::SyncSession::from_env()
    .expect("Failed to create an identity provider from the environment");

session
    .get_json(osauth::services::COMPUTE, &["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<Srv, I, Q, T>(
    &self,
    service: Srv,
    path: I,
    query: Q,
    api_version: Option<ApiVersion>
) -> Result<T, Error> where
    I: IntoIterator,
    Q: Serialize + Send,
    Srv: ServiceType + Send + Clone,
    T: DeserializeOwned + Send,
    <I as IntoIterator>::Item: AsRef<str>,
    <I as IntoIterator>::IntoIter: 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<Srv, I, Q>(
    &self,
    service: Srv,
    path: I,
    query: Q,
    api_version: Option<ApiVersion>
) -> Result<Response, Error> where
    I: IntoIterator,
    Q: Serialize + Send,
    Srv: ServiceType + Send + Clone,
    <I as IntoIterator>::Item: AsRef<str>,
    <I as IntoIterator>::IntoIter: 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 download(
    &self,
    response: Response
) -> SyncStream<'_, impl Stream<Item = Result<Bytes, Error>>, Error>
[src]

Download a body from a response.

use std::io::Read;

let session = osauth::sync::SyncSession::from_env()
    .expect("Failed to create an identity provider from the environment");

session
    .get(osauth::services::OBJECT_STORAGE, &["test-container", "test-object"], None)
    .map(|response| {
        let mut buffer = Vec::new();
        session
            .download(response)
            .read_to_end(&mut buffer)
            .map(|_| {
                println!("Data: {:?}", buffer);
            })
            // Do not do this in production!
            .expect("Could not read the remote file")
    })
    .expect("Could not open the remote file");

pub fn post<Srv, I, T>(
    &self,
    service: Srv,
    path: I,
    body: T,
    api_version: Option<ApiVersion>
) -> Result<Response, Error> where
    I: IntoIterator,
    Srv: ServiceType + Send + Clone,
    T: Serialize + Send,
    <I as IntoIterator>::Item: AsRef<str>,
    <I as IntoIterator>::IntoIter: 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<Srv, I, T, R>(
    &self,
    service: Srv,
    path: I,
    body: T,
    api_version: Option<ApiVersion>
) -> Result<R, Error> where
    I: IntoIterator,
    R: DeserializeOwned + Send,
    Srv: ServiceType + Send + Clone,
    T: Serialize + Send,
    <I as IntoIterator>::Item: AsRef<str>,
    <I as IntoIterator>::IntoIter: 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 put<Srv, I, T>(
    &self,
    service: Srv,
    path: I,
    body: T,
    api_version: Option<ApiVersion>
) -> Result<Response, Error> where
    I: IntoIterator,
    Srv: ServiceType + Send + Clone,
    T: Serialize + Send,
    <I as IntoIterator>::Item: AsRef<str>,
    <I as IntoIterator>::IntoIter: 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<Srv, I>(
    &self,
    service: Srv,
    path: I,
    api_version: Option<ApiVersion>
) -> Result<Response, Error> where
    I: IntoIterator,
    Srv: ServiceType + Send + Clone,
    <I as IntoIterator>::Item: AsRef<str>,
    <I as IntoIterator>::IntoIter: Send
[src]

Issue an empty PUT request.

See request for an explanation of the parameters.

pub fn put_json<Srv, I, T, R>(
    &self,
    service: Srv,
    path: I,
    body: T,
    api_version: Option<ApiVersion>
) -> Result<R, Error> where
    I: IntoIterator,
    R: DeserializeOwned + Send,
    Srv: ServiceType + Send + Clone,
    T: Serialize + Send,
    <I as IntoIterator>::Item: AsRef<str>,
    <I as IntoIterator>::IntoIter: 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 delete<Srv, I>(
    &self,
    service: Srv,
    path: I,
    api_version: Option<ApiVersion>
) -> Result<Response, Error> where
    I: IntoIterator,
    Srv: ServiceType + Send + Clone,
    <I as IntoIterator>::Item: AsRef<str>,
    <I as IntoIterator>::IntoIter: Send
[src]

Issue a DELETE request.

See request for an explanation of the parameters.

pub fn fetch_json<T>(&self, builder: RequestBuilder) -> Result<T, Error> where
    T: DeserializeOwned + Send
[src]

Send the response and convert the response to a JSON.

pub fn send_checked(&self, builder: RequestBuilder) -> Result<Response, Error>[src]

Check the response and convert errors into OpenStack ones.

Trait Implementations

impl Clone for SyncSession[src]

impl Debug for SyncSession[src]

impl From<Session> for SyncSession[src]

impl From<SyncSession> for Cloud[src]

Auto Trait Implementations

impl !RefUnwindSafe for SyncSession

impl Send for SyncSession

impl !Sync for SyncSession

impl Unpin for SyncSession

impl !UnwindSafe for SyncSession

Blanket Implementations

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

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

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

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

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

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

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

type Owned = T

The resulting type after obtaining ownership.

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.