DshApiPlatformClientFactory

Struct DshApiPlatformClientFactory 

Source
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

Source

pub fn create_from_access_token<T>( platform: DshPlatform, access_token: T, ) -> Result<Self, DshApiError>
where T: Into<String>,

§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());
Source

pub fn platform(&self) -> &DshPlatform

§Returns the factories platform
Source

pub async fn client<T>( &self, tenant_name: T, ) -> Result<DshApiClient, DshApiError>
where T: Into<String>,

§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§

Source§

impl Debug for DshApiPlatformClientFactory

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more