storage

package
v0.9.15 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package storage provides storage for IC and DAM.

Index

Constants

View Source
const (
	LatestRev      = int64(-1)
	LatestRevName  = "latest"
	HistoryRevName = "history"
	DefaultRealm   = "master"
	DefaultUser    = ""
	DefaultID      = "main"
	AllRealms      = ""
	MatchAllGroups = "" // alias for MatchAllUsers
	MatchAllUsers  = "" // alias for MatchAllGroups
	MatchAllIDs    = ""

	AccountDatatype                   = "account"
	AccountLookupDatatype             = "acct_lookup"
	CliAuthDatatype                   = "cli_auth"
	ClientDatatype                    = "client"
	ConfigDatatype                    = "config"
	GroupDatatype                     = "group"
	GroupMemberDatatype               = "member"
	LockDatatype                      = "lock"
	LoginStateDatatype                = "login_state"
	LongRunningOperationDatatype      = "lro"
	ProcessDataType                   = "process"
	PermissionsDatatype               = "permissions"
	SecretsDatatype                   = "secrets"
	TokensDatatype                    = "tokens"
	PendingDeleteTokenDatatype        = "pending_delete_token"
	ResourceTokenRequestStateDataType = "resource_token_state"
	RememberedConsentDatatype         = "remembered_consent"

	// StateActive indicates an object is active.
	StateActive = "ACTIVE"
	// StateDeleted indicates an object is deleted (can still be referenced by an admin).
	StateDeleted = "DELETED"
	// StateDisabled indicates an object is disabled (may be reactived later).
	StateDisabled = "DISABLED"

	// DefaultPageSize is the default number of entries returned by a list.
	DefaultPageSize = 50
	// MaxPageSize is the maximum number of entries returned by a list.
	MaxPageSize = 1000
)

Variables

This section is empty.

Functions

func BuildFilters

func BuildFilters(str string, fields map[string]func(p proto.Message) string) ([][]Filter, error)

BuildFilters creates a set of filters based on an input string. Within the field map, SCIM path names are expected to be lowercase. Example:

BuildFilters(`name.formatted eq "Joe" or name.familyName sw "Smith"`, map[string]func(p proto.Message) string {
  "name.formatted": func(p proto.Message) string {
    return myProtoCast(p).Profile.Name
  },
  "name.familyname": func(p proto.Message) string {
    return myProtoCast(p).Profile.FamilyName
  },
})

The filters generated by this method can be evaluated with a proto input using MatchProtoFilters(filters, myProto).

func ErrNotFound

func ErrNotFound(err error) bool

func GetHistory

func GetHistory(store Store, datatype, realm, user, id string, r *http.Request) (*cpb.History, int, error)

GetHistory returns a History object based on the input parameters.

func MakeConfigHistory

func MakeConfigHistory(desc, resType string, rev int64, ts float64, r *http.Request, user string, orig, update proto.Message) proto.Message

func MatchProtoFilters

func MatchProtoFilters(cnfFilters [][]Filter, p proto.Message) bool

MatchProtoFilters returns true if any of the filter conditions are met (i.e. evaluates a Conjunctive Normal Form (CNF) of this array of filters). Simplified version of: https://tools.ietf.org/html/rfc7644#section-3.4.2.2

func ReplaceContentVariables added in v0.8.4

func ReplaceContentVariables(content proto.Message, varValues map[string]string) error

ReplaceContentVariables does simple string replacement of variable names to values. If varValues is nil, then it only checks that `content` is JSON.

func UserFragment

func UserFragment(user string) string

Types

type Entry added in v0.9.9

type Entry struct {
	// Realm is the realm to which this entry belongs.
	Realm string
	// GroupID is a logical grouping for a set of items.
	GroupID string
	// ItemID is the identifier for the proto item being stored.
	ItemID string
	// Item is the proto that is being stored.
	Item proto.Message
}

Entry represents a single storage item and its metadata.

type FileStorage

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

func NewFileStorage

func NewFileStorage(service, path string) *FileStorage

func (*FileStorage) Delete

func (f *FileStorage) Delete(datatype, realm, user, id string, rev int64) error

Delete a record.

func (*FileStorage) DeleteTx

func (f *FileStorage) DeleteTx(datatype, realm, user, id string, rev int64, tx Tx) error

DeleteTx delete a record with transaction.

func (*FileStorage) Exists

func (f *FileStorage) Exists(datatype, realm, user, id string, rev int64) (bool, error)

func (*FileStorage) Info

func (f *FileStorage) Info() map[string]string

func (*FileStorage) LockTx

func (f *FileStorage) LockTx(lockName string, minFrequency time.Duration, tx Tx) Tx

