storage

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultConfigStore is the ConfigStore that should be used unless otherwise
	// specified.
	DefaultConfigStore = HomeJSONConfigStore{}

	// ErrConfigNotFound is returned if there is no Config in a ConfigStore.
	ErrConfigNotFound = errors.New("config did not exist")
)
View Source
var (
	// DefaultTokenStore is the TokenStore that should be used unless otherwise
	// specified.
	DefaultTokenStore = KeychainTokenStore{}

	// ErrTokenNotFound is returned if there is no Config in a ConfigStore.
	ErrTokenNotFound = errors.New("token does not exist")

	// ErrMultipleTokens is returned if there are multiple tokens with the same
	// name.
	ErrMultipleTokens = errors.New("multiple tokens with the same name")
)

Functions

func SetCurrentToken

func SetCurrentToken(name string, cs ConfigStore, ts TokenStore) error

SetCurrentToken is a convenient way to set the CurrentToken field in a the current config.

Types

type Config

type Config struct {
	Version      string
	CurrentToken string
}

Config represents the contents of a zed configuration file.

type ConfigStore

type ConfigStore interface {
	Get() (Config, error)
	Put(Config) error
}

ConfigStore is anything that can persistently store a Config.

type HomeJSONConfigStore

type HomeJSONConfigStore struct{}

HomeJSONConfigStore implements a ConfigStore that stores its Config in the file "${XDG_CONFIG_HOME:-$HOME/.zed}/config.json".

func (HomeJSONConfigStore) Get

func (s HomeJSONConfigStore) Get() (Config, error)

Get parses a Config from the filesystem.

func (HomeJSONConfigStore) Put

func (s HomeJSONConfigStore) Put(cfg Config) error

Put overwrites a Config on the filesystem.

type KeychainTokenStore

type KeychainTokenStore struct{}

KeychainTokenStore implements TokenStore by using the OS keychain service, falling back to an encrypted JWT on disk if the OS has no keychain.

func (KeychainTokenStore) Delete

func (ks KeychainTokenStore) Delete(system string) error

Delete removes a Token from the keychain.

func (KeychainTokenStore) Get

func (ks KeychainTokenStore) Get(system string) (Token, error)

Get fetches a Token from the keychain.

func (KeychainTokenStore) List

func (ks KeychainTokenStore) List(revealTokens bool) ([]Token, error)

List returns all of the tokens in the keychain.

If revealTokens is true, the Token.Secrets field will contain the secret.

func (KeychainTokenStore) Put

func (ks KeychainTokenStore) Put(system, endpoint, secret string) error

Put overwrites a Token in the keychain.

type Token

type Token struct {
	System   string
	Endpoint string
	Prefix   string
	Secret   string
}

Token represents an API Token and all of its metadata.

func CurrentToken

func CurrentToken(cs ConfigStore, ts TokenStore) (Token, error)

CurrentToken is convenient way to obtain the CurrentToken field from the current Config.

func DefaultToken

func DefaultToken(psystem, endpoint, tokenStr string) (Token, error)

DefaultToken creates a Token from input, filling any missing values in with the current context's defaults.

type TokenStore

type TokenStore interface {
	List(revealTokens bool) ([]Token, error)
	Get(system string) (Token, error)
	Put(system, endpoint, secret string) error
	Delete(system string) error
}

TokenStore is anything that can securely persist Tokens.

Jump to

Keyboard shortcuts

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