secrets

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package secrets keeps device tokens out of the database and the vault (ADR-0016, docs/specs/sync-protocol.md): the Secret Service over D-Bus, and a plain File for development and CI. Ported from frostmail's internal/secrets (frostmail ADR-0011).

Index

Constants

View Source
const ProbeKey = "probe"

ProbeKey is the key a pairing writes and deletes first: a store that cannot keep it cannot keep a device token either, and the store's prompt then comes before the hub knows the device.

Variables

View Source
var ErrDismissed = errors.New("secrets: the Secret Service's prompt was dismissed")

ErrDismissed means the user dismissed one of the service's prompts: to unlock a collection, or to make the default one.

View Source
var ErrNoKeyring = errors.New("secrets: no keyring can keep the token")

ErrNoKeyring means no keyring can keep a token: no Secret Service answers, or the service cannot make a default collection.

View Source
var ErrNotFound = errors.New("secrets: not found")

ErrNotFound means no secret is stored under the key.

View Source
var ErrUnavailable = errors.New("secrets: no Secret Service")

ErrUnavailable means no Secret Service answered on the bus.

Functions

func HubToken

func HubToken(hubID string) string

HubToken is the key of the device token for the hub with ID hubID.

Types

type File

type File struct {
	// contains filtered or unexported fields
}

File is a Store kept in one JSON object ({"key": "value", ...}) in a file with mode 0600: plain text on disk, guarded only by file permissions, for development, CI and machines without a Secret Service.

func NewFile

func NewFile(path string) *File

NewFile returns a File store at path. The file is created on first Set; its directory must exist.

func (*File) All

func (f *File) All() (map[string]string, error)

All returns every stored secret (for moving them to another store).

func (*File) Delete

func (f *File) Delete(ctx context.Context, key string) error

Delete removes key, rewriting the file atomically like Set. A missing key or a missing file is not an error.

func (*File) Get

func (f *File) Get(ctx context.Context, key string) (string, error)

Get returns the secret stored under key, or ErrNotFound. A missing file holds no secrets. A file whose mode allows group or other access is refused with an error naming the file and its mode.

func (*File) Remove

func (f *File) Remove() error

Remove deletes the file; a missing file is not an error.

func (*File) Set

func (f *File) Set(ctx context.Context, key, value string) error

Set stores value under key. It rewrites the whole file atomically: write a temporary file in the same directory with mode 0600, then rename it over the old file.

type Options added in v0.7.1

type Options struct {
	// NoFallback makes Open keep no plain file: its store fails every Get, Set and Delete with an error that wraps ErrNoKeyring.
	NoFallback bool
	// Hint ends the message of ErrNoKeyring errors: how the user keeps tokens in a file instead.
	Hint string
}

Options say what Open does when FROSTNOTES_SECRETS is unset and no Secret Service answers.

func FlatpakOptions added in v0.7.1

func FlatpakOptions() Options

FlatpakOptions keep no plain file unless the user explicitly opts in.

func HostOptions added in v0.7.1

func HostOptions() Options

HostOptions allow a plain file when no Secret Service answers on the host.

func OptionsFor added in v0.7.1

func OptionsFor(inFlatpak bool) Options

OptionsFor select the secret-store policy for notesd's environment.

type SecretService

type SecretService struct {
	// contains filtered or unexported fields
}

SecretService is a Store in the desktop's Secret Service.

func OpenSecretService

func OpenSecretService(ctx context.Context, conn *dbus.Conn) (*SecretService, error)

OpenSecretService opens a plain session with the Secret Service on conn, or returns an error wrapping ErrUnavailable.

func (*SecretService) Delete

func (s *SecretService) Delete(ctx context.Context, key string) error

Delete removes key; a missing key is not an error.

func (*SecretService) Get

func (s *SecretService) Get(ctx context.Context, key string) (string, error)

Get returns the secret stored under key, or ErrNotFound.

func (*SecretService) Set

func (s *SecretService) Set(ctx context.Context, key, value string) error

Set stores value under key, replacing any previous item.

type Store

type Store interface {
	// Get returns the secret, or ErrNotFound.
	Get(ctx context.Context, key string) (string, error)
	// Set stores the secret, replacing any previous value.
	Set(ctx context.Context, key, value string) error
	// Delete removes the secret; a missing key is not an error.
	Delete(ctx context.Context, key string) error
}

Store keeps string secrets by key.

func Open

func Open(ctx context.Context, file string, log *slog.Logger, opts Options) (Store, error)

Open picks notesd's secret store: the Secret Service on the session bus, unless FROSTNOTES_SECRETS=file explicitly picks the file store. When no service answers, opts.NoFallback refuses secret operations; otherwise Open uses the file store with a warning. With the Secret Service, secrets still in the file are moved over and the file is removed.

Jump to

Keyboard shortcuts

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