vault

package
v0.0.0-...-7578c0e Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DbStatusInit    = "setup-completed"
	DbStatusNotInit = "uninitialized"
	StatusLocked    = "locked"
	StatusUnlocked  = "unlocked"
)

Variables

View Source
var DataSourceOptions = sqlite.DataSourceOptions{WALEnabled: false}
View Source
var ErrDatabaseNotInitialised = errors2.APIError{
	Err:        errors.New("vault is not initialized yet"),
	HTTPStatus: http.StatusConflict,
}
View Source
var WrongPasswordError = errors2.APIError{
	Message:    "wrong password provided",
	HTTPStatus: http.StatusUnauthorized,
}

Functions

func Validate

func Validate(iv *InputValue) error

Types

type Aes256PassManager

type Aes256PassManager struct {
}

func (*Aes256PassManager) GetEncRandValue

func (apm *Aes256PassManager) GetEncRandValue(pass string) (encValue, decValue string, err error)

GetEncRandValue generates a pseudo random hash sum and encrypts it with the provided password this is used to check if the provided password is correct and can potentially decrypt vault values

func (*Aes256PassManager) PassMatch

func (apm *Aes256PassManager) PassMatch(dbStatus DbStatus, passToCheck string) (bool, error)

func (*Aes256PassManager) ValidatePass

func (apm *Aes256PassManager) ValidatePass(passToCheck string) error

type Config

type Config interface {
	GetVaultDBPath() string
}

type DbProvider

type DbProvider interface {
	GetStatus(ctx context.Context) (DbStatus, error)
	SetStatus(ctx context.Context, newStatus DbStatus) error
	GetByID(ctx context.Context, id int) (val StoredValue, found bool, err error)
	List(ctx context.Context, lo *query.ListOptions) ([]ValueKey, error)
	FindByKeyAndClientID(ctx context.Context, key, clientID string) (val StoredValue, found bool, err error)
	Save(ctx context.Context, user string, idToUpdate int64, val *InputValue, nowDate time.Time) (int64, error)
	Delete(ctx context.Context, id int) error
	io.Closer
}

type DbProviderFactory

type DbProviderFactory interface {
	GetDbProvider() DbProvider
	Init() error
}

func NewStatefulDbProviderFactory

func NewStatefulDbProviderFactory(initDBBuilder func() (DbProvider, error), notInitDBProvider DbProvider) DbProviderFactory

type DbStatus

type DbStatus struct {
	ID            int    `db:"id"`
	StatusName    string `db:"db_status"`
	EncCheckValue string `db:"enc_check"`
	DecCheckValue string `db:"dec_check"`
}

type InputValue

type InputValue struct {
	ClientID      string    `json:"client_id" db:"client_id"`
	RequiredGroup string    `json:"required_group" db:"required_group"`
	Key           string    `json:"key" db:"key"`
	Value         string    `json:"value" db:"value"`
	Type          ValueType `json:"type" db:"type"`
}

type Manager

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

func NewManager

func NewManager(dbFactory DbProviderFactory, pm PassManager, logger *logger.Logger) *Manager

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, id int, user UserDataProvider) error

func (*Manager) GetOne

func (m *Manager) GetOne(ctx context.Context, id int, user UserDataProvider) (StoredValue, bool, error)

func (*Manager) Init

func (m *Manager) Init(ctx context.Context, pass string) error

func (*Manager) IsLocked

func (m *Manager) IsLocked() bool

func (*Manager) List

func (m *Manager) List(ctx context.Context, re *http.Request) ([]ValueKey, error)

func (*Manager) Lock

func (m *Manager) Lock(ctx context.Context) error

func (*Manager) Status

func (m *Manager) Status(ctx context.Context) (StatusReport, error)

func (*Manager) Store

func (m *Manager) Store(ctx context.Context, existingID int64, valueToStore *InputValue, user UserDataProvider) (StoredValueID, error)

func (*Manager) UnLock

func (m *Manager) UnLock(ctx context.Context, pass string) error

type NotInitDbProvider

type NotInitDbProvider struct{}

func (*NotInitDbProvider) Close

func (nidp *NotInitDbProvider) Close() error

func (*NotInitDbProvider) Delete

func (nidp *NotInitDbProvider) Delete(ctx context.Context, id int) error

