secrets

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("secret not found") // error returned by a secrets.Keeper when a secret is not found
)
View Source
var ErrSkipLocation = errors.New("skip location")

ErrSkipLocation may be returned by a ForEach iterator function to skip the rest of the secrets in a location.

Functions

func ForEach

func ForEach(
	ctx context.Context,
	kpr Keeper,
	run func(Secret) error,
) error

ForEach runs the given function for each secret in the keeper.

func ForEachInLocation

func ForEachInLocation(
	ctx context.Context,
	kpr Keeper,
	location string,
	run func(Secret) error,
) error

ForEachInLocation runs the given function for each secret in the named location.

func UrlString

func UrlString(sec Secret) string

UrlString is a helper that returns the string for a URL. If the URL is set, it returns the value returned by calling the String method on it. If not, it returns an empty string.

Types

type Keeper

type Keeper interface {
	// ListLocations returns the names of every storage location.
	ListLocations(ctx context.Context) ([]string, error)

	// ListSecrets returns the name of the secrets stored at the given location.
	ListSecrets(ctx context.Context, location string) ([]string, error)

	// GetSecretsByName returns all secrets stored with that name. This should
	// not return the ErrNotFound error if no secret with the given name is
	// found.
	GetSecretsByName(ctx context.Context, name string) ([]Secret, error)

	// GetSecret returns a secret by unique ID, which is Keeper dependant. If no
	// secret is found for the given ID, this function should returned a nil
	// Secret with ErrNotFound.
	GetSecret(ctx context.Context, id string) (Secret, error)

	// SetSecret performs an insertion or update of the secret. If the secret
	// has a valid ID that matches a record in Keeper storage, it will update
	// that secret in the store. If the ID is not valid or not found in Keeper
	// storage, a new value will be inserted.
	//
	// In either case, a new Secret object will be returned. The old value
	// should now be considered invalid.
	SetSecret(ctx context.Context, secret Secret) (Secret, error)

	// CopySecret copies the identified secret to a new location while keeping
	// the secret in the existing location as well. A new secret representing
	// the new copy is returned. This should return ErrNotFound if the secret
	// is not found.
	CopySecret(ctx context.Context, id string, location string) (Secret, error)

	// MoveSecret moves a secret to a new location. The passed in ID is The
	// moved secret object is returned. This should return ErrNotFound if the
	// secret is not found.
	MoveSecret(ctx context.Context, id string, location string) (Secret, error)

	// DeleteSecret removes the secret. This should not return ErrNotFound even
	// if the secret was not found.
	DeleteSecret(ctx context.Context, id string) error
}

Keeper is a tool for storing and retrieving secrets. Locations are treated as flat opaque refs as far as this API is concerned, however, individual Keepers may provide multi-level hierarchies of locations.

This assumes a given secret is only found in a single location. The ID field must be unique throughout the storage and must be assigned whenever a Secret is returned by one of these methods. The Name field is not guaranteed to be unique. If the Location field is unset, this indicates the secret is to be stored in the default location. The Fields lists all those fields that do not have their own accessor.

Even if a Keeper storage uses one list of properties to store all, the fields with their own accessor should not be returned by Fields or GetField.

type Secret

type Secret interface {
	// ID returns the unique ID of the secret.
	ID() string

	// Name returns the name of the secret.
	Name() string

	// Username returns the username for the secret.
	Username() string

	// Password returns the secret value.
	Password() string

	// Type returns the type of the secret.
	Type() string

	// Fields returns the fields for the secret.
	Fields() map[string]string

	// GetField returns the value of the named field.
	GetField(string) string

	// LastModified returns the last modified time for the secret.
	LastModified() time.Time

	// Url returns the URL for the secret.
	Url() *url.URL

	// Location returns the location for the secret.
	Location() string
}

Secret is the interface for a secret.

func RemoveField

func RemoveField(secret Secret, name string) Secret

func SetField

func SetField(secret Secret, name, value string) Secret

func SetLastModified

func SetLastModified(secret Secret, lastModified time.Time) Secret

func SetName

func SetName(secret Secret, name string) Secret

func SetPassword

func SetPassword(secret Secret, secretValue string) Secret

func SetType

func SetType(secret Secret, typ string) Secret

func SetUrl

func SetUrl(secret Secret, url *url.URL) Secret

func SetUsername

func SetUsername(secret Secret, username string) Secret

type SettableFields

type SettableFields interface {
	SetField(string, string)
	DeleteField(string)
}

SettableFields is the interface for a secret that can have its fields set.

type SettableLastModified

type SettableLastModified interface {
	// SetLastModified sets the last modified time for the secret.
	SetLastModified(time.Time)
}

