Documentation
¶
Overview ¶
Package cache persists tokens on disk, keyed by (issuer, client_id), with 0600/0700 permissions, atomic writes, and advisory file locking for concurrency-safe refresh.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrLockTimeout = errors.New("cache: timed out waiting for the profile lock")
ErrLockTimeout is returned when WithLock could not acquire the profile lock within lockAcquireTimeout, or the caller's ctx was done first.
Functions ¶
Types ¶
type Cache ¶
type Cache struct {
Dir string
}
Cache is a directory of per-profile JSON token files.
func New ¶
New returns a Cache rooted at dir. The directory is created lazily on first write, with 0700 permissions.
func (*Cache) Load ¶
Load reads the cache entry for (issuer, clientID). An absent or unparseable file is reported as ok==false, err==nil (re-authenticate); other I/O errors (e.g. permission denied) return a non-nil error.
func (*Cache) Path ¶
Path returns the on-disk file path for the given (issuer, clientID) profile. Exposed for tests that need to manipulate the cache file directly (e.g. simulating corruption).
func (*Cache) Save ¶
Save atomically writes entry to its cache file: dir 0700, file 0600, write-to-temp-then-rename in the same directory so a crash never leaves a partially written cache file.
type Entry ¶
type Entry struct {
Issuer string `json:"issuer"`
ClientID string `json:"client_id"`
AccessToken string `json:"access_token,omitempty"`
IDToken string `json:"id_token,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
Expiry time.Time `json:"expiry"`
}
Entry is the on-disk cache record for a single (issuer, client_id) profile.