[−][src]Struct osauth::Session
An OpenStack API session.
The session object serves as a wrapper around an authentication type, providing convenient methods to make HTTP requests and work with microversions.
Note
All clones of one session share the same authentication and endpoint cache. Use with_auth_type to detach a session.
Implementations
impl Session
[src]
pub fn new<Auth: AuthType + 'static>(auth_type: Auth) -> Session
[src]
Create a new session with a given authentication plugin.
The resulting session will use the default endpoint interface (usually, public).
pub fn adapter<Srv>(&self, service: Srv) -> Adapter<Srv>
[src]
Create an adapter for the specific service type.
The new Adapter
will share the same authentication and will initially use the same
endpoint interface (although it can be changed later without affecting the Session
).
If you don't need the Session
any more, using into_adapter is a
bit more efficient.
let session = osauth::from_env().expect("Failed to create an identity provider from the environment"); let adapter = session.adapter(osauth::services::COMPUTE);
pub fn into_adapter<Srv>(self, service: Srv) -> Adapter<Srv>
[src]
Create an adapter for the specific service type.
The new Adapter
will share the same authentication and will initially use the same
endpoint interface (although it can be changed later without affecting the Session
).
This method is a bit more efficient than adapter since it does not involve cloning internal structures.
let session = osauth::from_env().expect("Failed to create an identity provider from the environment"); let adapter = session.into_adapter(osauth::services::COMPUTE);
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 filters in use.
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 async fn refresh<'_>(&'_ mut self) -> Result<(), Error>
[src]
Update the authentication and purges cached endpoint information.
Warning
Authentication will also be updated for clones of this 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 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: AuthType + 'static>(
self,
auth_method: Auth
) -> Session
[src]
self,
auth_method: Auth
) -> Session
Convert this session into one using the given authentication.
pub fn with_endpoint_filters(self, endpoint_filters: EndpointFilters) -> Session
[src]
Convert this session into one using the given endpoint filters.
pub fn with_endpoint_interface(
self,
endpoint_interface: InterfaceType
) -> Session
[src]
self,
endpoint_interface: InterfaceType
) -> Session
Convert this session into one using the given endpoint filters.
pub async fn get_api_versions<'_, Srv: ServiceType + Send>(
&'_ self,
service: Srv
) -> Result<Option<(ApiVersion, ApiVersion)>, Error>
[src]
&'_ self,
service: Srv
) -> Result<Option<(ApiVersion, ApiVersion)>, Error>
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::from_env().expect("Failed to create an identity provider from the environment"); let maybe_versions = session .get_api_versions(osauth::services::COMPUTE) .await?; 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 async fn get_endpoint<'_, Srv, I>(
&'_ self,
service: Srv,
path: I
) -> Result<Url, Error> where
Srv: ServiceType + Send,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
[src]
&'_ self,
service: Srv,
path: I
) -> Result<Url, Error> where
Srv: ServiceType + Send,
I: IntoIterator,
I::Item: AsRef<str>,
I::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 async 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 async fn pick_api_version<'_, Srv, I>(
&'_ self,
service: Srv,
versions: I
) -> Result<Option<ApiVersion>, Error> where
Srv: ServiceType + Send,
I: IntoIterator<Item = ApiVersion>,
I::IntoIter: Send,
[src]
&'_ self,
service: Srv,
versions: I
) -> Result<Option<ApiVersion>, Error> where
Srv: ServiceType + Send,
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.
let session = osauth::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) .await?; if let Some(version) = maybe_version { println!("Using version {}", version); } else { println!("Using the base version"); } let response = session .get(osauth::services::COMPUTE, &["servers"], maybe_version) .await?;
pub async 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 async fn request<'_, Srv, I>(
&'_ self,
service: Srv,
method: Method,
path: I,
api_version: Option<ApiVersion>
) -> Result<RequestBuilder, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
[src]
&'_ self,
service: Srv,
method: Method,
path: I,
api_version: Option<ApiVersion>
) -> Result<RequestBuilder, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::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
). For
an empty path, NO_PATH can be used.
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.
let session = osauth::from_env().expect("Failed to create an identity provider from the environment"); let response = osauth::request::send_checked( session .request(osauth::services::COMPUTE, reqwest::Method::HEAD, &["servers", "1234"], None) .await? ) .await?; 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 async fn get<'_, Srv, I>(
&'_ self,
service: Srv,
path: I,
api_version: Option<ApiVersion>
) -> Result<Response, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
[src]
&'_ self,
service: Srv,
path: I,
api_version: Option<ApiVersion>
) -> Result<Response, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Issue a GET request.
See request for an explanation of the parameters.
pub async fn get_json<'_, Srv, I, T>(
&'_ self,
service: Srv,
path: I,
api_version: Option<ApiVersion>
) -> Result<T, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
T: DeserializeOwned + Send,
[src]
&'_ self,
service: Srv,
path: I,
api_version: Option<ApiVersion>
) -> Result<T, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
T: DeserializeOwned + 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::from_env().expect("Failed to create an identity provider from the environment"); let servers: ServersRoot = session .get_json(osauth::services::COMPUTE, &["servers"], None) .await?; for srv in servers.servers { println!("ID = {}, Name = {}", srv.id, srv.name); }
See request for an explanation of the parameters.
pub async fn get_json_paginated<'_, Srv, I, T>(
&'_ self,
service: Srv,
path: I,
api_version: Option<ApiVersion>,
limit: Option<usize>,
starting_with: Option<<T as Resource>::Id>
) -> Result<impl Stream<Item = Result<T, Error>>, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
T: Resource + Unpin,
<T as Resource>::Root: Into<Vec<T>> + Send,
[src]
&'_ self,
service: Srv,
path: I,
api_version: Option<ApiVersion>,
limit: Option<usize>,
starting_with: Option<<T as Resource>::Id>
) -> Result<impl Stream<Item = Result<T, Error>>, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
T: Resource + Unpin,
<T as Resource>::Root: Into<Vec<T>> + Send,
Fetch a paginated list of JSON objects using the GET request.
use futures::pin_mut; use futures::stream::TryStreamExt; 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>, } // This implementatin defines the relationship between the root resource and its items. impl osauth::stream::Resource for Server { type Id = String; type Root = ServersRoot; fn resource_id(&self) -> Self::Id { self.id.clone() } } // This is another required part of the pagination contract. impl From<ServersRoot> for Vec<Server> { fn from(value: ServersRoot) -> Vec<Server> { value.servers } } let session = osauth::from_env().expect("Failed to create an identity provider from the environment"); let servers = session .get_json_paginated::<_, _, Server>( osauth::services::COMPUTE, &["servers"], None, None, None ) .await?; pin_mut!(servers); while let Some(srv) = servers.try_next().await? { println!("ID = {}, Name = {}", srv.id, srv.name); }
See request for an explanation of the parameters.
pub async fn get_json_query<'_, Srv, I, Q, T>(
&'_ self,
service: Srv,
path: I,
query: Q,
api_version: Option<ApiVersion>
) -> Result<T, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Q: Serialize + Send,
T: DeserializeOwned + Send,
[src]
&'_ self,
service: Srv,
path: I,
query: Q,
api_version: Option<ApiVersion>
) -> Result<T, Error> where
Srv: ServiceType + Send + Clone,
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 async fn get_json_query_paginated<'_, Srv, I, Q, T>(
&'_ self,
service: Srv,
path: I,
query: Q,
api_version: Option<ApiVersion>,
limit: Option<usize>,
starting_with: Option<<T as Resource>::Id>
) -> Result<impl Stream<Item = Result<T, Error>>, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Q: Serialize + Send,
T: Resource + Unpin,
<T as Resource>::Root: Into<Vec<T>> + Send,
[src]
&'_ self,
service: Srv,
path: I,
query: Q,
api_version: Option<ApiVersion>,
limit: Option<usize>,
starting_with: Option<<T as Resource>::Id>
) -> Result<impl Stream<Item = Result<T, Error>>, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Q: Serialize + Send,
T: Resource + Unpin,
<T as Resource>::Root: Into<Vec<T>> + Send,
Fetch a paginated list of JSON objects 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 async fn get_query<'_, Srv, I, Q>(
&'_ self,
service: Srv,
path: I,
query: Q,
api_version: Option<ApiVersion>
) -> Result<Response, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Q: Serialize + Send,
[src]
&'_ self,
service: Srv,
path: I,
query: Q,
api_version: Option<ApiVersion>
) -> Result<Response, Error> where
Srv: ServiceType + Send + Clone,
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 async fn post<'_, Srv, I, T>(
&'_ self,
service: Srv,
path: I,
body: T,
api_version: Option<ApiVersion>
) -> Result<Response, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
T: Serialize + Send,
[src]
&'_ self,
service: Srv,
path: I,
body: T,
api_version: Option<ApiVersion>
) -> Result<Response, Error> where
Srv: ServiceType + Send + Clone,
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 async fn post_json<'_, Srv, I, T, R>(
&'_ self,
service: Srv,
path: I,
body: T,
api_version: Option<ApiVersion>
) -> Result<R, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
T: Serialize + Send,
R: DeserializeOwned + Send,
[src]
&'_ self,
service: Srv,
path: I,
body: T,
api_version: Option<ApiVersion>
) -> Result<R, Error> where
Srv: ServiceType + Send + Clone,
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 async fn put<'_, Srv, I, T>(
&'_ self,
service: Srv,
path: I,
body: T,
api_version: Option<ApiVersion>
) -> Result<Response, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
T: Serialize + Send,
[src]
&'_ self,
service: Srv,
path: I,
body: T,
api_version: Option<ApiVersion>
) -> Result<Response, Error> where
Srv: ServiceType + Send + Clone,
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 async fn put_empty<'_, Srv, I>(
&'_ self,
service: Srv,
path: I,
api_version: Option<ApiVersion>
) -> Result<Response, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
[src]
&'_ self,
service: Srv,
path: I,
api_version: Option<ApiVersion>
) -> Result<Response, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Issue an empty PUT request.
See request for an explanation of the parameters.
pub async fn put_json<'_, Srv, I, T, R>(
&'_ self,
service: Srv,
path: I,
body: T,
api_version: Option<ApiVersion>
) -> Result<R, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
T: Serialize + Send,
R: DeserializeOwned + Send,
[src]
&'_ self,
service: Srv,
path: I,
body: T,
api_version: Option<ApiVersion>
) -> Result<R, Error> where
Srv: ServiceType + Send + Clone,
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 async fn delete<'_, Srv, I>(
&'_ self,
service: Srv,
path: I,
api_version: Option<ApiVersion>
) -> Result<Response, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
[src]
&'_ self,
service: Srv,
path: I,
api_version: Option<ApiVersion>
) -> Result<Response, Error> where
Srv: ServiceType + Send + Clone,
I: IntoIterator,
I::Item: AsRef<str>,
I::IntoIter: Send,
Issue a DELETE request.
See request for an explanation of the parameters.
Trait Implementations
impl Clone for Session
[src]
impl Debug for Session
[src]
impl<Srv> From<Adapter<Srv>> for Session
[src]
impl From<Session> for SyncSession
[src]
fn from(value: Session) -> SyncSession
[src]
impl From<SyncSession> for Session
[src]
fn from(value: SyncSession) -> Session
[src]
Auto Trait Implementations
impl !RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl !UnwindSafe for Session
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, 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>,