[−][src]Struct openstack::session::Session
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]
S: AsRef<str>,
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]
Auth: 'static + AuthType,
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]
Auth: 'static + AuthType,
Convert this session into one using the given authentication.
pub fn with_endpoint_filters(
self,
endpoint_filters: EndpointFilters
) -> SyncSession
[src]
self,
endpoint_filters: EndpointFilters
) -> SyncSession
Convert this session into one using the given endpoint filters.
pub fn with_endpoint_interface(
self,
endpoint_interface: InterfaceType
) -> SyncSession
[src]
self,
endpoint_interface: InterfaceType
) -> SyncSession
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]
&self,
service: Srv
) -> Result<Option<(ApiVersion, ApiVersion)>, Error> where
Srv: ServiceType + Send,
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]
I: IntoIterator,
Srv: ServiceType + Send,
<I as IntoIterator>::Item: AsRef<str>,
<I as IntoIterator>::IntoIter: Send,
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]
&self,
service: Srv
) -> Result<Option<ApiVersion>, Error> where
Srv: ServiceType + 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<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]
&self,
service: Srv,
versions: I
) -> Result<Option<ApiVersion>, Error> where
I: IntoIterator<Item = ApiVersion>,
Srv: ServiceType + Send,
<I as IntoIterator>::IntoIter: Send,
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]
&self,
service: Srv,
version: ApiVersion
) -> Result<bool, Error> where
Srv: ServiceType + Send,
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]
&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,
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]
&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,
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]
&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,
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]
&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,
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]
&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,
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]
&self,
response: Response
) -> SyncStream<'_, impl Stream<Item = Result<Bytes, Error>>, Error>
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]
&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,
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]
&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,
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]
&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,
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]
&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,
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]
&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,
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]
&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,
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]
T: DeserializeOwned + Send,
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]
fn clone(&self) -> SyncSession
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for SyncSession
[src]
impl From<Session> for SyncSession
[src]
fn from(value: Session) -> SyncSession
[src]
impl From<SyncSession> for Cloud
[src]
fn from(value: SyncSession) -> 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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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, U> TryFrom<U> 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<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,