Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

chore: make CodexAuth::api_key a private field (#1965)

Michael Bolin02c9c2ecad78
diff --git a/codex-rs/cli/src/login.rs b/codex-rs/cli/src/login.rs
index 5f56eb1c4d..3881a1ce3f 100644
--- a/codex-rs/cli/src/login.rs
+++ b/codex-rs/cli/src/login.rs
@@ -49,9 +49,9 @@ pub async fn run_login_status(cli_config_overrides: CliConfigOverrides) -> ! {
match load_auth(&config.codex_home) {
Ok(Some(auth)) => match auth.mode {
- AuthMode::ApiKey => {
- if let Some(api_key) = auth.api_key.as_deref() {
- eprintln!("Logged in using an API key - {}", safe_format_key(api_key));
+ AuthMode::ApiKey => match auth.get_token().await {
+ Ok(api_key) => {
+ eprintln!("Logged in using an API key - {}", safe_format_key(&api_key));
if let Ok(env_api_key) = env::var(OPENAI_API_KEY_ENV_VAR) {
if env_api_key == api_key {
@@ -60,11 +60,13 @@ pub async fn run_login_status(cli_config_overrides: CliConfigOverrides) -> ! {
);
}
}
- } else {
- eprintln!("Logged in using an API key");
+ std::process::exit(0);
}
- std::process::exit(0);
- }
+ Err(e) => {
+ eprintln!("Unexpected error retrieving API key: {e}");
+ std::process::exit(1);
+ }
+ },
AuthMode::ChatGPT => {
eprintln!("Logged in using ChatGPT");
std::process::exit(0);
diff --git a/codex-rs/login/src/lib.rs b/codex-rs/login/src/lib.rs
index 3aa1816fcb..36a78aaa22 100644
--- a/codex-rs/login/src/lib.rs
+++ b/codex-rs/login/src/lib.rs
@@ -38,8 +38,9 @@ pub enum AuthMode {
#[derive(Debug, Clone)]
pub struct CodexAuth {
- pub api_key: Option<String>,
pub mode: AuthMode,
+
+ api_key: Option<String>,
auth_dot_json: Arc<Mutex<Option<AuthDotJson>>>,
auth_file: PathBuf,
}