Skip to main content

agentctl_auth/
credential.rs

1//! Core credential types.
2
3use serde::{Deserialize, Serialize};
4
5/// A credential in the auth pool.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct Credential {
8    pub provider: String,
9    #[serde(rename = "type")]
10    pub cred_type: String,
11    #[serde(default)]
12    pub token: Option<String>,
13    #[serde(default)]
14    pub keychain_service: Option<String>,
15}
16
17impl Credential {
18    /// Get the resolved token value.
19    ///
20    /// Returns `None` if the credential uses keychain storage (caller must resolve).
21    pub fn resolved_token(&self) -> Option<&str> {
22        self.token.as_deref()
23    }
24
25    /// Whether this credential is an OAuth credential.
26    pub fn is_oauth(&self) -> bool {
27        self.cred_type == "oauth"
28    }
29}
30
31/// Usage statistics for a credential.
32#[derive(Debug, Clone, Serialize, Deserialize, Default)]
33pub struct UsageStats {
34    #[serde(default)]
35    pub last_used: Option<u64>,
36    #[serde(default)]
37    pub error_count: Option<u32>,
38    #[serde(default)]
39    pub cooldown_until: Option<u64>,
40}
41
42/// Result of testing a credential against an API.
43#[derive(Debug, Clone, Serialize)]
44pub struct TestResult {
45    pub credential_name: String,
46    pub provider: String,
47    pub success: bool,
48    pub status_code: Option<u16>,
49    pub error: Option<String>,
50    pub latency_ms: u64,
51}