AuthConfig is used for interacting with some persistent configuration for gh, with knowledge on how to access encrypted storage when neccesarry. Behavior is scoped to authentication specific tasks.
| 253 | // with knowledge on how to access encrypted storage when neccesarry. |
| 254 | // Behavior is scoped to authentication specific tasks. |
| 255 | type AuthConfig struct { |
| 256 | cfg *ghConfig.Config |
| 257 | refresher gh.TokenRefresher |
| 258 | defaultHostOverride func() (string, string) |
| 259 | hostsOverride func() []string |
| 260 | tokenOverride func(string) (string, string) |
| 261 | // acquireRefreshLock acquires the cross-process refresh lock and returns a function that releases it. It is nil in |
| 262 | // production, where withFreshConfigForRefresh falls back to a flock-backed implementation. Tests set it to a no-op |
| 263 | // so they never take a real filesystem lock. |
| 264 | acquireRefreshLock func(ctx context.Context, path string) (unlock func(), err error) |
| 265 | // reloadConfig re-reads the config from disk into the shared config. It is nil in production, where |
| 266 | // withFreshConfigForRefresh falls back to ghConfig.Reload. Tests set it to a no-op because their config is parsed |
| 267 | // from a string and a reload would discard it by reading the empty temp config dir. |
| 268 | reloadConfig func() error |
| 269 | // refreshMu serializes withFreshConfigForRefresh within this process. The cross-process flock guards against other |
| 270 | // gh processes but not against goroutines sharing this single AuthConfig instance, so this mutex provides the |
| 271 | // in-process half of the mutual exclusion that keeps a rotating refresh token from being spent twice. |
| 272 | refreshMu sync.Mutex |
| 273 | // warningsMu guards warnings. |
| 274 | warningsMu sync.Mutex |
| 275 | // warnings collects deduplicated messages, such as a skipped token refresh, for the user to see before gh exits. |
| 276 | warnings []string |
| 277 | // telemetry records token refresh attempts. It is nil until SetTelemetryRecorder is called, in which case nothing |
| 278 | // is recorded. |
| 279 | telemetry ghtelemetry.InvocationRecorder |
| 280 | // sleep pauses between the re-reads that follow a rejected refresh token. It is nil in production, where |
| 281 | // credentialRotatedByPeer falls back to time.Sleep. Tests set it to a no-op so a rejection does not slow them down. |
| 282 | sleep func(time.Duration) |
| 283 | // telemetryCommand is the command path reported with token refresh attempts. It is stored atomically because a |
| 284 | // background goroutine, such as the update check, may refresh a token while the command is still being resolved. |
| 285 | telemetryCommand atomic.Pointer[string] |
| 286 | } |
| 287 | |
| 288 | // Warnings returns the deduplicated warnings recorded so far in this process, such as a skipped token refresh, in the |
| 289 | // order they were first recorded. Callers are expected to show them to the user before gh exits. |
nothing calls this directly
no outgoing calls
no test coverage detected