Documentation
¶
Overview ¶
Package token manages the on-disk cache of Chainguard OIDC access and refresh tokens, organized by audience and optional alias.
Index ¶
- Variables
- func Delete(kind Kind, audience string, opts ...Option) error
- func DeleteAll() error
- func ListAudiences() ([]string, error)
- func Load(kind Kind, audience string, opts ...Option) ([]byte, error)
- func Path(kind Kind, audience string, opts ...Option) (string, error)
- func RemainingLife(kind Kind, audience string, less time.Duration, opts ...Option) time.Duration
- func Save(token []byte, kind Kind, audience string, opts ...Option) error
- type Kind
- type Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var (
AllKinds = []Kind{KindAccess, KindRefresh}
)
Functions ¶
func Delete ¶
Delete removes the token for the given audience, if it exists. No error is returned if the token doesn't exist.
func DeleteAll ¶
func DeleteAll() error
DeleteAll removes all Chainguard tokens and empty audience directories.
func ListAudiences ¶ added in v0.1.164
ListAudiences returns the set of audiences for which an access token (KindAccess) currently exists in the local token cache.
Audiences are recovered from each token's "aud" claim rather than from the on-disk directory name, since the directory name is a lossy encoding of the audience (e.g. "/" is replaced with "-"). The returned slice is sorted and de-duplicated. Files that cannot be read or parsed as tokens are skipped.
func RemainingLife ¶
RemainingLife returns the amount of time remaining before the token for the given audience expires. Returns 0 for expired and non-existent tokens.
Types ¶
type Option ¶ added in v0.1.44
type Option func(*token)
func WithAlias ¶ added in v0.1.44
WithAlias allows callers to organize tokens into subdirectories under an audience to manage multiple tokens for the same audience without overwriting.
Example ¶
ExampleWithAlias demonstrates creating an Option that sets a token alias.
package main
import (
"fmt"
"chainguard.dev/sdk/auth/token"
)
func main() {
opt := token.WithAlias("my-alias")
fmt.Println(opt != nil)
}
Output: true