Skip to main content

codex_cli/auth/
output.rs

1use anyhow::Result;
2use serde::Serialize;
3use serde_json::Value;
4
5use crate::diag_output;
6
7pub const AUTH_SCHEMA_VERSION: &str = "codex-cli.auth.v1";
8
9#[derive(Debug, Clone, Serialize)]
10pub struct AuthLoginResult {
11    pub method: String,
12    pub provider: String,
13    pub completed: bool,
14}
15
16#[derive(Debug, Clone, Serialize)]
17pub struct AuthUseResult {
18    pub target: String,
19    pub matched_secret: Option<String>,
20    pub applied: bool,
21    pub auth_file: String,
22}
23
24#[derive(Debug, Clone, Serialize)]
25pub struct AuthSaveResult {
26    pub auth_file: String,
27    pub target_file: String,
28    pub saved: bool,
29    pub overwritten: bool,
30}
31
32#[derive(Debug, Clone, Serialize)]
33pub struct AuthRefreshResult {
34    pub target_file: String,
35    pub refreshed: bool,
36    pub synced: bool,
37    #[serde(skip_serializing_if = "Option::is_none")]
38    pub refreshed_at: Option<String>,
39}
40
41#[derive(Debug, Clone, Serialize)]
42pub struct AuthAutoRefreshTargetResult {
43    pub target_file: String,
44    pub status: String,
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub reason: Option<String>,
47}
48
49#[derive(Debug, Clone, Serialize)]
50pub struct AuthAutoRefreshResult {
51    pub refreshed: i64,
52    pub skipped: i64,
53    pub failed: i64,
54    pub min_age_days: i64,
55    pub targets: Vec<AuthAutoRefreshTargetResult>,
56}
57
58#[derive(Debug, Clone, Serialize)]
59pub struct AuthCurrentResult {
60    pub auth_file: String,
61    pub matched: bool,
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub matched_secret: Option<String>,
64    #[serde(skip_serializing_if = "Option::is_none")]
65    pub match_mode: Option<String>,
66}
67
68#[derive(Debug, Clone, Serialize)]
69pub struct AuthSyncResult {
70    pub auth_file: String,
71    pub synced: usize,
72    pub skipped: usize,
73    pub failed: usize,
74    #[serde(skip_serializing_if = "Vec::is_empty")]
75    pub updated_files: Vec<String>,
76}
77
78pub fn emit_result<T: Serialize>(command: &str, result: T) -> Result<()> {
79    diag_output::emit_success_result(AUTH_SCHEMA_VERSION, command, result)
80}
81
82pub fn emit_error(
83    command: &str,
84    code: &str,
85    message: impl Into<String>,
86    details: Option<Value>,
87) -> Result<()> {
88    diag_output::emit_error(AUTH_SCHEMA_VERSION, command, code, message, details)
89}