Documentation ¶
Index ¶
- Constants
- Variables
- func Generate(length int, specialChars bool) string
- type Collection
- func (c *Collection) Add(secret Secret) error
- func (c Collection) Get(id string) Secret
- func (c Collection) GetByID(id string) Secret
- func (c Collection) GetByName(name string) Secret
- func (c *Collection) GobDecode(b []byte) error
- func (c Collection) GobEncode() ([]byte, error)
- func (c Collection) List() []Secret
- func (c *Collection) Remove(id string) error
- func (c *Collection) RemoveByID(id string) error
- func (c *Collection) RemoveByName(name string) error
- func (c *Collection) Set(options ...CollectionOption)
- func (c *Collection) Update(secret Secret) error
- func (c Collection) Updated() time.Time
- type CollectionOption
- type CollectionOptions
- type Handler
- func (h Handler) AddSecret(name, value string, options ...SecretOption) (Secret, error)
- func (h Handler) Collection() *Collection
- func (h Handler) DeleteSecretByID(id string) error
- func (h Handler) DeleteSecretByName(name string) error
- func (h Handler) GetSecretByID(id string) (Secret, error)
- func (h Handler) GetSecretByName(name string) (Secret, error)
- func (h Handler) ListSecrets() (Secrets, error)
- func (h *Handler) Load() error
- func (h *Handler) Save() error
- func (h *Handler) Sync() error
- func (h *Handler) UpdateKey(key security.Key) error
- func (h Handler) UpdateSecretByID(id string, options ...SecretOption) (Secret, error)
- func (h Handler) UpdateSecretByName(name string, options ...SecretOption) (Secret, error)
- type HandlerOption
- type HandlerOptions
- type Secret
- type SecretOption
- type SecretOptions
- type Secrets
- type Storage
- type Type
Constants ¶
const (
KeyLength = security.KeyLength
)
Variables ¶
var ( // ErrProfileID is returned when no profile ID is provided. ErrProfileID = errors.New("a profile ID must be provided") // ErrStorage is returned when no storage is provided. ErrStorage = errors.New("a storage path must be provided when using default storage") // ErrLoadCollection is returned when a collection load fails. ErrLoadCollection = errors.New("load collection failed") // ErrSaveCollection is returned when a collection save fails. ErrSaveCollection = errors.New("save collection failed") // ErrSecretNotFound is returned when a secret cannot be found. ErrSecretNotFound = errors.New("a secret with that identifier cannot be found") )
var ( // ErrInvalidKey is returned when the provided key is invalid. ErrInvalidKey = security.ErrInvalidKey // ErrInvalidKeyLength is returned when the provided key is not the correct size. ErrInvalidKeyLength = security.ErrInvalidKeyLength )
var ( // ErrSecretEncrypt is returned when an error is encountered when encrypting a secret. ErrSecretEncrypt = errors.New("encrypting secret") // ErrSecretDecrypt is returned when an error is encountered when decrypting a secret. ErrSecretDecrypt = errors.New("decrypting secret") )
var ( // ErrSecretAlreadyExists is returned when a secret already exists. ErrSecretAlreadyExists = errors.New("a secret with that ID or name already exists") )
Functions ¶
Types ¶
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection represents a collection of secrets.
func NewCollection ¶
func NewCollection(profileID string, options ...CollectionOption) Collection
NewCollection creates and returns a new collections.
func (*Collection) Add ¶
func (c *Collection) Add(secret Secret) error
Add a secret to the collection. Returns true if secret was added, false if not (secret already exists).
func (Collection) GetByID ¶
func (c Collection) GetByID(id string) Secret
GetByID gets a secret by the provided ID.
func (Collection) GetByName ¶
func (c Collection) GetByName(name string) Secret
GetByName gets a secret by the provided name.
func (*Collection) GobDecode ¶
func (c *Collection) GobDecode(b []byte) error
GobDecode populates the Collection from a binary format.
func (Collection) GobEncode ¶
func (c Collection) GobEncode() ([]byte, error)
GobEncode serializes the Collection into a binary format.
func (*Collection) Remove ¶
func (c *Collection) Remove(id string) error
Remove a secret by the provided ID.
func (*Collection) RemoveByID ¶
func (c *Collection) RemoveByID(id string) error
RemoveByID removes a secret by the provided ID.
func (*Collection) RemoveByName ¶
func (c *Collection) RemoveByName(name string) error
RemoveByID removes a secret by the provided name.
func (*Collection) Set ¶
func (c *Collection) Set(options ...CollectionOption)
Set options for a collection.
func (Collection) Updated ¶
func (c Collection) Updated() time.Time
Updated returns when the collection was last modified.
type CollectionOption ¶
type CollectionOption func(o *CollectionOptions)
CollectionOption is a function that sets options to CollectionOptions.
func WithExpireInterval ¶
func WithExpireInterval(d time.Duration) CollectionOption
WithExpireInterfal sets expire interval on a collection.
type CollectionOptions ¶
CollectionOptions contains options for a Collection.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler represents a handler for a Collection and the storage configurations.
func NewHandler ¶
func NewHandler(profileID string, storageKey, key security.Key, storage Storage, options ...HandlerOption) (*Handler, error)
NewHandler creates and returns a new Handler.
func (Handler) AddSecret ¶
func (h Handler) AddSecret(name, value string, options ...SecretOption) (Secret, error)
AddSecret adds a new secret to the collection.
func (Handler) Collection ¶
func (h Handler) Collection() *Collection
Collection returns the current collection set to the handler.
func (Handler) DeleteSecretByID ¶
DeleteSecretByID deletes a secret by ID.
func (Handler) DeleteSecretByName ¶
DeleteSecretByName deletes a secret by name.
func (Handler) GetSecretByID ¶
GetSecretByID retrieves a secret by ID.
func (Handler) GetSecretByName ¶
GetSecretByName retrieves a secret by Name.
func (Handler) ListSecrets ¶
ListSecrets lists all secrets.
func (Handler) UpdateSecretByID ¶
func (h Handler) UpdateSecretByID(id string, options ...SecretOption) (Secret, error)
UpdateSecretByUD updates a secret in the collection by ID.
func (Handler) UpdateSecretByName ¶
func (h Handler) UpdateSecretByName(name string, options ...SecretOption) (Secret, error)
UpdateSecretByName updates a secret in the collection by name.
type HandlerOption ¶
type HandlerOption func(o *HandlerOptions)
HandlerOption is a function that sets HandlerOptions.
func WithLoadCollection ¶
func WithLoadCollection() HandlerOption
WithLoadCollection() sets that collections should be loaded when creating a new handler.
func WithSecondaryStorage ¶
func WithSecondaryStorage(storage Storage) HandlerOption
WithSecondaryStorage sets secondary storage for the Handler.
type HandlerOptions ¶
HandlerOptions contains options for a Handler.
type Secret ¶
type Secret struct { ID string `json:"id"` Name string `json:"name"` DisplayName string `json:"displayName,omitempty"` // Value is the encrypted value of a secret. Value []byte `json:"-"` Type Type `json:"type"` Labels []string `json:"labels,omitempty"` Tags map[string]string `json:"tags,omitempty"` Created time.Time `json:"created,omitempty"` Updated time.Time `json:"updated,omitempty"` // contains filtered or unexported fields }
Secret represents a secret and its data.
func NewSecret ¶
func NewSecret(name, value string, key []byte, options ...SecretOption) (Secret, error)
NewSecret creates a new secret.
type SecretOption ¶
type SecretOption func(options *SecretOptions)
SecretOption is a function to set SecretOptions.
func WithValue ¶
func WithValue(value []byte) SecretOption
WithValue sets the value to SecretOptions.
type SecretOptions ¶
type SecretOptions struct { DisplayName string Value []byte Type Type Labels []string Tags map[string]string Updated time.Time // contains filtered or unexported fields }
SecretOptions contains options for a secret.
type Storage ¶
type Storage interface { Save(data []byte) error Load() ([]byte, error) Updated() (time.Time, error) }
Storage is the interface that wraps around methods Save, Load and Updated.
type Type ¶
type Type uint8
Type represents the type of secret.
func (Type) MarshalJSON ¶
MarshalJSON marshals the Type to its string representation for JSON.
func (*Type) UnmarhsalJSON ¶
UnmarhsalJSON unmarshals the Type to its Type (uint8) representation.