Enum AutoStrategy
pub enum AutoStrategy {
AccessKey(AccessKeyStrategy),
DeviceSession(DeviceSessionStrategy),
}Expand description
An AuthStrategy that automatically detects available credentials
and delegates to the appropriate inner strategy.
§Detection order
- If the
CS_CLIENT_ACCESS_KEYenvironment variable is set, anAccessKeyStrategyis created. The workspace CRN is parsed fromCS_WORKSPACE_CRN(or the explicitwith_workspace_crnvalue); its region drives service discovery and its workspace ID is used to verify every issued token. - If a token store file exists at the default location
(
~/.cipherstash/auth.json), aDeviceSessionStrategyis created from it. - Otherwise,
AuthError::NotAuthenticatedis returned.
§Examples
use stack_auth::{AuthStrategy, AutoStrategy};
// Auto-detect from env vars + profile store
let strategy = AutoStrategy::detect()?;
let token = (&strategy).get_token().await?;
println!("Authenticated! token={:?}", token);use stack_auth::AutoStrategy;
// Provide explicit values with env/profile fallback
let strategy = AutoStrategy::builder()
.with_access_key("CSAK...")
.detect()?;Variants§
AccessKey(AccessKeyStrategy)
Authenticated via a static access key.
DeviceSession(DeviceSessionStrategy)
Authenticated via OAuth tokens persisted on disk.
Implementations§
Source§impl AutoStrategy
impl AutoStrategy
Sourcepub fn builder() -> AutoStrategyBuilder
pub fn builder() -> AutoStrategyBuilder
Create a builder for configuring credential resolution.
The builder lets callers provide explicit values (access key, workspace CRN) that take precedence over environment variables and the profile store.
§Example
use stack_auth::AutoStrategy;
use cts_common::Crn;
let crn: Crn = "crn:ap-southeast-2.aws:workspace-id".parse()?;
let strategy = AutoStrategy::builder()
.with_access_key("CSAKmyKeyId.myKeySecret")
.with_workspace_crn(crn)
.detect()?;Sourcepub fn detect() -> Result<AutoStrategy, AuthError>
pub fn detect() -> Result<AutoStrategy, AuthError>
Detect credentials from environment variables and profile store.
Equivalent to AutoStrategy::builder().detect().
Resolution order:
CS_CLIENT_ACCESS_KEYenv var →AccessKeyStrategy~/.cipherstash/auth.json→DeviceSessionStrategyAuthError::NotAuthenticated
Trait Implementations§
Source§impl AuthStrategy for &AutoStrategy
impl AuthStrategy for &AutoStrategy
Auto Trait Implementations§
impl !Freeze for AutoStrategy
impl !RefUnwindSafe for AutoStrategy
impl !UnwindSafe for AutoStrategy
impl Send for AutoStrategy
impl Sync for AutoStrategy
impl Unpin for AutoStrategy
impl UnsafeUnpin for AutoStrategy
Blanket Implementations§
impl<T> AuthStrategyBounds for T
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
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>
Converts
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>
Converts
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