Client

Struct Client 

Source
pub struct Client<C, M, R = Standard> { /* private fields */ }
Expand description

An ergonomic service client for IdentityService.

This client allows ergonomic access to a IdentityService-shaped service. Each method corresponds to an endpoint defined in the service’s Smithy model, and the request and response shapes are auto-generated from that same model.

§Constructing a Client

To construct a client, you need a few different things:

  • A Config that specifies additional configuration required by the service.
  • A connector (C) that specifies how HTTP requests are translated into HTTP responses. This will typically be an HTTP client (like hyper), though you can also substitute in your own, like a mock mock connector for testing.
  • A “middleware” (M) that modifies requests prior to them being sent to the request. Most commonly, middleware will decide what endpoint the requests should be sent to, as well as perform authentication and authorization of requests (such as SigV4). You can also have middleware that performs request/response tracing, throttling, or other middleware-like tasks.
  • A retry policy (R) that dictates the behavior for requests that fail and should (potentially) be retried. The default type is generally what you want, as it implements a well-vetted retry policy implemented in RetryMode::Standard.

To construct a client, you will generally want to call Client::with_config, which takes a aws_smithy_client::Client (a Smithy client that isn’t specialized to a particular service), and a Config. Both of these are constructed using the builder pattern where you first construct a Builder type, then configure it with the necessary parameters, and then call build to construct the finalized output type. The aws_smithy_client::Client builder is re-exported in this crate as Builder for convenience.

In most circumstances, you will want to use the following pattern to construct a client:

use rivet_identity::{Builder, Client, Config};
let raw_client =
    Builder::dyn_https()
      .middleware(/* discussed below */)
      .build();
let config = Config::builder().build();
let client = Client::with_config(raw_client, config);

For the middleware, you’ll want to use whatever matches the routing, authentication and authorization required by the target service. For example, for the standard AWS SDK which uses SigV4-signed requests, the middleware looks like this:

use aws_endpoint::AwsEndpointStage;
use aws_http::auth::CredentialsStage;
use aws_http::recursion_detection::RecursionDetectionStage;
use aws_http::user_agent::UserAgentStage;
use aws_sig_auth::middleware::SigV4SigningStage;
use aws_sig_auth::signer::SigV4Signer;
use aws_smithy_client::retry::Config as RetryConfig;
use aws_smithy_http_tower::map_request::{AsyncMapRequestLayer, MapRequestLayer};
use std::fmt::Debug;
use tower::layer::util::{Identity, Stack};
use tower::ServiceBuilder;

type AwsMiddlewareStack = Stack<
    MapRequestLayer<RecursionDetectionStage>,
    Stack<
        MapRequestLayer<SigV4SigningStage>,
        Stack<
            AsyncMapRequestLayer<CredentialsStage>,
            Stack<
                MapRequestLayer<UserAgentStage>,
                Stack<MapRequestLayer<AwsEndpointStage>, Identity>,
            >,
        >,
    >,
>;

/// AWS Middleware Stack
///
/// This implements the middleware stack for this service. It will:
/// 1. Load credentials asynchronously into the property bag
/// 2. Sign the request with SigV4
/// 3. Resolve an Endpoint for the request
/// 4. Add a user agent to the request
#[derive(Debug, Default, Clone)]
#[non_exhaustive]
pub struct AwsMiddleware;

impl AwsMiddleware {
    /// Create a new `AwsMiddleware` stack
    ///
    /// Note: `AwsMiddleware` holds no state.
    pub fn new() -> Self {
        AwsMiddleware::default()
    }
}

// define the middleware stack in a non-generic location to reduce code bloat.
fn base() -> ServiceBuilder<AwsMiddlewareStack> {
    let credential_provider = AsyncMapRequestLayer::for_mapper(CredentialsStage::new());
    let signer = MapRequestLayer::for_mapper(SigV4SigningStage::new(SigV4Signer::new()));
    let endpoint_resolver = MapRequestLayer::for_mapper(AwsEndpointStage);
    let user_agent = MapRequestLayer::for_mapper(UserAgentStage::new());
    let recursion_detection = MapRequestLayer::for_mapper(RecursionDetectionStage::new());
    // These layers can be considered as occurring in order, that is:
    // 1. Resolve an endpoint
    // 2. Add a user agent
    // 3. Acquire credentials
    // 4. Sign with credentials
    // (5. Dispatch over the wire)
    ServiceBuilder::new()
        .layer(endpoint_resolver)
        .layer(user_agent)
        .layer(credential_provider)
        .layer(signer)
        .layer(recursion_detection)
}

impl<S> tower::Layer<S> for AwsMiddleware {
    type Service = <AwsMiddlewareStack as tower::Layer<S>>::Service;

    fn layer(&self, inner: S) -> Self::Service {
        base().service(inner)
    }
}

§Using a Client

Once you have a client set up, you can access the service’s endpoints by calling the appropriate method on Client. Each such method returns a request builder for that endpoint, with methods for setting the various fields of the request. Once your request is complete, use the send method to send the request. send returns a future, which you then have to .await to get the service’s response.

Implementations§

Source§

impl<C, M, R> Client<C, M, R>

Source

pub fn with_config(client: Client<C, M, R>, conf: Config) -> Self

Creates a client with the given service configuration.

Source

pub fn conf(&self) -> &Config

Returns the client’s configuration.

Source§

impl<C, M, R> Client<C, M, R>

Constructs a fluent builder for the CancelGameLink operation.

Constructs a fluent builder for the CompleteGameLink operation.

