models

package
v0.0.0-...-0e2b5c9 Latest Latest
Warning

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

Go to latest
Published: May 7, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package models is a generated GoMock package.

Index

Constants

View Source
const (
	DBDialectSQLite   = "sqlite3"
	DBDialectPostgres = "postgres"
)

List of available DB dialects

View Source
const QueryLimit = 100

QueryLimit defines the maximum number of records returned

Variables

View Source
var (
	// ErrUnsupportedDialect is returned when creating a new database with a Config having an unsupported dialect
	ErrUnsupportedDialect = errors.New("unsupported database dialect")
	// ErrTopicKeyNotFound is returned when the topic cannot be found in the database
	ErrTopicKeyNotFound = errors.New("topicKey not found in database")
	// ErrClientNotFound is returned when the key cannot be found in the database
	ErrClientNotFound = errors.New("Client not found in database")
	// ErrClientNoPrimaryKey is returned when an Client is provided but it doesn't have a primary key set
	ErrClientNoPrimaryKey = errors.New("Client doesn't have primary key")
	// ErrTopicKeyNoPrimaryKey is returned when an TopicKey is provided but it doesn't have a primary key set
	ErrTopicKeyNoPrimaryKey = errors.New("TopicKey doesn't have primary key")
)

Functions

func IsErrRecordNotFound

func IsErrRecordNotFound(err error) bool

IsErrRecordNotFound indicate whenever the err is a gorm.RecordNotFound error

Types

type Client

type Client struct {
	ID        int         `gorm:"primary_key:true"`
	E4ID      []byte      `gorm:"unique_index;NOT NULL"`
	Name      string      `gorm:"unique_index;NOT NULL" sql:"size:256"`
	Key       []byte      `gorm:"NOT NULL"`
	TopicKeys []*TopicKey `gorm:"many2many:clients_topickeys;"`
	Clients   []*Client   `gorm:"many2many:clients_clientkeys;association_jointable_foreignkey:clientkey_id"`
}

Client represents an Identity Key in the database given a unique device ID.

func (Client) DecryptKey

func (i Client) DecryptKey(dbEncKey []byte) ([]byte, error)

DecryptKey returns the decrypted key of current Client

type Database

type Database interface {
	Close() error
	Connection() *gorm.DB
	Migrate() error

	// Transaction management
	BeginTx(ctx context.Context, opts *sql.TxOptions) (Database, error)
	CommitTx() error
	Rollback() error

	// Client Only Manipulation
	InsertClient(name string, id, protectedkey []byte) error
	GetClientByID(id []byte) (Client, error)
	DeleteClientByID(id []byte) error
	CountClients() (int, error)
	GetAllClients() ([]Client, error)
	GetClientsRange(offset, limit int) ([]Client, error)

	// Individual Topic Manipulaton
	InsertTopicKey(topic string, protectedKey []byte) error
	GetTopicKey(topic string) (TopicKey, error)
	DeleteTopicKey(topic string) error
	CountTopicKeys() (int, error)
	GetAllTopics() ([]TopicKey, error)
	GetAllTopicsUnsafe() ([]TopicKey, error)
	GetTopicsRange(offset, limit int) ([]TopicKey, error)

	// Linking, removing topic-client mappings:
	LinkClientTopic(client Client, topicKey TopicKey) error
	UnlinkClientTopic(client Client, topicKey TopicKey) error

	// Counting topics per client, or clients per topic.
	CountTopicsForClientByID(id []byte) (int, error)
	CountClientsForTopic(topic string) (int, error)

	// Retrieving clients per topic or topics per client
	GetTopicsForClientByID(id []byte, offset int, count int) ([]TopicKey, error)
	GetClientsForTopic(topic string, offset int, count int) ([]Client, error)

	// Linking, removing client-client mappings:
	LinkClient(source Client, target Client) error
	UnlinkClient(source Client, target Client) error

	// Counting client's linked clients
	CountLinkedClients(id []byte) (int, error)

	// Retrieving clients per client
	GetLinkedClientsForClientByID(id []byte, offset int, count int) ([]Client, error)
}

Database describes a generic database implementation

func NewDB

