oauthtoken

package
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeyringMockInit added in v0.0.8

func KeyringMockInit()

KeyringMockInit initializes this package so that its methods may be called from a test without reading or writing external state.

func NewFakeTokenForSubject added in v0.0.11

func NewFakeTokenForSubject(subject string) *oauth2.Token

Types

type DebugPrint

type DebugPrint struct{}

func (*DebugPrint) Load

func (d *DebugPrint) Load(ctx context.Context, cluster string) (*oauth2.Token, error)

func (*DebugPrint) Store

func (d *DebugPrint) Store(ctx context.Context, cluster string, token *oauth2.Token) error

type FakeTokenStore added in v0.0.3

type FakeTokenStore struct {
	Tokens map[string]*oauth2.Token

	// Error values to be returned by Load, Store, and Delete, if not nil.
	LoadErr, StoreErr, DeleteErr error

	// Value to panic with in Load, Store, and Delete, if not nil.
	// Used to test that a method is NOT called.
	PanicValue any
}

FakeTokenStore is a test implementation of LoadStorer that stores tokens in memory instead of the system keychain.

func NewFakeTokenStore added in v0.0.3

func NewFakeTokenStore() *FakeTokenStore

func (*FakeTokenStore) Delete added in v0.0.3

func (f *FakeTokenStore) Delete(cluster string) error

func (*FakeTokenStore) Load added in v0.0.3

func (f *FakeTokenStore) Load(cluster string) (*oauth2.Token, error)

func (*FakeTokenStore) Store added in v0.0.3

func (f *FakeTokenStore) Store(cluster string, token *oauth2.Token) error

func (*FakeTokenStore) WithDeleteErr added in v0.0.5

func (f *FakeTokenStore) WithDeleteErr(err error) *FakeTokenStore

func (*FakeTokenStore) WithLoadErr added in v0.0.5

func (f *FakeTokenStore) WithLoadErr(err error) *FakeTokenStore

func (*FakeTokenStore) WithPanic added in v0.0.11

func (f *FakeTokenStore) WithPanic(value any) *FakeTokenStore

func (*FakeTokenStore) WithStoreErr added in v0.0.5

func (f *FakeTokenStore) WithStoreErr(err error) *FakeTokenStore

func (*FakeTokenStore) WithToken added in v0.0.5

func (f *FakeTokenStore) WithToken(cluster string, token *oauth2.Token) *FakeTokenStore

func (*FakeTokenStore) WithTokenForSubject added in v0.0.11

func (f *FakeTokenStore) WithTokenForSubject(cluster, subject string) *FakeTokenStore

type FileStore added in v0.0.5

type FileStore struct {
	// contains filtered or unexported fields
}

FileStore persists tokens in JSON files in a directory, one file per token. The tokens are stored unecrypted. This implementation may be used when Keyring cannot be used, for example, in a CI environment when there is no encrypted keyring.

func NewFileTokenStore added in v0.0.5

func NewFileTokenStore(dir string) (*FileStore, error)

func (*FileStore) Delete added in v0.0.5

func (f *FileStore) Delete(cluster string) error

func (*FileStore) Load added in v0.0.5

func (f *FileStore) Load(cluster string) (_ *oauth2.Token, err error)

func (*FileStore) Store added in v0.0.5

func (f *FileStore) Store(cluster string, token *oauth2.Token) (err error)

type Keyring

type Keyring struct {
	// contains filtered or unexported fields
}

Keyring stores a JWT token on the user's keyring via the OS-specific keyring mechanism of the current platform.

func (*Keyring) Delete added in v0.0.3

func (f *Keyring) Delete(cluster string) error

func (*Keyring) Load

func (f *Keyring) Load(cluster string) (*oauth2.Token, error)

func (*Keyring) Store

func (f *Keyring) Store(cluster string, token *oauth2.Token) error

type LoadStorer

type LoadStorer interface {
	// Load loads a token for a cluster, specified by hostname. It returns
	// fs.ErrNotFound if the token isn't present, or an unspecified non-nil
	// error for any other error conditions.
	Load(cluster string) (*oauth2.Token, error)

	// Store stores a token for a cluster, specified by hostname. It returns an
	// unspecified non-nil error if the operation fails; in this case, the state
	// of the token storage for the specified cluster is not specified (token
	// storage for other clusters is unaffected).
	Store(cluster string, token *oauth2.Token) error

	// Delete deletes a token for a cluster, specified by hostname. It returns
	// fs.ErrNotFound if there is currently no token stored for the specified
	// cluster, or an unspecified non-nil error for any other error conditions
	// (although the storage backend should make a best-effort attempt to delete
	// the token).
	Delete(string) error
}

LoadStorer provides access to a token via some backend implementation/policy.

func NewKeyring

func NewKeyring() (LoadStorer, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL