Skip to main content

SmApiClient

Struct SmApiClient 

Source
pub struct SmApiClient { /* private fields */ }
Expand description

SM API client. Stateless until SmApiClient::login establishes a session.

Implementations§

Source§

impl SmApiClient

Source

pub fn new(base_url: Url, flow: LoginFlow) -> Self

Build a client for the SM API base (e.g. https://<sm-api-host>/api/v1).

Source

pub fn with_http_client(base_url: Url, http: Client, flow: LoginFlow) -> Self

Build with a caller-provided reqwest client (tests / shared client).

Source

pub async fn login( &mut self, access_token: &str, sm_id_token: Option<&str>, ) -> Result<(), AuthError>

Establish a session: POST /login with the Okta access token, then fetch the CSRF token. Pass sm_id_token only for SSO logins (omit for Google/GitHub).

Returns AuthError::MfaRequired when SM challenges the login; call SmApiClient::complete_mfa on this same client to finish it.

Source

pub async fn complete_mfa( &mut self, access_token: &str, sm_id_token: Option<&str>, code: &str, ) -> Result<(), AuthError>

Finish an MFA-challenged login with a TOTP code, reusing the challenged session.

Errors with AuthError::Protocol if no challenge is outstanding — submitting a code on a fresh session cannot work, because SM verifies it against challenge state held in the session it issued.

Source

pub async fn fetch_current_user(&self) -> Result<SmUser, AuthError>

GET /users/me.

Source

pub async fn fetch_accounts(&self) -> Result<Vec<SmAccount>, AuthError>

GET /accounts.

Source

pub async fn ensure_capi_enabled(&self) -> Result<bool, AuthError>

POST /accounts/cloud-api/cloudApiAccessKey — enable programmatic access. Idempotent: a 400 account_api_key_already_exists is treated as success. Returns whether this call is what switched programmatic access on, so a caller can say so rather than enabling an account-wide setting silently.

Source

pub async fn mint_capi_key( &self, name: &str, user_account: u64, ) -> Result<CapiKey, AuthError>

POST /accounts/cloud-api/cloudApiKeys — mint a named user secret key.

Source

pub async fn fetch_capi_keys(&self) -> Result<Vec<String>, AuthError>

GET /accounts/cloud-api/cloudApiKeys — list existing CAPI key names. Best-effort: used only to warn about redisctl-* key sprawl at login, so tolerant of response shape.

Source

pub async fn fetch_capi_key_entries( &self, ) -> Result<Vec<(u64, String)>, AuthError>

GET /accounts/cloud-api/cloudApiKeys, as (id, name) pairs.

Source

pub async fn delete_capi_key(&self, id: u64) -> Result<(), AuthError>

DELETE /accounts/cloud-api/cloudApiKeys/{id} — revoke a minted key server-side.

Source

pub async fn set_current_account( &self, account_id: u64, ) -> Result<(), AuthError>

Rebind the session to account_id (POST /accounts/setcurrent/{id}).

Every CAPI call resolves the account from the session — createApiSecretKey uses the session’s userAccountId — so this must happen before enabling access or minting, or the key lands on the previous account. Annotated LEGACY_ONLY server-side, which the JSESSIONID established by SmApiClient::login satisfies.

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> ErasedDestructor for T
where T: 'static,

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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