models

package
v1.10.4-0...-52d5685 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2020 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageDataMaxSize      = 512000
	MessageSignatureMaxSize = 10000
)
View Source
const (
	TokenTTL = time.Minute * 30
	CacheTTL = time.Minute * 120
)

Variables

This section is empty.

Functions

func Create

func Create(v interface{}) *gorm.DB

func Setup

func Setup() (err error)

func Update

func Update(v interface{}) *gorm.DB

func UpdateFields

func UpdateFields(v interface{}, fields map[string]interface{}) *gorm.DB

func ValidateMessage

func ValidateMessage(data, signature string) error

Types

type AccessPoint

type AccessPoint struct {
	gorm.Model

	UnitID uint   `json:"-"`
	Name   string `gorm:"size:255;not null" json:"name"`
	Mac    string `gorm:"size:255;not null" json:"mac"`
}

type EnrollmentRequest

type EnrollmentRequest struct {
	Identity    string                 `json:"identity"`   // name@SHA256(public_key)
	PublicKey   string                 `json:"public_key"` // BASE64(public_key.pem)
	Signature   string                 `json:"signature"`  // BASE64(SIGN(identity, private_key))
	Data        map[string]interface{} `json:"data"`       // misc data for the unit
	KeyPair     *crypto.KeyPair        `json:"-"`          // parsed from public_key
	Name        string                 `json:"-"`
	Fingerprint string                 `json:"-"` // SHA256(public_key)
	Address     string                 `json:"-"`
	Country     string                 `json:"-"`
}

func (*EnrollmentRequest) Validate

func (enroll *EnrollmentRequest) Validate() error

type Message

type Message struct {
	ID         uint       `gorm:"primary_key" json:"id"`
	CreatedAt  time.Time  `json:"created_at"`
	UpdatedAt  time.Time  `json:"updated_at"`
	DeletedAt  *time.Time `sql:"index" json:"deleted_at"`
	SeenAt     *time.Time `json:"seen_at" sql:"index"`
	SenderID   uint       `json:"-"`
	ReceiverID uint       `json:"-"`
	SenderName string     `gorm:"size:255" json:"sender_name"`
	Sender     string     `gorm:"size:255;not null" json:"sender"`
	Data       string     `gorm:"size:512000;not null" json:"-"`
	Signature  string     `gorm:"size:10000;not null" json:"-"`
}

type Unit

type Unit struct {
	ID          uint       `gorm:"primary_key" json:"-"`
	CreatedAt   time.Time  `json:"enrolled_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
	DeletedAt   *time.Time `sql:"index" json:"-"`
	Address     string     `gorm:"size:50;not null" json:"-"`
	Country     string     `gorm:"size:10" json:"country"`
	Name        string     `gorm:"size:255;not null" json:"name"`
	Fingerprint string     `gorm:"size:255;not null;unique" json:"fingerprint"`
	PublicKey   string     `gorm:"size:10000;not null" json:"public_key"`
	Token       string     `gorm:"size:10000;not null" json:"-"`
	Data        string     `gorm:"size:10000;not null" json:"data"`

	AccessPoints []AccessPoint `gorm:"foreignkey:UnitID" json:"-"`

	Inbox []Message `gorm:"foreignkey:ReceiverID" json:"-"`
	Sent  []Message `gorm:"foreignkey:SenderID" json:"-"`
}

func EnrollUnit

func EnrollUnit(enroll EnrollmentRequest) (err error, unit *Unit)

func FindUnit

func FindUnit(id uint) *Unit

func FindUnitByFingerprint

func FindUnitByFingerprint(fingerprint string) *Unit

func GetPagedUnits

func GetPagedUnits(page int) (units []Unit, total int, pages int)

func (Unit) FindAccessPoint

func (u Unit) FindAccessPoint(essid, bssid string) *AccessPoint

func (*Unit) GetInboxMessage

func (u *Unit) GetInboxMessage(id int) *Message

func (*Unit) GetPagedInbox

func (u *Unit) GetPagedInbox(page int) (messages []Message, total int, pages int)

func (Unit) Identity

func (u Unit) Identity() string

func (*Unit) MarshalJSON

func (u *Unit) MarshalJSON() ([]byte, error)

func (*Unit) UpdateWith

func (u *Unit) UpdateWith(enroll EnrollmentRequest) error

type UnitsByCountry

type UnitsByCountry struct {
	Country string `json:"country"`
	Count   int    `json:"units"`
}

func GetUnitsByCountry

func GetUnitsByCountry() ([]UnitsByCountry, error)

Jump to

Keyboard shortcuts

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