device

package
v0.0.0-...-6b846f9 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidDeviceID       = errors.New("device id is invalid")
	ErrDeviceNotFound        = errors.New("device is not found")
	ErrRelationNotFound      = errors.New("relation is not found")
	ErrRelationAlreadyExists = errors.New("relation already exists")
	ErrNilDatabase           = errors.New("data is nil")
	ErrInvalidAssetID        = errors.New("asset id is invalid")
)

Functions

This section is empty.

Types

type Asset

type Asset struct {
	ID   uuid.UUID `db:"id" json:"id"`
	Kind AssetKind `db:"kind" json:"kind"`
}

type AssetKind

type AssetKind uint8
const (
	AKClient AssetKind = iota
	AKIdentity
)

type Device

type Device struct {
	Name         string    `db:"name" json:"name"`
	ID           uuid.UUID `db:"id" json:"id"`
	IMEI         string    `db:"imei" json:"imei"`
	MEID         string    `db:"meid" json:"meid"`
	SerialNumber string    `db:"esn" json:"esn"`
	RegisteredAt time.Time `db:"registered_at" json:"registered_at"`
	ExpireAt     time.Time `db:"expire_at" json:"expire_at"`
	Flags        Flags     `db:"flags" json:"flags"`
	// contains filtered or unexported fields
}

Device represents

type Flags

type Flags uint8

Flags represent device flags

const (
	FEnabled Flags = 1 << iota
	FCompromised
	FLost
)

type Kind

type Kind uint8

Kind represents a kind of a device (i.e.: desktop/mobile/iot/etc...)

type Manager

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

type Relation

type Relation struct {
	DeviceID uuid.UUID `db:"device_id" json:"device_id"`
	Asset    `db:"asset" json:"asset"`
}

type SQLStore

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

func (*SQLStore) CreateRelation

func (s *SQLStore) CreateRelation(ctx context.Context, rel Relation) (err error)

func (*SQLStore) DeleteDeviceByID

func (s *SQLStore) DeleteDeviceByID(ctx context.Context, deviceID uuid.UUID) (err error)

func (*SQLStore) DeleteRelation

func (s *SQLStore) DeleteRelation(ctx context.Context, rel Relation) (err error)

func (*SQLStore) FetchAllDevices

func (s *SQLStore) FetchAllDevices(ctx context.Context) ([]Device, error)

func (*SQLStore) FetchAllRelations

func (s *SQLStore) FetchAllRelations(ctx context.Context) (relations []Relation, err error)

func (*SQLStore) FetchClientRelations

func (s *SQLStore) FetchClientRelations(ctx context.Context, groupID uuid.UUID) ([]Relation, error)

func (*SQLStore) FetchDeviceByID

func (s *SQLStore) FetchDeviceByID(ctx context.Context, groupID uuid.UUID) (Device, error)

func (*SQLStore) HasRelation

func (s *SQLStore) HasRelation(ctx context.Context, rel Relation) bool

func (*SQLStore) UpsertDevice

func (s *SQLStore) UpsertDevice(ctx context.Context, d Device) (_ Device, err error)

type Store

type Store interface {
	UpsertDevice(ctx context.Context, d Device) (Device, error)
	CreateRelation(ctx context.Context, rel Relation) error
	HasRelation(ctx context.Context, rel Relation) bool
	FetchDeviceByID(ctx context.Context, deviceID uuid.UUID) (d Device, err error)
	FetchAllDevices(ctx context.Context) (ds []Device, err error)
	FetchAllRelations(ctx context.Context) ([]Relation, error)
	DeleteDeviceByID(ctx context.Context, deviceID uuid.UUID) error
	DeleteRelation(ctx context.Context, rel Relation) error
}

func NewMemoryStore

func NewMemoryStore() Store

func NewSQLStore

func NewSQLStore(db *pgx.Conn) (Store, error)

Jump to

Keyboard shortcuts

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