func NewDB(config config.DBCfg, logger *log.Logger) (Database, error)

NewDB creates a new database

type MockDatabase

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

MockDatabase is a mock of Database interface

func NewMockDatabase

func NewMockDatabase(ctrl *gomock.Controller) *MockDatabase

NewMockDatabase creates a new mock instance

func (*MockDatabase) BeginTx

func (m *MockDatabase) BeginTx(arg0 context.Context, arg1 *sql.TxOptions) (Database, error)

BeginTx mocks base method

func (*MockDatabase) Close

func (m *MockDatabase) Close() error

Close mocks base method

func (*MockDatabase) CommitTx

func (m *MockDatabase) CommitTx() error

CommitTx mocks base method

func (*MockDatabase) Connection

func (m *MockDatabase) Connection() *gorm.DB

Connection mocks base method

func (*MockDatabase) CountClients

func (m *MockDatabase) CountClients() (int, error)

CountClients mocks base method

func (*MockDatabase) CountClientsForTopic

func (m *MockDatabase) CountClientsForTopic(arg0 string) (int, error)

CountClientsForTopic mocks base method

func (*MockDatabase) CountLinkedClients

func (m *MockDatabase) CountLinkedClients(arg0 []byte) (int, error)

CountLinkedClients mocks base method

func (*MockDatabase) CountTopicKeys

func (m *MockDatabase) CountTopicKeys() (int, error)

CountTopicKeys mocks base method

func (*MockDatabase) CountTopicsForClientByID

func (m *MockDatabase) CountTopicsForClientByID(arg0 []byte) (int, error)

CountTopicsForClientByID mocks base method

func (*MockDatabase) DeleteClientByID

func (m *MockDatabase) DeleteClientByID(arg0 []byte) error

DeleteClientByID mocks base method

func (*MockDatabase) DeleteTopicKey

func (m *MockDatabase) DeleteTopicKey(arg0 string) error

DeleteTopicKey mocks base method

func (*MockDatabase) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockDatabase) GetAllClients

func (m *MockDatabase) GetAllClients() ([]Client, error)

GetAllClients mocks base method

func (*MockDatabase) GetAllTopics

func (m *MockDatabase) GetAllTopics() ([]TopicKey, error)

GetAllTopics mocks base method

func (*MockDatabase) GetAllTopicsUnsafe

func (m *MockDatabase) GetAllTopicsUnsafe() ([]TopicKey, error)

GetAllTopicsUnsafe mocks base method

func (*MockDatabase) GetClientByID

func (m *MockDatabase) GetClientByID(arg0 []byte) (Client, error)

GetClientByID mocks base method

func (*MockDatabase) GetClientsForTopic

func (m *MockDatabase) GetClientsForTopic(arg0 string, arg1, arg2 int) ([]Client, error)

GetClientsForTopic mocks base method

func (*MockDatabase) GetClientsRange

func (m *MockDatabase) GetClientsRange(arg0, arg1 int) ([]Client, error)

GetClientsRange mocks base method

func (*MockDatabase) GetLinkedClientsForClientByID

func (m *MockDatabase) GetLinkedClientsForClientByID(arg0 []byte, arg1, arg2 int) ([]Client, error)

GetLinkedClientsForClientByID mocks base method

func (*MockDatabase) GetTopicKey

func (m *MockDatabase) GetTopicKey(arg0 string) (TopicKey, error)

GetTopicKey mocks base method

func (*MockDatabase) GetTopicsForClientByID

func (m *MockDatabase) GetTopicsForClientByID(arg0 []byte, arg1, arg2 int) ([]TopicKey, error)

GetTopicsForClientByID mocks base method

func (*MockDatabase) GetTopicsRange

func (m *MockDatabase) GetTopicsRange(arg0, arg1 int) ([]TopicKey, error)

GetTopicsRange mocks base method

func (*MockDatabase) InsertClient

func (m *MockDatabase) InsertClient(arg0 string, arg1, arg2 []byte) error

InsertClient mocks base method

func (*MockDatabase) InsertTopicKey

func (m *MockDatabase) InsertTopicKey(arg0 string, arg1 []byte) error

InsertTopicKey mocks base method

func (*MockDatabase) LinkClient

