Documentation ¶
Overview ¶
Package keyring provides a uniform API over a range of desktop credential storage engines
See project homepage at https://github.com/99designs/keyring for more background
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Whether to print debugging output Debug bool )
var ErrKeyNotFound = errors.New("The specified item could not be found in the keyring.")
ErrKeyNotFound is returned by Keyring Get when the item is not on the keyring
var ErrNoAvailImpl = errors.New("Specified keyring backend not available")
ErrNoAvailImpl is returned by Open when a backend cannot be found
Functions ¶
func Open ¶
func Open(cfg Config) (Keyring, BackendType, error)
Open will open a specific keyring backend
Example ¶
package main import ( "log" "github.com/fluidkeys/keyring" ) func main() { // Use the best keyring implementation for your operating system kr, err := keyring.Open(keyring.Config{ ServiceName: "my-service", }) v, err := kr.Get("llamas") if err != nil { log.Fatal(err) } log.Printf("llamas was %v", v) }
Output:
Types ¶
type ArrayKeyring ¶
type ArrayKeyring struct {
// contains filtered or unexported fields
}
ArrayKeyring is a mock/non-secure backend that meets the Keyring interface. It is intended to be used to aid unit testing of code that relies on the package. NOTE: Do not use in production code
func NewArrayKeyring ¶
func NewArrayKeyring(initial []Item) *ArrayKeyring
NewArrayKeyring returns an ArrayKeyring, optionally constructed with an initial slice of items
func (*ArrayKeyring) Get ¶
func (k *ArrayKeyring) Get(key string) (Item, error)
Get returns an Item matching Key
func (*ArrayKeyring) Keys ¶
func (k *ArrayKeyring) Keys() ([]string, error)
Keys provides a slice of all Item keys on the Keyring
func (*ArrayKeyring) Remove ¶
func (k *ArrayKeyring) Remove(key string) error
Remove will delete an Item from the Keyring
func (*ArrayKeyring) Set ¶
func (k *ArrayKeyring) Set(i Item) error
Set will store an item on the mock Keyring
type BackendType ¶
type BackendType string
const ( InvalidBackend BackendType = "invalid" SecretServiceBackend BackendType = "secret-service" KeychainBackend BackendType = "keychain" )
All currently supported secure storage backends
func AvailableBackends ¶
func AvailableBackends() []BackendType
AvailableBackends provides a slice of all available backend keys on the current OS
type Config ¶
type Config struct { // AllowedBackends is a whitelist of backend providers that can be used. Nil means all available. AllowedBackends []BackendType // ServiceName is a generic service name that is used by backends that support the concept ServiceName string // MacOSKeychainNameKeychainName is the name of the macOS keychain that is used KeychainName string // KeychainTrustApplication is whether the calling application should be trusted by default by items KeychainTrustApplication bool // KeychainSynchronizable is whether the item can be synchronized to iCloud KeychainSynchronizable bool // KeychainAccessibleWhenUnlocked is whether the item is accessible when the device is locked KeychainAccessibleWhenUnlocked bool // KeychainPasswordFunc is an optional function used to prompt the user for a password KeychainPasswordFunc PromptFunc // FilePasswordFunc is a required function used to prompt the user for a password FilePasswordFunc PromptFunc // FileDir is the directory that keyring files are stored in, ~ is resolved to home dir FileDir string // KWalletAppID is the application id for KWallet KWalletAppID string // KWalletFolder is the folder for KWallet KWalletFolder string // LibSecretCollectionName is the name collection in secret-service LibSecretCollectionName string }
type Item ¶
type Item struct { Key string Data []byte Label string Description string // Backend specific config KeychainNotTrustApplication bool KeychainNotSynchronizable bool }
Item is a thing stored on the keyring
type Keyring ¶
type Keyring interface { // Returns an Item matching the key or ErrKeyNotFound Get(key string) (Item, error) // Stores an Item on the keyring Set(item Item) error // Removes the item with matching key Remove(key string) error // Provides a slice of all keys stored on the keyring Keys() ([]string, error) }
Keyring provides the uniform interface over the underlying backends