pub struct AppState {
pub credential_source: CredentialSource,
pub policy: Arc<Policy>,
pub database_url: Option<String>,
/* private fields */
}Expand description
Shared application state
Fields§
§credential_source: CredentialSourceCredential source configuration
policy: Arc<Policy>Resolved policy for granular tool access control
database_url: Option<String>Optional Redis database URL for direct connections
Implementations§
Source§impl AppState
impl AppState
Sourcepub fn new(
credential_source: CredentialSource,
policy: Arc<Policy>,
database_url: Option<String>,
) -> Result<Self>
pub fn new( credential_source: CredentialSource, policy: Arc<Policy>, database_url: Option<String>, ) -> Result<Self>
Create new application state
Sourcepub fn available_profiles(&self) -> &[String]
pub fn available_profiles(&self) -> &[String]
Get the list of configured profiles
Sourcepub async fn cloud_client_for_profile(
&self,
profile: Option<&str>,
) -> Result<CloudClient>
pub async fn cloud_client_for_profile( &self, profile: Option<&str>, ) -> Result<CloudClient>
Get or create Cloud API client for a specific profile
If profile is None, uses the first configured profile or default from config
Sourcepub async fn cloud_client(&self) -> Result<CloudClient>
pub async fn cloud_client(&self) -> Result<CloudClient>
Get or create Cloud API client (uses default profile)
Sourcepub async fn enterprise_client_for_profile(
&self,
profile: Option<&str>,
) -> Result<EnterpriseClient>
pub async fn enterprise_client_for_profile( &self, profile: Option<&str>, ) -> Result<EnterpriseClient>
Get or create Enterprise API client for a specific profile
If profile is None, uses the first configured profile or default from config
Sourcepub async fn enterprise_client(&self) -> Result<EnterpriseClient>
pub async fn enterprise_client(&self) -> Result<EnterpriseClient>
Get or create Enterprise API client (uses default profile)
Sourcepub fn database_url_for_profile(&self, profile: Option<&str>) -> Result<String>
pub fn database_url_for_profile(&self, profile: Option<&str>) -> Result<String>
Resolve a Redis database URL from a profile
If profile is None, uses the first configured profile or default from config
Sourcepub async fn redis_connection_for_url(
&self,
url: &str,
) -> Result<MultiplexedConnection>
pub async fn redis_connection_for_url( &self, url: &str, ) -> Result<MultiplexedConnection>
Get or create a cached Redis connection for a resolved URL.
Connections are cached by URL. If a cached connection fails a PING health check, it is evicted and a fresh connection is created.
Sourcepub fn is_write_allowed(&self) -> bool
pub fn is_write_allowed(&self) -> bool
Check if write operations are allowed by the global policy tier.
Returns true for ReadWrite and Full tiers.
Used for defense-in-depth in non-destructive write tool handlers.
Sourcepub fn is_destructive_allowed(&self) -> bool
pub fn is_destructive_allowed(&self) -> bool
Check if destructive operations are allowed by the global policy tier.
Returns true only for Full tier.
Used for defense-in-depth in destructive tool handlers.
Sourcepub async fn set_alias(&self, name: String, commands: Vec<Vec<String>>)
pub async fn set_alias(&self, name: String, commands: Vec<Vec<String>>)
Store a named command alias (session-scoped, in-memory only).
Sourcepub async fn get_alias(&self, name: &str) -> Option<Vec<Vec<String>>>
pub async fn get_alias(&self, name: &str) -> Option<Vec<Vec<String>>>
Retrieve a named command alias.
Sourcepub async fn list_aliases(&self) -> Vec<(String, usize)>
pub async fn list_aliases(&self) -> Vec<(String, usize)>
List all aliases with their command counts.
Sourcepub async fn delete_alias(&self, name: &str) -> bool
pub async fn delete_alias(&self, name: &str) -> bool
Delete a named alias. Returns true if it existed.
Source§impl AppState
Test helpers for creating AppState with pre-configured clients
impl AppState
Test helpers for creating AppState with pre-configured clients
Sourcepub fn test_policy() -> Arc<Policy>
pub fn test_policy() -> Arc<Policy>
Create a default read-only policy for tests
Sourcepub fn with_cloud_client(client: CloudClient) -> Self
pub fn with_cloud_client(client: CloudClient) -> Self
Create test state with a pre-configured Cloud client
Sourcepub fn with_enterprise_client(client: EnterpriseClient) -> Self
pub fn with_enterprise_client(client: EnterpriseClient) -> Self
Create test state with a pre-configured Enterprise client
Sourcepub fn with_clients(cloud: CloudClient, enterprise: EnterpriseClient) -> Self
pub fn with_clients(cloud: CloudClient, enterprise: EnterpriseClient) -> Self
Create test state with both Cloud and Enterprise clients
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for AppState
impl !RefUnwindSafe for AppState
impl Send for AppState
impl Sync for AppState
impl Unpin for AppState
impl UnsafeUnpin for AppState
impl !UnwindSafe for AppState
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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