Thanks to visit codestin.com
Credit goes to pkg.go.dev

sessionstore

package
v2.29.4 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package sessionstore provides CLI session token storage mechanisms. Operating system keyring storage is intended to have compatibility with other Coder applications (e.g. Coder Desktop, Coder provider for JetBrains Toolbox, etc) so that applications can read/write the same credential stored in the keyring.

Note that we aren't using an existing Go package zalando/go-keyring here for a few reasons. 1) It prescribes the format of the target credential name in the OS keyrings, which makes our life difficult for compatibility with other Coder applications. 2) It uses init functions that make it difficult to test with. As a result, the OS keyring implementations may be adapted from zalando/go-keyring source (i.e. Windows).

Index

Constants

View Source
const (
	// DefaultServiceName is the service name used in keyrings for storing Coder CLI session
	// tokens.
	DefaultServiceName = "coder-v2-credentials"
)

Variables

View Source
var (

	// ErrSetDataTooBig is returned if `keyringProvider.Set` was called with too much data.
	// On macOS: The combination of service, username & password should not exceed ~3000 bytes
	// On Windows: The service is limited to 32KiB while the password is limited to 2560 bytes
	ErrSetDataTooBig = xerrors.New("data passed to Set was too big")

	// ErrNotImplemented represents when keyring usage is not implemented on the current
	// operating system.
	ErrNotImplemented = xerrors.New("not implemented")
)

Functions

This section is empty.

Types

type Backend

type Backend interface {
	// Read returns the session token for the given server URL or an error, if any. It
	// will return os.ErrNotExist if no token exists for the given URL.
	Read(serverURL *url.URL) (string, error)
	// Write stores the session token for the given server URL.
	Write(serverURL *url.URL, token string) error
	// Delete removes the session token for the given server URL or an error, if any.
	// It will return os.ErrNotExist error if no token exists to delete.
	Delete(serverURL *url.URL) error
}

Backend is a storage backend for session tokens.

type File

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

File is a Backend that exclusively stores the session token in a file on disk.

func NewFile

func NewFile(f func() config.Root) *File

func (*File) Delete

func (f *File) Delete(_ *url.URL) error

func (*File) Read

func (f *File) Read(_ *url.URL) (string, error)

func (*File) Write

func (f *File) Write(_ *url.URL, token string) error

type Keyring

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

Keyring is a Backend that exclusively stores the session token in the operating system keyring. Happy path usage of this type should start with NewKeyring. It stores a JSON object in the keyring that supports multiple credentials for different server URLs, providing compatibility with Coder Desktop and other Coder applications.

func NewKeyringWithService

func NewKeyringWithService(serviceName string) Keyring

NewKeyringWithService creates a Keyring Backend that stores credentials under the specified service name. Generally, DefaultServiceName should be provided as the service name except in tests which may need parameterization to avoid conflicting keyring use.

func (Keyring) Delete

func (o Keyring) Delete(serverURL *url.URL) error

func (Keyring) Read

func (o Keyring) Read(serverURL *url.URL) (string, error)

func (Keyring) Write

func (o Keyring) Write(serverURL *url.URL, token string) error

Jump to

Keyboard shortcuts

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