codex_auth_manager/
status.rs1use std::{fmt, path::PathBuf};
2
3use super::IdentityName;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum AuthStatus {
8 CodexHomeMissing {
10 path: PathBuf,
12 },
13 None,
15 Native,
17 Managed {
19 identity: IdentityName,
21 },
22 BrokenManaged {
24 identity: IdentityName,
26 },
27 Unknown {
29 reason: UnknownAuthReason,
31 },
32}
33
34impl fmt::Display for AuthStatus {
35 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36 match self {
37 Self::CodexHomeMissing { path } => write!(f, "Codex home missing: {}", path.display()),
38 Self::None => write!(f, "No auth file"),
39 Self::Native => write!(f, "Native auth file"),
40 Self::Managed { identity } => write!(f, "Active identity: {identity}"),
41 Self::BrokenManaged { identity } => {
42 write!(f, "Active identity is broken: {identity}")
43 }
44 Self::Unknown { reason } => write!(f, "Unknown auth state: {reason}"),
45 }
46 }
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq)]
51pub enum UnknownAuthReason {
52 AuthPathIsNotFileOrSymlink,
54 SymlinkTargetOutsideManagerDir,
56 SymlinkTargetHasInvalidIdentityName,
58}
59
60impl fmt::Display for UnknownAuthReason {
61 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62 match self {
63 Self::AuthPathIsNotFileOrSymlink => write!(f, "auth.json is not a file or symlink"),
64 Self::SymlinkTargetOutsideManagerDir => {
65 write!(f, "symlink target is outside codex-auth-manager")
66 }
67 Self::SymlinkTargetHasInvalidIdentityName => {
68 write!(f, "symlink target has invalid identity name")
69 }
70 }
71 }
72}