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.
| 250 | // with knowledge on how to access encrypted storage when neccesarry. |
| 251 | // Behavior is scoped to authentication specific tasks. |
| 252 | type AuthConfig struct { |
| 253 | cfg *ghConfig.Config |
| 254 | refresher gh.TokenRefresher |
| 255 | defaultHostOverride func() (string, string) |
| 256 | hostsOverride func() []string |
| 257 | tokenOverride func(string) (string, string) |
| 258 | // acquireRefreshLock acquires the cross-process refresh lock and returns a function that releases it. It is nil in |
| 259 | // production, where withFreshConfigForRefresh falls back to a flock-backed implementation. Tests set it to a no-op |
| 260 | // so they never take a real filesystem lock. |
| 261 | acquireRefreshLock func(ctx context.Context, path string) (unlock func(), err error) |
| 262 | // reloadConfig re-reads the config from disk into the shared config. It is nil in production, where |
| 263 | // withFreshConfigForRefresh falls back to ghConfig.Reload. Tests set it to a no-op because their config is parsed |
| 264 | // from a string and a reload would discard it by reading the empty temp config dir. |
| 265 | reloadConfig func() error |
| 266 | // refreshMu serializes withFreshConfigForRefresh within this process. The cross-process flock guards against other |
| 267 | // gh processes but not against goroutines sharing this single AuthConfig instance, so this mutex provides the |
| 268 | // in-process half of the mutual exclusion that keeps a rotating refresh token from being spent twice. |
| 269 | refreshMu sync.Mutex |
| 270 | // warningsMu guards warnings. |
| 271 | warningsMu sync.Mutex |
| 272 | // warnings collects deduplicated messages, such as a skipped token refresh, for the user to see before gh exits. |
| 273 | warnings []string |
| 274 | } |
| 275 | |
| 276 | // Warnings returns the deduplicated warnings recorded so far in this process, such as a skipped token refresh, in the |
| 277 | // 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