vaultstore

package module
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2024 License: AGPL-3.0 Imports: 26 Imported by: 0

README

Vault Store Open in Gitpod

Tests Status Go Report Card PkgGoDev

Vault - a secure value storage (data-at-rest) implementation for Go.

License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0). You can find a copy of the license at https://www.gnu.org/licenses/agpl-3.0.en.html

For commercial use, please use my contact page to obtain a commercial license.

Installation

go get -u github.com/gouniverse/valuestore

Table Schema

The following schema is used for the database.

vault
id String, UniqueId
vault_token Long Text, Unique
vault_value Long Text
created_at DateTime
updated_at DateTime
deleted_at DateTime

Setup

vault, err := NewStore(NewStoreOptions{
	VaultTableName:     "my_vault",
	DB:                 databaseInstance,
	AutomigrateEnabled: true,
})

Usage

  • Stores a value to the vault and returns a token
token, err = vault.TokenCreate("my_value", "my_password", 20)

if err != nil {
  print("Create Failure: " + err.Error())
}
  • Check a token exists
exists, err := vault.TokenExists(token)

if err != nil {
  print("Delete Failed: " + errDelete.Error())
}

if (!exists) {
    print("token does not exist")
}
  • Retrieve a value from the vault by its token
val, err := vault.TokenRead(token, "test_pass")

if err != nil {
  print("Read failed:" + err.Error())
}
  • Delete a value from the vault by its token
err := vault.TokenDelete(token)
if err != nil {
  print("Delete failed: " + err.Error())
}

Changelog

2024.08.11 - Added token support, to allow (tokenization). More info at: https://en.wikipedia.org/wiki/Tokenization_(data_security)

2022.12.26 - Updated ID to Human Friendly UUID

2021.12.12 - Added tests badge

2021.12.28 - Fixed bug where DB scanner was returning empty values

2021.12.28 - Removed GORM dependency and moved to the standard library

Documentation

Index

Constants

View Source
const COLUMN_CREATED_AT = "created_at"
View Source
const COLUMN_DELETED_AT = "deleted_at"
View Source
const COLUMN_ID = "id"
View Source
const COLUMN_UPDATED_AT = "updated_at"
View Source
const COLUMN_VAULT_TOKEN = "vault_token"
View Source
const COLUMN_VAULT_VALUE = "vault_value"
View Source
const TOKEN_PREFIX = "tk_"

Variables

This section is empty.

Functions

func IsToken added in v0.22.0

func IsToken(s string) bool

Types

type NewStoreOptions

type NewStoreOptions struct {
	VaultTableName     string
	DB                 *sql.DB
	DbDriverName       string
	AutomigrateEnabled bool
	DebugEnabled       bool
}

NewStoreOptions define the options for creating a new session store

type Record

type Record struct {
	dataobject.DataObject
}

func NewRecord

func NewRecord() *Record

func NewRecordFromExistingData

func NewRecordFromExistingData(data map[string]string) *Record

func (*Record) CreatedAt

func (v *Record) CreatedAt() string

func (*Record) DeletedAt

func (v *Record) DeletedAt() string

func (*Record) ID

func (v *Record) ID() string

func (*Record) SetCreatedAt

func (v *Record) SetCreatedAt(createdAt string) *Record

func (*Record) SetDeletedAt

func (v *Record) SetDeletedAt(deletedAt string) *Record

func (*Record) SetID

func (v *Record) SetID(id string) *Record

func (*Record) SetToken

func (v *Record) SetToken(token string) *Record

func (*Record) SetUpdatedAt

func (v *Record) SetUpdatedAt(updatedAt string) *Record

func (*Record) SetValue

func (v *Record) SetValue(value string) *Record

func (*Record) Token

func (v *Record) Token() string

func (*Record) UpdatedAt

func (v *Record) UpdatedAt() string

func (*Record) Value

func (v *Record) Value() string

type RecordQueryOptions

