api

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAPINotEnabled      = errors.New("api not enabled")
	ErrInvalidAuthHeader  = errors.New("invalid auth header")
	ErrInvalidAPIKey      = errors.New("invalid api key")
	ErrInvalidSerialCount = errors.New("invalid serial count")
)

API errors

Functions

func SubmitHandler

func SubmitHandler(c *Context) http.Handler

SubmitHandler returns an http.Handler for submitHandler

Types

type Address

type Address struct {
	ID         int
	IP         string
	InternetIP string
}

Address represents a set of IP Addresses

type Cache

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

Cache is a cache id lookup by MD5 hash

func NewCache

func NewCache() *Cache

NewCache returns a new initialized cache

func (*Cache) Add

func (c *Cache) Add(h Hash, id int)

Add adds an entry to the cache

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all entries from th cache

func (*Cache) Delete

func (c *Cache) Delete(h Hash)

Delete removes an entry from the cache

func (*Cache) Get

func (c *Cache) Get(h Hash) int

Get returns an id by hash. If the entry doesn't exist, 0 is returned

func (*Cache) Visit

func (c *Cache) Visit(fn func(key Hash, val int))

Visit calls fn(key, val) for each entry in the cache. fn should not attempt any modifications to key or val, and should not call any methods on c

type Context

type Context struct {
	DB     *DB
	APIKey string
}

Context is a set of services accessed by endpoints

func (*Context) HandleQueryLastUser added in v1.3.0

func (c *Context) HandleQueryLastUser() http.Handler

HandleQueryLastUser returns the latest information for the submitted serials

type DB

type DB struct {
	DB *sql.DB

	WriteInterval time.Duration
	// contains filtered or unexported fields
}

DB represents a database

func NewDB

func NewDB(driver, dsn string, workers int, writeInterval time.Duration) (*DB, error)

NewDB creates a new DB with the given driver and dsn as used by database/sql's Open. workers specifies how many worker goroutines will be used

func (*DB) Push

func (db *DB) Push(e *Entry)

Push passes the entry onto the queue to be processed

func (*DB) QueryLastUser added in v1.3.0

func (db *DB) QueryLastUser(serials []string) ([]*Entry, error)

QueryLastUser returns the last information for serials

func (*DB) QueueLen

func (db *DB) QueueLen() int

QueueLen returns then length of the writer queue

type Device

type Device struct {
	ID               int
	Serial           string
	ClientIdentifier string
	Hostname         string
}

Device represents a device

type Entry

type Entry struct {
	UID              uint32    `json:"uid,omitempty"`
	Username         string    `json:"username"`
	FullName         string    `json:"full_name"`
	Serial           string    `json:"serial"`
	ClientIdentifier string    `json:"client_identifier,omitempty"`
	Hostname         string    `json:"hostname,omitempty"`
	IP               string    `json:"ip"`
	InternetIP       string    `json:"internet_ip,omitempty"`
	Time             time.Time `json:"time,omitempty"`
}

Entry represents information about a computer

func (*Entry) Hashes

func (e *Entry) Hashes() (user Hash, device Hash, address Hash, identity Hash)

Hashes generates and returns the user, device, address, and identity hashes for an Entry

func (*Entry) Validate

func (e *Entry) Validate() error

Validate checks that the given Entry's fields fit in the DB

type Hash

type Hash [md5.Size]byte

Hash is an MD5 hash

func NewHash

func NewHash(args ...string) Hash

NewHash returns a hashed MD5 Sum of the given strings

type Identity

type Identity struct {
	ID        int
	UserID    int
	DeviceID  int
	AddressID int
}

Identity represents a unique set of User, Device, and Address

type Insert

type Insert struct {
	*User
	*Device
	*Address
	*Identity
	*LogEntry

	UserHash     Hash
	DeviceHash   Hash
	AddressHash  Hash
	IdentityHash Hash

	UserID     int
	DeviceID   int
	AddressID  int
	IdentityID int
}

Insert represents a Decomposed Entry. If a field of Insert is nil, it already is in the database

type LogEntry

type LogEntry struct {
	ID         int64
	IdentityID int
	Time       time.Time
}

LogEntry represents an event

type User

type User struct {
	ID       int
	UID      uint32
	Username string
	FullName string
}

User represents a user

type ValidationError

type ValidationError string

ValidationError represents a field that is too long

func (ValidationError) Error

func (v ValidationError) Error() string

Jump to

Keyboard shortcuts

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