func (m *MockDatabase) LinkClient(arg0, arg1 Client) error

LinkClient mocks base method

func (*MockDatabase) LinkClientTopic

func (m *MockDatabase) LinkClientTopic(arg0 Client, arg1 TopicKey) error

LinkClientTopic mocks base method

func (*MockDatabase) Migrate

func (m *MockDatabase) Migrate() error

Migrate mocks base method

func (*MockDatabase) Rollback

func (m *MockDatabase) Rollback() error

Rollback mocks base method

func (*MockDatabase) UnlinkClient

func (m *MockDatabase) UnlinkClient(arg0, arg1 Client) error

UnlinkClient mocks base method

func (*MockDatabase) UnlinkClientTopic

func (m *MockDatabase) UnlinkClientTopic(arg0 Client, arg1 TopicKey) error

UnlinkClientTopic mocks base method

type MockDatabaseMockRecorder

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

MockDatabaseMockRecorder is the mock recorder for MockDatabase

func (*MockDatabaseMockRecorder) BeginTx

func (mr *MockDatabaseMockRecorder) BeginTx(arg0, arg1 interface{}) *gomock.Call

BeginTx indicates an expected call of BeginTx

func (*MockDatabaseMockRecorder) Close

func (mr *MockDatabaseMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close

func (*MockDatabaseMockRecorder) CommitTx

func (mr *MockDatabaseMockRecorder) CommitTx() *gomock.Call

CommitTx indicates an expected call of CommitTx

func (*MockDatabaseMockRecorder) Connection

func (mr *MockDatabaseMockRecorder) Connection() *gomock.Call

Connection indicates an expected call of Connection

func (*MockDatabaseMockRecorder) CountClients

func (mr *MockDatabaseMockRecorder) CountClients() *gomock.Call

CountClients indicates an expected call of CountClients

func (*MockDatabaseMockRecorder) CountClientsForTopic

func (mr *MockDatabaseMockRecorder) CountClientsForTopic(arg0 interface{}) *gomock.Call

CountClientsForTopic indicates an expected call of CountClientsForTopic

func (*MockDatabaseMockRecorder) CountLinkedClients

func (mr *MockDatabaseMockRecorder) CountLinkedClients(arg0 interface{}) *gomock.Call

CountLinkedClients indicates an expected call of CountLinkedClients

func (*MockDatabaseMockRecorder) CountTopicKeys

func (mr *MockDatabaseMockRecorder) CountTopicKeys() *gomock.Call

CountTopicKeys indicates an expected call of CountTopicKeys

func (*MockDatabaseMockRecorder) CountTopicsForClientByID

func (mr *MockDatabaseMockRecorder) CountTopicsForClientByID(arg0 interface{}) *gomock.Call

CountTopicsForClientByID indicates an expected call of CountTopicsForClientByID

func (*MockDatabaseMockRecorder) DeleteClientByID

func (mr *MockDatabaseMockRecorder) DeleteClientByID(arg0 interface{}) *gomock.Call

DeleteClientByID indicates an expected call of DeleteClientByID

func (*MockDatabaseMockRecorder) DeleteTopicKey

func (mr *MockDatabaseMockRecorder) DeleteTopicKey(arg0 interface{}) *gomock.Call

DeleteTopicKey indicates an expected call of DeleteTopicKey

func (*MockDatabaseMockRecorder) GetAllClients

func (mr *MockDatabaseMockRecorder) GetAllClients() *gomock.Call

GetAllClients indicates an expected call of GetAllClients

func (*MockDatabaseMockRecorder) GetAllTopics

func (mr *MockDatabaseMockRecorder) GetAllTopics() *gomock.Call

GetAllTopics indicates an expected call of GetAllTopics

func (*MockDatabaseMockRecorder) GetAllTopicsUnsafe

func (mr *MockDatabaseMockRecorder) GetAllTopicsUnsafe() *gomock.Call

GetAllTopicsUnsafe indicates an expected call of GetAllTopicsUnsafe

func (*MockDatabaseMockRecorder) GetClientByID

func (mr *MockDatabaseMockRecorder) GetClientByID(arg0 interface{}) *gomock.Call

GetClientByID indicates an expected call of GetClientByID

func (*MockDatabaseMockRecorder) GetClientsForTopic

func (mr *MockDatabaseMockRecorder) GetClientsForTopic(arg0, arg1, arg2 interface{}) *gomock.Call

GetClientsForTopic indicates an expected call of GetClientsForTopic

func (*MockDatabaseMockRecorder) GetClientsRange

func (mr *MockDatabaseMockRecorder) GetClientsRange(arg0, arg1 interface{}) *gomock.Call

GetClientsRange indicates an expected call of GetClientsRange

func (*MockDatabaseMockRecorder) GetLinkedClientsForClientByID

func (mr *MockDatabaseMockRecorder) GetLinkedClientsForClientByID(arg0, arg1, arg2 interface{}) *gomock.Call

GetLinkedClientsForClientByID indicates an expected call of GetLinkedClientsForClientByID

func (*MockDatabaseMockRecorder) GetTopicKey

func (mr *MockDatabaseMockRecorder) GetTopicKey(arg0 interface{}) *gomock.Call

GetTopicKey indicates an expected call of GetTopicKey

func (*MockDatabaseMockRecorder) GetTopicsForClientByID

func (mr *MockDatabaseMockRecorder) GetTopicsForClientByID(arg0, arg1, arg2 interface{}) *gomock.Call

GetTopicsForClientByID indicates an expected call of GetTopicsForClientByID

func (*MockDatabaseMockRecorder) GetTopicsRange

func (mr *MockDatabaseMockRecorder) GetTopicsRange(arg0, arg1 interface{}) *gomock.Call

GetTopicsRange indicates an expected call of GetTopicsRange

func (*MockDatabaseMockRecorder) InsertClient

func (mr *MockDatabaseMockRecorder) InsertClient(arg0, arg1, arg2 interface{}) *gomock.Call

InsertClient indicates an expected call of InsertClient

func (*MockDatabaseMockRecorder) InsertTopicKey

func (mr *MockDatabaseMockRecorder) InsertTopicKey(arg0, arg1 interface{}) *gomock.Call

InsertTopicKey indicates an expected call of InsertTopicKey

func (*MockDatabaseMockRecorder) LinkClient

func (mr *MockDatabaseMockRecorder) LinkClient(arg0, arg1 interface{}) *gomock.Call

LinkClient indicates an expected call of LinkClient

func (*MockDatabaseMockRecorder) LinkClientTopic

func (mr *MockDatabaseMockRecorder) LinkClientTopic(arg0, arg1 interface{}) *gomock.Call

LinkClientTopic indicates an expected call of LinkClientTopic

func (*MockDatabaseMockRecorder) Migrate

func (mr *MockDatabaseMockRecorder) Migrate() *gomock.Call

Migrate indicates an expected call of Migrate

func (*MockDatabaseMockRecorder) Rollback

func (mr *MockDatabaseMockRecorder) Rollback() *gomock.Call

Rollback indicates an expected call of Rollback

func (*MockDatabaseMockRecorder) UnlinkClient

func (mr *MockDatabaseMockRecorder) UnlinkClient(arg0, arg1 interface{}) *gomock.Call

UnlinkClient indicates an expected call of UnlinkClient

func (*MockDatabaseMockRecorder) UnlinkClientTopic

func (mr *MockDatabaseMockRecorder) UnlinkClientTopic(arg0, arg1 interface{}) *gomock.Call

UnlinkClientTopic indicates an expected call of UnlinkClientTopic

type TopicKey

type TopicKey struct {
	ID      int       `gorm:"primary_key:true"`
	Topic   string    `gorm:"unique_index;NOT NULL"`
	Key     []byte    `gorm:"NOT NULL"`
	Clients []*Client `gorm:"many2many:clients_topickeys;"`
}

TopicKey represents

func (TopicKey) DecryptKey

func (t TopicKey) DecryptKey(dbEncKey []byte) ([]byte, error)

DecryptKey returns the decrypted key of the current TopicKey

func (TopicKey) Hash

func (t TopicKey) Hash() []byte

Hash return the E4 Hashed topic of the current TopicKey

Jump to

Keyboard shortcuts

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