Skip to content
quarry Artifact [3fb3c6b9ed]
Login

Artifact [3fb3c6b9ed]

Artifact 3fb3c6b9edf82102a77caa3dc93440f312323ee0dbaeff1036717d3c64ce00bb:


package pickupclient

import (
	"errors"

	"github.com/zalando/go-keyring"
)

// ringKeychain is the Secret Service on Linux (over D-Bus) and the
// Credential Manager on Windows, through go-keyring: pure Go, no cgo. One
// item per host and account, service "quarry:HOST".
//
// Where there is no service to ask (a headless box with no D-Bus session)
// every call fails, so the store keeps the token in its private file.
type ringKeychain struct{}

func ringService(host string) string { return "quarry:" + host }

func (ringKeychain) Put(host, account, value string) error {
	return keyring.Set(ringService(host), account, value)
}

func (ringKeychain) Get(host, account string) (string, error) {
	v, err := keyring.Get(ringService(host), account)
	if errors.Is(err, keyring.ErrNotFound) {
		err = errNoItem
	}
	return v, err
}

func (ringKeychain) Delete(host, account string) error {
	if err := keyring.Delete(ringService(host), account); err != nil && !errors.Is(err, keyring.ErrNotFound) {
		return err
	}
	return nil
}