func (*NotInitDbProvider) FindByKeyAndClientID

func (nidp *NotInitDbProvider) FindByKeyAndClientID(ctx context.Context, key, clientID string) (val StoredValue, found bool, err error)

func (*NotInitDbProvider) GetByID

func (nidp *NotInitDbProvider) GetByID(ctx context.Context, id int) (val StoredValue, found bool, err error)

func (*NotInitDbProvider) GetStatus

func (nidp *NotInitDbProvider) GetStatus(ctx context.Context) (DbStatus, error)

func (*NotInitDbProvider) Init

func (nidp *NotInitDbProvider) Init(ctx context.Context) error

func (*NotInitDbProvider) List

func (nidp *NotInitDbProvider) List(ctx context.Context, lo *query.ListOptions) ([]ValueKey, error)

func (*NotInitDbProvider) Save

func (nidp *NotInitDbProvider) Save(ctx context.Context, user string, idToUpdate int64, val *InputValue, nowDate time.Time) (int64, error)

func (*NotInitDbProvider) SetStatus

func (nidp *NotInitDbProvider) SetStatus(ctx context.Context, newStatus DbStatus) error

type PassManager

type PassManager interface {
	ValidatePass(passToCheck string) error
	PassMatch(dbStatus DbStatus, passToCheck string) (bool, error)
	GetEncRandValue(pass string) (encValue, decValue string, err error)
}

type PassRequest

type PassRequest struct {
	Password string `json:"password"`
}

type SqliteProvider

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

func NewSqliteProvider

func NewSqliteProvider(c Config, logger *logger.Logger) (*SqliteProvider, error)

func (*SqliteProvider) Close

func (p *SqliteProvider) Close() error

func (*SqliteProvider) Delete

func (p *SqliteProvider) Delete(ctx context.Context, id int) error

func (*SqliteProvider) FindByKeyAndClientID

func (p *SqliteProvider) FindByKeyAndClientID(ctx context.Context, key, clientID string) (val StoredValue, found bool, err error)

func (*SqliteProvider) GetByID

func (p *SqliteProvider) GetByID(ctx context.Context, id int) (val StoredValue, found bool, err error)

func (*SqliteProvider) GetStatus

func (p *SqliteProvider) GetStatus(ctx context.Context) (DbStatus, error)

func (*SqliteProvider) List

func (p *SqliteProvider) List(ctx context.Context, lo *query.ListOptions) ([]ValueKey, error)

func (*SqliteProvider) Save

func (p *SqliteProvider) Save(ctx context.Context, user string, idToUpdate int64, val *InputValue, nowDate time.Time) (int64, error)

func (*SqliteProvider) SetStatus

func (p *SqliteProvider) SetStatus(ctx context.Context, newStatus DbStatus) error

type StatefulDbProviderFactory

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

func (*StatefulDbProviderFactory) GetDbProvider

func (dpf *StatefulDbProviderFactory) GetDbProvider() DbProvider

func (*StatefulDbProviderFactory) Init

func (dpf *StatefulDbProviderFactory) Init() error

type StatusReport

type StatusReport struct {
	InitStatus string `json:"init"`
	LockStatus string `json:"status"`
}

type StoredValue

type StoredValue struct {
	InputValue
	ID        int       `json:"id" db:"id"`
	CreatedAt time.Time `json:"created_at" db:"created_at"`
	UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
	CreatedBy string    `json:"created_by" db:"created_by"`
	UpdatedBy *string   `json:"updated_by" db:"updated_by"`
}

type StoredValueID

type StoredValueID struct {
	ID int64 `json:"id"`
}

type UserDataProvider

type UserDataProvider interface {
	GetGroups() []string
	GetUsername() string
}

type ValueKey

type ValueKey struct {
	ID        int       `json:"id" db:"id"`
	ClientID  string    `json:"client_id" db:"client_id"`
	CreatedBy string    `json:"created_by" db:"created_by"`
	CreatedAt time.Time `json:"created_at" db:"created_at"`
	Key       string    `json:"key" db:"key"`
}

type ValueType

type ValueType string
const MarkdownType ValueType = "markdown"
const SecretType ValueType = "secret"
const StringType ValueType = "string"
const TextType ValueType = "text"

Jump to

Keyboard shortcuts

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