Skip to content
quarry Artifact [c73480413d]
Login

Artifact [c73480413d]

Artifact c73480413d80c9fbe87ce71b0bbaf4dbd0557b1b2537a70fbc0b70131248e3c5:


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) {
	return keyring.Get(ringService(host), account)
}

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
}