Documentation ¶
Index ¶
- Variables
- func ForEach(ctx context.Context, kpr Keeper, run func(Secret) error) error
- func ForEachInLocation(ctx context.Context, kpr Keeper, location string, run func(Secret) error) error
- func UrlString(sec Secret) string
- type Keeper
- type Secret
- func RemoveField(secret Secret, name string) Secret
- func SetField(secret Secret, name, value string) Secret
- func SetLastModified(secret Secret, lastModified time.Time) Secret
- func SetName(secret Secret, name string) Secret
- func SetPassword(secret Secret, secretValue string) Secret
- func SetType(secret Secret, typ string) Secret
- func SetUrl(secret Secret, url *url.URL) Secret
- func SetUsername(secret Secret, username string) Secret
- type SettableFields
- type SettableLastModified
- type SettableName
- type SettablePassword
- type SettableType
- type SettableUrl
- type SettableUsername
- type Single
- func (s *Single) DeleteField(name string)
- func (s *Single) Fields() map[string]string
- func (s *Single) GetField(name string) string
- func (s *Single) ID() string
- func (s *Single) LastModified() time.Time
- func (s *Single) Location() string
- func (s *Single) Name() string
- func (s *Single) Password() string
- func (s *Single) SetField(name, value string)
- func (s *Single) SetLastModified(lastModified time.Time)
- func (s *Single) SetLocation(location string)
- func (s *Single) SetName(name string)
- func (s *Single) SetPassword(password string)
- func (s *Single) SetType(typ string)
- func (s *Single) SetUrl(url *url.URL)
- func (s *Single) SetUsername(username string)
- func (s *Single) Type() string
- func (s *Single) Url() *url.URL
- func (s *Single) Username() string
- type SingleOption
- func WithField(name, value string) SingleOption
- func WithFields(fields map[string]string) SingleOption
- func WithID(id string) SingleOption
- func WithLastModified(t time.Time) SingleOption
- func WithLocation(l string) SingleOption
- func WithName(name string) SingleOption
- func WithPassword(secret string) SingleOption
- func WithType(typ string) SingleOption
- func WithUrl(u *url.URL) SingleOption
- func WithUsername(username string) SingleOption
Constants ¶
This section is empty.
Variables ¶
var (
ErrNotFound = errors.New("secret not found") // error returned by a secrets.Keeper when a secret is not found
)
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 ¶
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 SetPassword ¶
func SetUsername ¶
type SettableFields ¶
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 ¶
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 ¶
DeleteField sets the value of the named field. This works safely whether Field is initialized or not.
func (*Single) GetField ¶
GetField returns the value of the named field. This works safely whether Field has been initialized or not.
func (*Single) LastModified ¶
LastModified returns the last modified time of the secret.
func (*Single) SetField ¶
SetField sets the value of the named field. This works safely whether Field is initialized or not.
func (*Single) SetLastModified ¶
SetLastModified sets the last modified time of the secret.
func (*Single) SetLocation ¶
SetLocation sets the location of the secret.
func (*Single) SetPassword ¶
SetSecret sets the secret of the secret.
func (*Single) SetUsername ¶
SetUsername sets 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 WithUsername ¶
func WithUsername(username string) SingleOption
WithUsername sets the username of the secret for use when copying a secret using NewSingleFromSecret.