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 ¶
const ( // DefaultServiceName is the service name used in keyrings for storing Coder CLI session // tokens. DefaultServiceName = "coder-v2-credentials" )
Variables ¶
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.
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 ¶
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.