api

package
v1.15.4 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2023 License: MIT Imports: 9 Imported by: 12

Documentation

Overview

Example
package main

import (
	"context"
	"fmt"

	"github.com/gopasspw/gopass/pkg/gopass/api"
	"github.com/gopasspw/gopass/pkg/gopass/secrets"
)

func main() { //nolint:testableexamples
	ctx := context.Background()

	gp, err := api.New(ctx)
	if err != nil {
		panic(err)
	}

	// Listing secrets
	ls, err := gp.List(ctx)
	if err != nil {
		panic(err)
	}

	for _, s := range ls {
		fmt.Printf("Secret: %s", s)
	}

	// Writing secrets
	sec := secrets.New()
	sec.SetPassword("foobar")
	if err := gp.Set(ctx, "my/new/secret", sec); err != nil {
		panic(err)
	}

	// Reading secrets
	sec, err = gp.Get(ctx, "my/new/secret", "latest")
	if err != nil {
		panic(err)
	}
	fmt.Printf("content of %s: %s\n", "my/new/secret", string(sec.Bytes()))

	// Removing a secret
	if err := gp.Remove(ctx, "my/new/secret"); err != nil {
		panic(err)
	}

	// Cleaning up
	if err := gp.Close(ctx); err != nil {
		panic(err)
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = fmt.Errorf("not yet implemented")

ErrNotImplemented is returned when a method is not implemented.

View Source
var ErrNotInitialized = fmt.Errorf("password store not initialized. run 'gopass setup' first")

ErrNotInitialized is returned when the store is not initialized.

Functions

func ConfigDir

func ConfigDir() string

ConfigDir returns gopass' configuration directory.

Types

type Gopass

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

Gopass is a secret store implementation.

func New

func New(ctx context.Context) (*Gopass, error)

New initializes an existing password store. It will attempt to load an existing configuration or use the built-in defaults. If no password store is found and the user will need to initialize it with the gopass CLI (`gopass setup`) first.

WARNING: This will need to change to accommodate for runtime configuration.

func (*Gopass) Close

func (g *Gopass) Close(ctx context.Context) error

Close shuts down all background processes.

MUST be called before existing to make sure any background processing (e.g. pending commits or pushes) are complete. Failing to do so might result in an invalid password store state.

func (*Gopass) Get

func (g *Gopass) Get(ctx context.Context, name, revision string) (gopass.Secret, error)

Get returns a single, encrypted secret. It must be unwrapped before use. Use "latest" to get the latest revision.

func (*Gopass) List

func (g *Gopass) List(ctx context.Context) ([]string, error)

List returns a list of all secrets.

func (*Gopass) Remove

func (g *Gopass) Remove(ctx context.Context, name string) error

Remove removes a single secret.

func (*Gopass) RemoveAll

func (g *Gopass) RemoveAll(ctx context.Context, prefix string) error

RemoveAll removes all secrets with a given prefix.

func (*Gopass) Rename

func (g *Gopass) Rename(ctx context.Context, src, dest string) error

Rename move a prefix to another.

func (*Gopass) Revisions

func (g *Gopass) Revisions(ctx context.Context, name string) ([]string, error)

Revisions lists all revisions of this secret.

func (*Gopass) Set

func (g *Gopass) Set(ctx context.Context, name string, sec gopass.Byter) error

Set adds a new revision to an existing secret or creates a new one. Create new secrets with secrets.New().

func (*Gopass) String

func (g *Gopass) String() string

func (*Gopass) Sync

func (g *Gopass) Sync(ctx context.Context) error

Sync synchronizes a secret with a remote.

Jump to

Keyboard shortcuts

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