Source

pub fn complete_identity_avatar_upload( &self, ) -> CompleteIdentityAvatarUpload<C, M, R>

Constructs a fluent builder for the CompleteIdentityAvatarUpload operation.

Source

pub fn follow_identity(&self) -> FollowIdentity<C, M, R>

Constructs a fluent builder for the FollowIdentity operation.

Constructs a fluent builder for the GetGameLink operation.

Source

pub fn get_identity_handles(&self) -> GetIdentityHandles<C, M, R>

Constructs a fluent builder for the GetIdentityHandles operation.

Source

pub fn get_identity_profile(&self) -> GetIdentityProfile<C, M, R>

Constructs a fluent builder for the GetIdentityProfile operation.

Source

pub fn get_identity_self_profile(&self) -> GetIdentitySelfProfile<C, M, R>

Constructs a fluent builder for the GetIdentitySelfProfile operation.

Source

pub fn get_identity_summaries(&self) -> GetIdentitySummaries<C, M, R>

Constructs a fluent builder for the GetIdentitySummaries operation.

Source

pub fn list_activities(&self) -> ListActivities<C, M, R>

Constructs a fluent builder for the ListActivities operation.

Source

pub fn list_followers(&self) -> ListFollowers<C, M, R>

Constructs a fluent builder for the ListFollowers operation.

Source

pub fn list_following(&self) -> ListFollowing<C, M, R>

Constructs a fluent builder for the ListFollowing operation.

Source

pub fn list_friends(&self) -> ListFriends<C, M, R>

Constructs a fluent builder for the ListFriends operation.

Source

pub fn list_mutual_friends(&self) -> ListMutualFriends<C, M, R>

Constructs a fluent builder for the ListMutualFriends operation.

Constructs a fluent builder for the PrepareGameLink operation.

Source

pub fn prepare_identity_avatar_upload( &self, ) -> PrepareIdentityAvatarUpload<C, M, R>

Constructs a fluent builder for the PrepareIdentityAvatarUpload operation.

Source

pub fn remove_identity_game_activity( &self, ) -> RemoveIdentityGameActivity<C, M, R>

Constructs a fluent builder for the RemoveIdentityGameActivity operation.

Source

pub fn report_identity(&self) -> ReportIdentity<C, M, R>

Constructs a fluent builder for the ReportIdentity operation.

Source

pub fn search_identities(&self) -> SearchIdentities<C, M, R>

Constructs a fluent builder for the SearchIdentities operation.

Source

pub fn set_identity_game_activity(&self) -> SetIdentityGameActivity<C, M, R>

Constructs a fluent builder for the SetIdentityGameActivity operation.

Source

pub fn setup_identity(&self) -> SetupIdentity<C, M, R>

Constructs a fluent builder for the SetupIdentity operation.

  • The fluent builder is configurable:
  • On success, responds with SetupIdentityOutput with field(s):
    • identity_token(Option<String>): Token used to authenticate the identity. Should be stored somewhere permanent. Pass this to rivet.api.identity#SetupIdentity$existing_identity_token next time rivet.api.identity#SetupIdentity is called. Token has a 90 day TTL. This means that if rivet.api.identity#SetupIdentity is not called again within 90 days, the token will no longer be valid. If this happens, the user can recover their account through the linking process (see rivet.api.identity#PrepareGameLink). This token should be stored locally and never sent to a server or another device. If this token is comprimised, anyone with access to this token has control of the identity.
    • identity_token_expire_ts(Option<DateTime>): Timestamp (in milliseconds) at which the token expires.
    • identity(Option<IdentityProfile>): Information about the identity that was just authenticated.
    • game_id(Option<String>): A universally unique identifier.
  • On failure, responds with SdkError<SetupIdentityError>
Source

pub fn signup_for_beta(&self) -> SignupForBeta<C, M, R>

Constructs a fluent builder for the SignupForBeta operation.

Source

pub fn unfollow_identity(&self) -> UnfollowIdentity<C, M, R>

Constructs a fluent builder for the UnfollowIdentity operation.

Source

pub fn update_identity_profile(&self) -> UpdateIdentityProfile<C, M, R>

Constructs a fluent builder for the UpdateIdentityProfile operation.

Source

pub fn update_identity_status(&self) -> UpdateIdentityStatus<C, M, R>

Constructs a fluent builder for the UpdateIdentityStatus operation.

Source

pub fn validate_identity_profile(&self) -> ValidateIdentityProfile<C, M, R>

Constructs a fluent builder for the ValidateIdentityProfile operation.

Source

pub fn watch_events(&self) -> WatchEvents<C, M, R>

Constructs a fluent builder for the WatchEvents operation.

Trait Implementations§

Source§

impl<C, M, R> Clone for Client<C, M, R>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: Debug, M: Debug, R: Debug> Debug for Client<C, M, R>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<C, M, R> From<Client<C, M, R>> for Client<C, M, R>

Source§

fn from(client: Client<C, M, R>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<C, M, R> Freeze for Client<C, M, R>

§

impl<C, M, R = Standard> !RefUnwindSafe for Client<C, M, R>

§

impl<C, M, R> Send for Client<C, M, R>
where C: Sync + Send, M: Sync + Send, R: Sync + Send,

§

impl<C, M, R> Sync for Client<C, M, R>
where C: Sync + Send, M: Sync + Send, R: Sync + Send,

§

impl<C, M, R> Unpin for Client<C, M, R>

§

impl<C, M, R = Standard> !UnwindSafe for Client<C, M, R>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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