Skip to main content

Session

Trait Session 

Source
pub trait Session {
    // Required methods
    async fn login(&self) -> Result<String>;
    fn set_credentials(&mut self, password: &str) -> Result<()>;
    fn session_id_file(&self) -> &str;
    fn secret(&self) -> Secret;
    fn retry(&self) -> i32;
    fn inc_retry(&mut self);
    fn reset_retry(&mut self);

    // Provided methods
    async fn get_session_id(&mut self) -> Result<String> { ... }
    fn read_session_id(file_name: &str) -> Result<String> { ... }
    fn write_session_id(file_name: &str, session_id: &str) -> Result<()> { ... }
    fn delete_session_id(&self) -> Result<()> { ... }
}
Expand description

Session lifecycle shared by every API client: cache the session id on disk, prompt for the password only when needed, retry a bounded number of times.

Implementors supply the provider-specific pieces (login, set_credentials, file names); the provided methods do the rest.

Required Methods§

Source

async fn login(&self) -> Result<String>

Authenticates with the stored credentials, returning a session id.

Source

fn set_credentials(&mut self, password: &str) -> Result<()>

Stores the password (encoded as the provider requires) for login.

Source

fn session_id_file(&self) -> &str

Per-provider session cache filename.

Source

fn secret(&self) -> Secret

Per-provider secret manager (prompt text, cache file).

Source

fn retry(&self) -> i32

Current failed-attempt count.

Source

fn inc_retry(&mut self)

Bumps the failed-attempt count.

Source

fn reset_retry(&mut self)

Clears the failed-attempt count after a successful login.

Provided Methods§

Source

async fn get_session_id(&mut self) -> Result<String>

Returns a session id: cached if available, otherwise via login with up to [MAX_RETRY_COUNT] password attempts (a retry always re-prompts rather than reusing a password that just failed).

Source

fn read_session_id(file_name: &str) -> Result<String>

Reads the cached session id.

Source

fn write_session_id(file_name: &str, session_id: &str) -> Result<()>

Writes the session id to the cache file.

Source

fn delete_session_id(&self) -> Result<()>

Drops the cached session, forcing a fresh login next time.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§