type RecordQueryOptions struct {
	ID          string
	IDIn        []string
	Token       string
	TokenIn     []string
	Offset      int
	OrderBy     string
	Limit       int
	CountOnly   bool
	SortOrder   string
	WithDeleted bool
}

type Store

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

Store defines a session store

func NewStore

func NewStore(opts NewStoreOptions) (*Store, error)

NewStore creates a new entity store

func (*Store) AutoMigrate

func (st *Store) AutoMigrate() error

AutoMigrate auto migrate

func (*Store) EnableDebug

func (st *Store) EnableDebug(debug bool)

EnableDebug - enables the debug option

func (*Store) RecordCount

func (store *Store) RecordCount(ctx context.Context, options RecordQueryOptions) (int64, error)

func (*Store) RecordCreate

func (store *Store) RecordCreate(ctx context.Context, record Record) error

func (*Store) RecordDeleteByID

func (store *Store) RecordDeleteByID(ctx context.Context, recordID string) error

func (*Store) RecordDeleteByToken

func (store *Store) RecordDeleteByToken(ctx context.Context, token string) error

func (*Store) RecordFindByID

func (st *Store) RecordFindByID(ctx context.Context, id string) (*Record, error)

FindByID finds an entry by ID

func (*Store) RecordFindByToken

func (st *Store) RecordFindByToken(ctx context.Context, token string) (*Record, error)

RecordFindByToken finds a store record by token

func (*Store) RecordList

func (store *Store) RecordList(ctx context.Context, options RecordQueryOptions) ([]Record, error)

func (*Store) RecordUpdate

func (store *Store) RecordUpdate(ctx context.Context, record Record) error

func (*Store) SqlCreateTable

func (store *Store) SqlCreateTable() string

SqlCreateTable returns a SQL string for creating the setting table

func (*Store) TokenCreate

func (st *Store) TokenCreate(ctx context.Context, data string, password string, tokenLength int) (token string, err error)

TokenCreate creates a new record and returns the token

func (*Store) TokenCreateCustom

func (store *Store) TokenCreateCustom(ctx context.Context, token string, data string, password string) (err error)

func (*Store) TokenDelete

func (st *Store) TokenDelete(ctx context.Context, token string) error

TokenDelete deletes a token from the store

func (*Store) TokenExists

func (store *Store) TokenExists(ctx context.Context, token string) (bool, error)

func (*Store) TokenRead

func (st *Store) TokenRead(ctx context.Context, token string, password string) (value string, err error)

ValueRetrieve retrieves a value of a vault entry

func (*Store) TokenUpdate

func (st *Store) TokenUpdate(ctx context.Context, token string, value string, password string) (err error)

TokenUpdate updates a token in the store

func (*Store) TokensRead

func (st *Store) TokensRead(ctx context.Context, tokens []string, password string) (values map[string]string, err error)

ValueRetrieve retrieves a value of a vault entry

type StoreInterface

type StoreInterface interface {
	RecordCreate(ctx context.Context, record Record) error
	RecordFindByID(ctx context.Context, recordID string) (*Record, error)
	RecordFindByToken(ctx context.Context, token string) (*Record, error)
	RecordList(ctx context.Context, options RecordQueryOptions) ([]Record, error)
	RecordUpdate(ctx context.Context, record Record) error
	RecordDeleteByID(ctx context.Context, recordID string) error

	TokenCreate(ctx context.Context, value string, password string, tokenLength int) (token string, err error)
	TokenCreateCustom(ctx context.Context, token string, value string, password string) (err error)
	TokenDelete(ctx context.Context, token string) error
	TokenRead(ctx context.Context, token string, password string) (string, error)
	//ValueFindByID(id string) (*SearchValue, error)
	//ValueList(options SearchValueQueryOptions) ([]SearchValue, error)
	// ValueSoftDelete(valueID string) error
	// ValueSoftDeleteByID(discountID string) error
	TokenUpdate(ctx context.Context, token string, value string, password string) error
}

Jump to

Keyboard shortcuts

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