vault

package
v0.0.0-...-7adfc1b Latest Latest
Warning

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

Go to latest
Published: May 28, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package vault handles storing and retrieving passwords from a vault. Creates a level of abstraction between the application and the underlying storage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager represents a vault manager, which can be used to perform CRUD operations on a vault. A vault is an abstraction of the underlying database.

A vault manager is created by calling NewManager() and must be initialized with Init before it can be used. After initialization, the vault can be immediately used as if it was already unlocked. The vault status can be checked by calling IsUnlocked(), the status can be changed by calling Lock() or Unlock(). Locking the vault manager is useful when the vault manager is no longer needed.

func NewManager

func NewManager(db Vault) *Manager

NewManager creates a new vault manager without initializing it. If the vault manager has been already initialized, the Manager can be used after Unlock() has been called. If the vault manager has not been initialised, Init() must be called before any other method. Please remember to Close() the vault Manager.

func (*Manager) Close

func (m *Manager) Close()

Close closes and locks (see Lock()) the vault and the underlying database connection. The vault can no longer be used after Close has been called.

func (*Manager) Create

func (m *Manager) Create(entry *model.PasswordEntry) error

Create adds a new model.PasswordEntry to the vault.

func (*Manager) Delete

func (*Manager) Delete(_ *model.PasswordEntry) error

Delete removes a model.PasswordEntry from the vault.

func (*Manager) Init

func (m *Manager) Init(masterPassword string) error

Init initializes the vault. After initialization, the vault can be immediately used as if it was already unlocked.

func (*Manager) IsUnlocked

func (m *Manager) IsUnlocked() bool

IsUnlocked returns true if the vault is unlocked. If the vault is locked, the vault can be unlocked by calling Unlock(). Locking the vault is useful when the vault is no longer needed.

The vault is unlocked by default when the vault is first initialized with Init.

func (*Manager) List

func (*Manager) List() ([]*model.PasswordEntry, error)

List retrieves all model.PasswordEntry from the vault.

func (*Manager) Lock

func (m *Manager) Lock()

Lock locks the vault, removing the encryption key from memory. The vault can be unlocked again by calling Unlock(). Locking the vault is useful when the vault is no longer needed.

func (*Manager) Read

func (m *Manager) Read(service string) (*model.PasswordEntry, error)

Read retrieves the model.PasswordEntry associated with the service from the vault.

func (*Manager) Unlock

func (m *Manager) Unlock(masterPassword string) (bool, error)

Unlock unlocks the vault using the masterPassword. If the vault is already unlocked, Unlock returns true and no error. The vault can be locked again using Lock.

Unlock returns true if the vault was unlocked successfully, false otherwise. If any error occurs, it is returned to the caller.

func (*Manager) Update

func (*Manager) Update(_ *model.PasswordEntry) error

Update updates a model.PasswordEntry.

type Vault

type Vault interface {
	// SavePasswordEntry creates or updates a new password entry to the vault.
	SavePasswordEntry(entry *model.PasswordEntry) error
	// GetPasswordEntry retrieves a password entry from the vault.
	GetPasswordEntry(service string) (*model.PasswordEntry, error)
	// ListPasswordEntries retrieves all password entries from the vault.
	ListPasswordEntries() ([]*model.PasswordEntry, error)
	// DeletePasswordEntry deletes a password entry from the vault.
	DeletePasswordEntry(service string) error
	// SaveVaultMetadata creates or updates the vault metadata.
	SaveVaultMetadata(v *model.VaultMetadata) error
	// GetVaultMetadata retrieves the vault metadata.
	GetVaultMetadata() (*model.VaultMetadata, error)
	// Initialize the vault.
	Initialize() error
	// Close the vault and the underlying database connection.
	Close() error
}

Vault defines the methods to perform CRUD operations on the underlying database. It is implemented by db.Database.

Jump to

Keyboard shortcuts

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