SettableLastModified is the interface for a secret that can have its last modified time set.

type SettableName

type SettableName interface {
	// SetName sets the name of the secret.
	SetName(string)
}

SettableName is the interface for a secret that can have its name set.

type SettablePassword

type SettablePassword interface {
	// SetPassword sets the secret value.
	SetPassword(string)
}

SettablePassword is the interface for a secret that can have its password value set.

type SettableType

type SettableType interface {
	// SetType sets the type of the secret.
	SetType(string)
}

SettableType is the interface for a secret that can have its type set.

type SettableUrl

type SettableUrl interface {
	// SetUrl sets the URL for the secret.
	SetUrl(*url.URL)
}

SettableUrl is the interface for a secret that can have its URL set.

type SettableUsername

type SettableUsername interface {
	// SetUsername sets the username for the secret.
	SetUsername(string)
}

SettableUsername is the interface for a secret that can have its username set.

type Single

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

Single represents a single secret stored in a Keeper.

func NewSecret

func NewSecret(name, username, password string, opts ...SingleOption) *Single

NewSecret creates a secret from the given settings.

func NewSingleFromSecret

func NewSingleFromSecret(s Secret, opts ...SingleOption) *Single

NewSecretFromSecret creates a *Single from the given secret with the requested modifications applied.

func (*Single) DeleteField

func (s *Single) DeleteField(name string)

DeleteField sets the value of the named field. This works safely whether Field is initialized or not.

func (*Single) Fields

func (s *Single) Fields() map[string]string

Fields returns the fields of the secret.

func (*Single) GetField

func (s *Single) GetField(name string) string

GetField returns the value of the named field. This works safely whether Field has been initialized or not.

func (*Single) ID

func (s *Single) ID() string

ID returns the unique identifier for the secret.

func (*Single) LastModified

func (s *Single) LastModified() time.Time

LastModified returns the last modified time of the secret.

func (*Single) Location

func (s *Single) Location() string

Location returns the location of the secret.

func (*Single) Name

func (s *Single) Name() string

Name returns the name of the secret.

func (*Single) Password

func (s *Single) Password() string

Single returns the secret of the secret.

func (*Single) SetField

func (s *Single) SetField(name, value string)

SetField sets the value of the named field. This works safely whether Field is initialized or not.

func (*Single) SetLastModified

func (s *Single) SetLastModified(lastModified time.Time)

SetLastModified sets the last modified time of the secret.

func (*Single) SetLocation

func (s *Single) SetLocation(location string)

SetLocation sets the location of the secret.

func (*Single) SetName

func (s *Single) SetName(name string)

SetName sets the name of the secret.

func (*Single) SetPassword

func (s *Single) SetPassword(password string)

SetSecret sets the secret of the secret.

func (*Single) SetType

func (s *Single) SetType(typ string)

SetType sets the type of the secret.

func (*Single) SetUrl

func (s *Single) SetUrl(url *url.URL)

SetUrl sets the URL of the secret.

func (*Single) SetUsername

func (s *Single) SetUsername(username string)

SetUsername sets the username of the secret.

func (*Single) Type

func (s *Single) Type() string

Type returns the type of the secret.

func (*Single) Url

func (s *Single) Url() *url.URL

Url returns the URL of the secret.

func (*Single) Username

func (s *Single) Username() string

Username returns the username of the secret.

type SingleOption

type SingleOption interface {
	// contains filtered or unexported methods
}

SingleOption is used to customize a secret during construction.

func WithField

func WithField(name, value string) SingleOption

WithField sets a field on the secret.

func WithFields

func WithFields(fields map[string]string) SingleOption

WithFields sets the given fields on the secret.

func WithID

func WithID(id string) SingleOption

WithID sets the ID of the secret, which is useful when copying a secret using NewSingleFromSecret or when initializing a secret with a known ID using NewSecret.

func WithLastModified

func WithLastModified(t time.Time) SingleOption

WithLastModified sets the last modified time for the secret.

func WithLocation

func WithLocation(l string) SingleOption

WithLocation sets the location for the secret.

func WithName

func WithName(name string) SingleOption

WithName sets the name of the secret for use when copying a secret using NewSingleFromSecret.

func WithPassword

func WithPassword(secret string) SingleOption

WithPassword sets the password of the secret for use when copying a secret using NewSingleFromSecret.

func WithType

func WithType(typ string) SingleOption

WithType sets the type of the secret.

func WithUrl

func WithUrl(u *url.URL) SingleOption

WithUrl sets the URL for the secret.

func WithUsername

func WithUsername(username string) SingleOption

WithUsername sets the username of the secret for use when copying a secret using NewSingleFromSecret.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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