LockTx returns a storage-wide lock by the given name. Only one such lock should be requested at a time. If Tx is provided, it must be an update Tx.

func (*FileStorage) MultiDeleteTx

func (f *FileStorage) MultiDeleteTx(datatype, realm, user string, tx Tx) error

MultiDeleteTx deletes all records of a certain data type within a realm.

func (*FileStorage) MultiReadTx

func (f *FileStorage) MultiReadTx(datatype, realm, user, id string, filters [][]Filter, offset, pageSize int, typ proto.Message, tx Tx) (*Results, error)

MultiReadTx reads a set of objects matching the input parameters and filters

func (*FileStorage) Read

func (f *FileStorage) Read(datatype, realm, user, id string, rev int64, content proto.Message) error

func (*FileStorage) ReadHistory

func (f *FileStorage) ReadHistory(datatype, realm, user, id string, content *[]proto.Message) error

func (*FileStorage) ReadHistoryTx

func (f *FileStorage) ReadHistoryTx(datatype, realm, user, id string, content *[]proto.Message, tx Tx) (ferr error)

ReadHistoryTx reads hisotry inside a transaction.

func (*FileStorage) ReadTx

func (f *FileStorage) ReadTx(datatype, realm, user, id string, rev int64, content proto.Message, tx Tx) (ferr error)

ReadTx reads inside a transaction.

func (*FileStorage) Tx

func (f *FileStorage) Tx(update bool) (Tx, error)

func (*FileStorage) Wipe

func (f *FileStorage) Wipe(ctx context.Context, realm string, batchNum, maxEntries int) (int, error)

Wipe deletes all records within a realm.

func (*FileStorage) Write

func (f *FileStorage) Write(datatype, realm, user, id string, rev int64, content proto.Message, history proto.Message) error

func (*FileStorage) WriteTx

func (f *FileStorage) WriteTx(datatype, realm, user, id string, rev int64, content proto.Message, history proto.Message, tx Tx) error

type FileTx

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

func (*FileTx) Finish

func (tx *FileTx) Finish() error

Finish attempts to commit a transaction.

func (*FileTx) IsUpdate

func (tx *FileTx) IsUpdate() bool

func (*FileTx) MakeUpdate added in v0.8.8

func (tx *FileTx) MakeUpdate() error

MakeUpdate will upgrade a read-only transaction to an update transaction.

func (*FileTx) Rollback

func (tx *FileTx) Rollback() error

Rollback attempts to rollback a transaction.

type Filter

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

Filter is a means to filter which entries are returned from MultiReadTx.

type MemTx

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

func (*MemTx) Finish

func (tx *MemTx) Finish() error

Finish attempts to commit a transaction.

func (*MemTx) IsUpdate

func (tx *MemTx) IsUpdate() bool

func (*MemTx) MakeUpdate added in v0.8.8

func (tx *MemTx) MakeUpdate() error

MakeUpdate will upgrade a read-only transaction to an update transaction.

func (*MemTx) Rollback

func (tx *MemTx) Rollback() error

Rollback attempts to rollback a transaction.

type MemoryStorage

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

MemoryStorage is designed as a single threading storage. Will throw exception if multiple TX request.

func NewMemoryStorage

func NewMemoryStorage(service, path string) *MemoryStorage

func (*MemoryStorage) Delete

func (m *MemoryStorage) Delete(datatype, realm, user, id string, rev int64) error

Delete a record.

func (*MemoryStorage) DeleteTx

func (m *MemoryStorage) DeleteTx(datatype, realm, user, id string, rev int64, tx Tx) (ferr error)

DeleteTx delete a record with transaction.

func (*MemoryStorage) Exists

func (m *MemoryStorage) Exists(datatype, realm, user, id string, rev int64) (bool, error)

func (*MemoryStorage) Info

func (m *MemoryStorage) Info() map[string]string

func (*MemoryStorage) LockTx

func (m *MemoryStorage) LockTx(lockName string, minFrequency time.Duration, tx Tx) Tx

LockTx returns a storage-wide lock by the given name. Only one such lock should be requested at a time. If Tx is provided, it must be an update Tx.

func (*MemoryStorage) MultiDeleteTx

func (m *MemoryStorage) MultiDeleteTx(datatype, realm, user string, tx Tx) (ferr error)

MultiDeleteTx deletes all records of a certain data type within a realm.

func (*MemoryStorage) MultiReadTx

func (m *MemoryStorage) MultiReadTx(datatype, realm, user, id string, filters [][]Filter, offset, pageSize int, typ proto.Message, tx Tx) (_ *Results, ferr error)

