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 AuthRemoveResult {
34    pub target_file: String,
35    pub removed: bool,
36}
37
38#[derive(Debug, Clone, Serialize)]
39pub struct AuthRefreshResult {
40    pub target_file: String,
41    pub refreshed: bool,
42    pub synced: bool,
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub refreshed_at: Option<String>,
45}
46
47#[derive(Debug, Clone, Serialize)]
48pub struct AuthAutoRefreshTargetResult {
49    pub target_file: String,
50    pub status: String,
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub reason: Option<String>,
53}
54
55#[derive(Debug, Clone, Serialize)]
56pub struct AuthAutoRefreshResult {
57    pub refreshed: i64,
58    pub skipped: i64,
59    pub failed: i64,
60    pub min_age_days: i64,
61    pub targets: Vec<AuthAutoRefreshTargetResult>,
62}
63
64#[derive(Debug, Clone, Serialize)]
65pub struct AuthCurrentResult {
66    pub auth_file: String,
67    pub matched: bool,
68    #[serde(skip_serializing_if = "Option::is_none")]
69    pub matched_secret: Option<String>,
70    #[serde(skip_serializing_if = "Option::is_none")]
71    pub match_mode: Option<String>,
72}
73
74#[derive(Debug, Clone, Serialize)]
75pub struct AuthSyncResult {
76    pub auth_file: String,
77    pub synced: usize,
78    pub skipped: usize,
79    pub failed: usize,
80    #[serde(skip_serializing_if = "Vec::is_empty")]
81    pub updated_files: Vec<String>,
82}
83
84pub fn emit_result<T: Serialize>(command: &str, result: T) -> Result<()> {
85    diag_output::emit_success_result(AUTH_SCHEMA_VERSION, command, result)
86}
87
88pub fn emit_error(
89    command: &str,
90    code: &str,
91    message: impl Into<String>,
92    details: Option<Value>,
93) -> Result<()> {
94    diag_output::emit_error(AUTH_SCHEMA_VERSION, command, code, message, details)
95}