pub struct SessionManager { /* private fields */ }Expand description
Session manager for handling session lifecycle
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn new(identity_manager: IdentityManager) -> Self
pub fn new(identity_manager: IdentityManager) -> Self
Create a new SessionManager with the provided identity manager
Sourcepub async fn get_api_session(&self) -> ZitiResult<ApiSession>
pub async fn get_api_session(&self) -> ZitiResult<ApiSession>
Get a valid API session, authenticating if necessary
This method checks if there’s a current valid session, and if not, it will authenticate with the controller to obtain a new one.
§Returns
ZitiResult<ApiSession>- A valid API session
§Example
use ziti_sdk::session::SessionManager;
use ziti_sdk::identity::load_from_file;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let identity = load_from_file("identity.json").await?;
let session_manager = SessionManager::new(identity);
let api_session = session_manager.get_api_session().await?;
println!("Got API session: {}", api_session.id);
Ok(())
}Sourcepub async fn get_network_session(
&self,
service_id: &str,
) -> ZitiResult<NetworkSession>
pub async fn get_network_session( &self, service_id: &str, ) -> ZitiResult<NetworkSession>
Sourcepub async fn clear_api_session(&self)
pub async fn clear_api_session(&self)
Clear the current API session
This method clears the stored API session, forcing the next call to
get_api_session() to authenticate again.
Sourcepub async fn has_valid_api_session(&self) -> bool
pub async fn has_valid_api_session(&self) -> bool
Check if the current API session is valid
§Returns
bool- True if there’s a valid (non-expired) API session
Sourcepub fn identity_manager(&self) -> &IdentityManager
pub fn identity_manager(&self) -> &IdentityManager
Get the identity manager associated with this session manager
Trait Implementations§
Source§impl Clone for SessionManager
impl Clone for SessionManager
Source§fn clone(&self) -> SessionManager
fn clone(&self) -> SessionManager
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for SessionManager
impl !UnwindSafe for SessionManager
impl Freeze for SessionManager
impl Send for SessionManager
impl Sync for SessionManager
impl Unpin for SessionManager
impl UnsafeUnpin for SessionManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more