MultiReadTx reads a set of objects matching the input parameters and filters

func (*MemoryStorage) Read

func (m *MemoryStorage) Read(datatype, realm, user, id string, rev int64, content proto.Message) error

func (*MemoryStorage) ReadHistory

func (m *MemoryStorage) ReadHistory(datatype, realm, user, id string, content *[]proto.Message) error

func (*MemoryStorage) ReadHistoryTx

func (m *MemoryStorage) ReadHistoryTx(datatype, realm, user, id string, content *[]proto.Message, tx Tx) (ferr error)

ReadHistoryTx reads history inside a transaction.

func (*MemoryStorage) ReadTx

func (m *MemoryStorage) ReadTx(datatype, realm, user, id string, rev int64, content proto.Message, tx Tx) (ferr error)

ReadTx reads inside a transaction.

func (*MemoryStorage) Tx

func (m *MemoryStorage) Tx(update bool) (Tx, error)

func (*MemoryStorage) Wipe

func (m *MemoryStorage) Wipe(ctx context.Context, realm string, batchNum, maxEntries int) (int, error)

func (*MemoryStorage) Write

func (m *MemoryStorage) Write(datatype, realm, user, id string, rev int64, content proto.Message, history proto.Message) error

func (*MemoryStorage) WriteTx

func (m *MemoryStorage) WriteTx(datatype, realm, user, id string, rev int64, content proto.Message, history proto.Message, tx Tx) (ferr error)

WriteTx writes inside a transaction.

type Results added in v0.9.9

type Results struct {
	// Entries contains the list of entries returned by the query.
	Entries []*Entry
	// MatchCount is the number of matches that exist, starting at any offset provided by the query.
	MatchCount int
}

Results represents a set of entries returned as part of a query.

func NewResults added in v0.9.9

func NewResults() *Results

NewResults returns a new Results object.

type StorageCache

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

func NewStorageCache

func NewStorageCache() *StorageCache

func (*StorageCache) Backup

func (s *StorageCache) Backup()

func (*StorageCache) DeleteEntity

func (s *StorageCache) DeleteEntity(id string)

func (*StorageCache) DeleteHistory

func (s *StorageCache) DeleteHistory(id string)

func (*StorageCache) Entities added in v0.8.6

func (s *StorageCache) Entities() map[string]proto.Message

Entities returns the map of entity names to content.

func (*StorageCache) GetEntity

func (s *StorageCache) GetEntity(id string) (proto.Message, bool)

func (*StorageCache) GetHistory

func (s *StorageCache) GetHistory(id string) ([]proto.Message, bool)

func (*StorageCache) PutEntity

func (s *StorageCache) PutEntity(id string, msg proto.Message)

func (*StorageCache) PutHistory

func (s *StorageCache) PutHistory(id string, msg []proto.Message)

func (*StorageCache) Restore

func (s *StorageCache) Restore()

type Store

type Store interface {
	Info() map[string]string
	Exists(datatype, realm, user, id string, rev int64) (bool, error)
	Read(datatype, realm, user, id string, rev int64, content proto.Message) error
	ReadTx(datatype, realm, user, id string, rev int64, content proto.Message, tx Tx) error
	// MultiReadTx reads a set of objects matching the input parameters and filters. Returns total count and error.
	MultiReadTx(datatype, realm, user, id string, filters [][]Filter, offset, pageSize int, typ proto.Message, tx Tx) (*Results, error)
	ReadHistory(datatype, realm, user, id string, content *[]proto.Message) error
	ReadHistoryTx(datatype, realm, user, id string, content *[]proto.Message, tx Tx) error
	Write(datatype, realm, user, id string, rev int64, content proto.Message, history proto.Message) error
	WriteTx(datatype, realm, user, id string, rev int64, content proto.Message, history proto.Message, tx Tx) error
	Delete(datatype, realm, user, id string, rev int64) error
	DeleteTx(datatype, realm, user, id string, rev int64, tx Tx) error
	MultiDeleteTx(datatype, realm, user string, tx Tx) error
	// Wipe removes any items from a realm up to maxEntries (if > 0). Returns count of deleted items and error.
	Wipe(ctx context.Context, realm string, batchNum, maxEntries int) (int, error)
	Tx(update bool) (Tx, error)
	LockTx(lockName string, minFrequency time.Duration, tx Tx) Tx
}

Store is an interface to the storage layer.

type Tx

type Tx interface {
	Finish() error
	Rollback() error
	// MakeUpdate will upgrade a read-only transaction to an update transaction.
	MakeUpdate() error
	IsUpdate() bool
}

Jump to

Keyboard shortcuts

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