Skip to main content

FinamApiConfig

Struct FinamApiConfig 

Source
pub struct FinamApiConfig {
    pub endpoint: ApiEndpoint,
    pub secret: String,
    pub source_app_id: String,
    pub tokens: Option<Arc<TokenManager>>,
    pub bearer: bool,
    pub request_timeout: Duration,
}
Expand description

Connection and credentials, shared in shape by both connector roles.

Holds the API secret, so it is not Display, and its Debug output hides the secret.

§Examples

Two accounts of one secret share one JWT. The token manager is started once and put into both configs. Here the broker is the in-process imitation:

use brokapi_finam::{FinamApiConfig, UserDataConfig};

// `cfg` is your config: secret plus endpoint.
let tokens = cfg.shared_tokens().await?;
let shared = cfg.with_tokens(tokens);
let first = UserDataConfig::new(shared.clone(), "ACC1", "finam-ud-ACC1");
let second = UserDataConfig::new(shared, "ACC2", "finam-ud-ACC2");
assert_ne!(first.account_id, second.account_id);

Fields§

§endpoint: ApiEndpoint

Address and timeouts of the channel. Default: the production endpoint.

§secret: String

API secret. Ignored when tokens is set.

§source_app_id: String

Optional application id sent with Auth.

§tokens: Option<Arc<TokenManager>>

Already running token manager to reuse (several accounts / roles on one secret).

§bearer: bool

Send authorization: Bearer <jwt> instead of the bare JWT (official SDKs send it bare).

§request_timeout: Duration

Deadline of a unary call. Default 10 seconds.

When it passes with no answer, a read fails with a transport error, and a command (place, cancel) ends as Error::Unknown, because the broker may still have applied it.

Implementations§

Source§

impl FinamApiConfig

Source

pub fn new(secret: impl Into<String>) -> Self

Config for secret with the production endpoint and default settings.

Nothing is checked or sent here. An empty or wrong secret shows up when a connector starts (Error::Config for an empty one, Error::Rejected for one the broker refuses).

Source

pub fn with_tokens(self, tokens: Arc<TokenManager>) -> Self

Reuse a token manager (see FinamApiConfig::shared_tokens).

When set, the connector does not log in itself and secret is not used.

Source

pub fn with_endpoint(self, url: impl Into<String>) -> Self

Points the config at another gRPC server, with the default timeouts.

url is https://host:port (TLS) or http://host:port (plain, for a proxy or the test imitation). It replaces the whole [ApiEndpoint], so set custom timeouts on FinamApiConfig::endpoint after this call.

§Examples
use brokapi_finam::FinamApiConfig;

let cfg = FinamApiConfig::new("secret").with_endpoint("http://127.0.0.1:50051");
assert_eq!(cfg.endpoint.url, "http://127.0.0.1:50051");
Source

pub async fn shared_tokens(&self) -> Result<Arc<TokenManager>, Error>

Authenticates once and returns the manager to put into several connector configs, so that all accounts of one secret share a single JWT.

The manager renews the token in the background until the last Arc is dropped.

§Errors
  • [Error::Config]: the secret is empty or the endpoint URL is invalid.
  • [Error::Config] also: the broker refused the secret (a wrong token is a configuration problem at every broker).
  • [Error::RateLimited]: the broker answered RESOURCE_EXHAUSTED.
  • [Error::Transport]: the broker could not be reached or the call timed out.

Trait Implementations§

Source§

impl Clone for FinamApiConfig

Source§

fn clone(&self) -> FinamApiConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FinamApiConfig

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

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

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

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

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.

§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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