store

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: MIT Imports: 2 Imported by: 8

README

Store

The store module is a strict interface for storing credentials and secrets. It is tightly coupled to the secrets engine and requires a valid secrets.ID.

Supported stores include:

  • Linux keychain (gnome-keyring and kdewallet)
  • macOS keychain
  • windows credential management API

Local Testing

You can run all tests using go test. For the keychain package the tests use the supported keychain of your host OS. Linux keychain tests can also be run inside Docker.

More information can be found at ./docs/test.md.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCredentialNotFound = secrets.ErrNotFound
View Source
var ParseID = secrets.ParseID

Functions

This section is empty.

Types

type ID

type ID = secrets.ID

type Secret

type Secret interface {
	// Marshal the secret into a slice of bytes
	Marshal() ([]byte, error)
	// Unmarshal the secret from a slice of bytes into its structured format
	Unmarshal(data []byte) error
}

Secret is a generic type that represents the actual secret values

The implementer is responsible for defining the data structure of their secrets.

Example:

type secret struct {
	AccessToken string
	RefreshToken string
}

func (s *secret) Marshal() ([]byte, error) {
	return []byte(s.AccessToken+":"+s.RefreshToken), nil
}

func (s *secret) Unmarshal(data []byte) error {
	tokens := bytes.Split(data, []byte(":"))
	if len(tokens) != 2 {
		return errors.New("invalid secret format")
	}

	s.AccessToken, s.RefreshToken = string(tokens[0]), string(tokens[1])
	return nil
}

type Store

type Store interface {
	// Delete removes credentials from the store for a given ID.
	Delete(ctx context.Context, id ID) error
	// Get retrieves credentials from the store for a given ID.
	Get(ctx context.Context, id ID) (Secret, error)
	// GetAll retrieves all the credentials from the store.
	GetAll(ctx context.Context) (map[ID]Secret, error)
	// Save persists credentials from the store.
	Save(ctx context.Context, id ID, secret Secret) error
}

Store defines a strict format for secrets to conform to when interacting with the secrets engine

Directories

Path Synopsis
The keychain package for Linux uses the org.freedesktop.secret service API over dbus.
The keychain package for Linux uses the org.freedesktop.secret service API over dbus.
cmd command

Jump to

Keyboard shortcuts

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