func SetCurrentToken(name string, cs ConfigStore, ss SecretStore) error {
	if _, err := GetToken(name, ss); err != nil {
		return err
	}
	cfg, err := cs.Get()
	if err != nil {
		if errors.Is(err, ErrConfigNotFound) {
			cfg = Config{Version: "v1"}
		} else {
			return err
		}
	}
	cfg.CurrentToken = name
	return cs.Put(cfg)
}
SetCurrentToken is a convenient way to set the CurrentToken field in a
the current config.
package storage
import (
	"encoding/json"
	"errors"
	"os"
	"path/filepath"
	"github.com/jzelinskie/stringz"
	"tailscale.com/atomicfile"
)
const configFileName = "config.json"
var ErrConfigNotFound = errors.New("config did not exist")
type Config struct {
	Version      string
	CurrentToken string
}
type ConfigStore interface {
	Get() (Config, error)
	Put(Config) error
}
var ErrMissingToken = errors.New("could not find token")
func DefaultToken(overrideEndpoint, overrideApiToken string, cs ConfigStore, ss SecretStore) (Token, error) {
	if overrideEndpoint != "" && overrideApiToken != "" {
		return Token{
			Name:     "env",
			Endpoint: overrideEndpoint,
			ApiToken: overrideApiToken,
		}, nil
	}
	token, err := CurrentToken(cs, ss)
	if err != nil {
		if errors.Is(err, ErrConfigNotFound) {
			return Token{}, errors.New("must first save a token: see `zed token save --help`")
		}
		return Token{}, err
	}
	return Token{
		Name:     token.Name,
		Endpoint: stringz.DefaultEmpty(overrideEndpoint, token.Endpoint),
		ApiToken: stringz.DefaultEmpty(overrideApiToken, token.ApiToken),
	}, nil
}
func CurrentToken(cs ConfigStore, ss SecretStore) (Token, error) {
	cfg, err := cs.Get()
	if err != nil {
		return Token{}, err
	}
	return GetToken(cfg.CurrentToken, ss)
}