pub struct DshApiPlatformClientFactory { /* private fields */ }Expand description
§Platform factory for DSH API client
This module provides a factory for creating DshApiClient instances,
based on a platform and a single-sign-on access token for that platform.
The DshApiClients for the different tenant name all share the same API client which uses a
pool to connect to the resource management API. This gives much better performance than
creating a separate client for each tenant and avoids network and dns problems.
This factory should be used with the single-sign-on authentication and authorization pattern.
For creating clients that authenticate and authorize with a robot password the
DshApiClientFactory should be used.
Create a factory by providing the platform and access_token parameters to the
create_from_access_token function.
Once you have the DshApiPlatformClientFactory you can call its
client() method with a tenant name as parameter
to get a DshApiClient.
§Example
In this example explicit platform and access token parameters are used to create a
DshApiPlatformClientFactory.
use dsh_api::platform::DshPlatform;
use dsh_api::dsh_api_platform_client_factory::DshApiPlatformClientFactory;
let platform = DshPlatform::try_from("np-aws-lz-dsh")?;
let access_token = "...";
let client_factory =
DshApiPlatformClientFactory::create_from_access_token(platform, access_token)?;
let client = client_factory.client("my-tenant").await?;
...Implementations§
Source§impl DshApiPlatformClientFactory
impl DshApiPlatformClientFactory
Sourcepub fn create_from_access_token<T>(
platform: DshPlatform,
access_token: T,
) -> Result<Self, DshApiError>
pub fn create_from_access_token<T>( platform: DshPlatform, access_token: T, ) -> Result<Self, DshApiError>
§Create platform factory for DSH API client with static access token
This function will create a new DshApiPlatformClientFactory from the provided parameters.
§Parameters
platform- Platform for which the factory will be created.access_token- The static access token used to access the API for the platform.
§Examples
use dsh_api::platform::DshPlatform;
use dsh_api::dsh_api_client_factory::DshApiPlatformClientFactory;
let platform = DshPlatform::new("nplz");
let access_token = "...";
let client_factory =
DshApiPlatformClientFactory::create_from_access_token(platform, access_token)?;
let client = client_factory.client("my-tenant").await?;
println!("tenant is {}", client.tenant());Sourcepub fn platform(&self) -> &DshPlatform
pub fn platform(&self) -> &DshPlatform
§Returns the factories platform
Sourcepub async fn client<T>(
&self,
tenant_name: T,
) -> Result<DshApiClient, DshApiError>
pub async fn client<T>( &self, tenant_name: T, ) -> Result<DshApiClient, DshApiError>
§Create an DSH API client
This function will create a new DshApiClient for the platform and the provided tenant name.
§Parameters
tenant_name- Name of the tenant for which the client will be created.
§Returns
Ok<DshApiClient>- Created client.Err<DshApiError>- Error message when the client could not be created.
§Examples
use dsh_api::dsh_api_client_factory::DshApiPlatformClientFactory;
let platform = DshPlatform::try_from("np-aws-lz-dsh")?;
let access_token = "...";
let client_factory = DshApiPlatformClientFactory::create_from_access_token(platform, access_token)?;
match client_factory.client("my-tenant").await {
Ok(client) => println!("tenant is {}", client.tenant()),
Err(error) => println!("could not create client ({})", error),
}Trait Implementations§
Auto Trait Implementations§
impl Freeze for DshApiPlatformClientFactory
impl !RefUnwindSafe for DshApiPlatformClientFactory
impl Send for DshApiPlatformClientFactory
impl Sync for DshApiPlatformClientFactory
impl Unpin for DshApiPlatformClientFactory
impl !UnwindSafe for DshApiPlatformClientFactory
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more