syncCodexCliCreds syncs credentials from OpenAI Codex CLI (~/.codex/).
(logger *zap.Logger)
| 76 | |
| 77 | // syncCodexCliCreds syncs credentials from OpenAI Codex CLI (~/.codex/). |
| 78 | func syncCodexCliCreds(logger *zap.Logger) bool { |
| 79 | home, err := os.UserHomeDir() |
| 80 | if err != nil { |
| 81 | return false |
| 82 | } |
| 83 | |
| 84 | paths := []string{ |
| 85 | filepath.Join(home, ".codex", "credentials.json"), |
| 86 | filepath.Join(home, ".codex", "auth.json"), |
| 87 | } |
| 88 | |
| 89 | for _, path := range paths { |
| 90 | data, err := os.ReadFile(path) //#nosec G304 -- path supplied by user/agent through validated tool surface (boundary check upstream) |
| 91 | if err != nil { |
| 92 | continue |
| 93 | } |
| 94 | |
| 95 | cred := parseCodexCredentials(data, logger) |
| 96 | if cred == nil { |
| 97 | continue |
| 98 | } |
| 99 | |
| 100 | store := LoadStore(logger) |
| 101 | existing := store.Profiles["openai-codex-sync"] |
| 102 | if existing != nil && existing.Expires > cred.Expires { |
| 103 | logger.Debug(i18n.T("auth.sync.codex_newer")) |
| 104 | return false |
| 105 | } |
| 106 | |
| 107 | if err := UpsertProfile("openai-codex-sync", cred, logger); err != nil { |
| 108 | logger.Warn(i18n.T("auth.sync.codex_save_failed"), zap.Error(err)) |
| 109 | return false |
| 110 | } |
| 111 | |
| 112 | logger.Info(i18n.T("auth.sync.codex_synced"), |
| 113 | zap.String("source", path)) |
| 114 | return true |
| 115 | } |
| 116 | |
| 117 | return false |
| 118 | } |
| 119 | |
| 120 | // parseClaudeCredentials parses Claude Code credential formats. |
| 121 | func parseClaudeCredentials(data []byte, logger *zap.Logger) *AuthProfileCredential { |
no test coverage detected