mrapids 0.1.31

Your OpenAPI, but executable
Documentation
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Credential status for runtime auth selection
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CredentialStatus {
    pub scheme_name: String,
    pub is_configured: bool,
    pub source: CredentialSource,
    pub validation_status: ValidationStatus,
    pub last_used: Option<chrono::DateTime<chrono::Utc>>,
}

/// Where credentials are sourced from
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum CredentialSource {
    Environment(String), // Environment variable name
    ConfigFile(String),  // Path to config file
    Keychain(String),    // Keychain service name
    Profile(String),     // Auth profile name
    Interactive,         // Will be prompted
    NotConfigured,
}

/// Validation status of credentials
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ValidationStatus {
    Valid,
    Invalid(String), // Error message
    Expired,
    NotValidated,
}

/// Result of auth selection process
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SelectedAuth {
    pub scheme_name: String,
    pub scheme_type: super::SchemeType,
    pub credentials: HashMap<String, String>, // Redacted values
    pub source: CredentialSource,
    pub reason: SelectionReason,
}

/// Why a particular auth scheme was selected
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SelectionReason {
    /// Only valid option available
    OnlyOption,
    /// Explicitly requested via --auth parameter
    ExplicitSelection,
    /// Chosen as best available option
    BestAvailable(String), // Explanation
    /// Default fallback
    Default,
}

/// Detailed auth error with diagnostic information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthDiagnostic {
    pub operation: String,
    pub error_type: AuthErrorType,
    pub missing_credentials: Vec<MissingCredential>,
    pub valid_options: Vec<ValidOption>,
    pub suggestions: Vec<String>,
}

/// Type of authentication error
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AuthErrorType {
    NoCredentials,
    InvalidCredentials,
    ExpiredToken,
    InsufficientScopes(Vec<String>),
    SchemeNotSupported(String),
}

/// Information about a missing credential
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MissingCredential {
    pub scheme_name: String,
    pub credential_type: String,
    pub expected_location: CredentialSource,
    pub setup_command: String,
}

/// A valid authentication option that could work
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValidOption {
    pub schemes: Vec<String>,
    pub all_configured: bool,
    pub setup_commands: Vec<String>,
}