model

package
v0.0.0-...-7c66ffc Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package model contains the data model for the Horde internals

Index

Constants

View Source
const (
	DisabledManagement   = FirmwareManagementSetting(' ')
	CollectionManagement = FirmwareManagementSetting('c')
	DeviceManagement     = FirmwareManagementSetting('d')
)

The various firmware management settings.

View Source
const (
	// UDPTransport is upstream UDP
	UDPTransport = MessageTransport(0)
	// CoAPTransport is uses CaAP and is sent unsolicited to the device, ie
	// it's not part of a GET request from the device.
	CoAPTransport = MessageTransport(1)
	// CoAPPullTransport is CoAP but the client pulls the message. This is
	// is useful if you want a device to retrieve the CoAP messages itself
	// f.e. when there's power saving modes running or you can't run a full
	// blown CoAP server on the device.
	CoAPPullTransport = MessageTransport(2)
	// UDPPullTransport sends the UDP message in response when the client has
	// sent an upstream message. This can be useful if the device is in some
	// kind of power save mode and you want to schedule a message for later
	// There is no guarantee *when* the message will be delivered
	UDPPullTransport = MessageTransport(3)

	UnknownTransport = MessageTransport(999)
)

Note that iota might be tempting here but the transport is persisted so the order of the transports should not matter.

View Source
const (
	Unknown      = DeviceFirmwareState(' ') // Unknown state
	Current      = DeviceFirmwareState('c') // The firmware is current. This is the default state
	Initializing = DeviceFirmwareState('i') // The firmware update has started
	Pending      = DeviceFirmwareState('p') // A firmware update is pending
	Downloading  = DeviceFirmwareState('d') // Firmware is downloading to the device
	Completed    = DeviceFirmwareState('u') // Device has downloaded and written the firmware
	UpdateFailed = DeviceFirmwareState('f') // Update operation has failed
	TimedOut     = DeviceFirmwareState('t') // Update timed out
	Reverted     = DeviceFirmwareState('r') // Device was updated but did not report the updated version
)

Firmware states for devices

View Source
const (
	// IMSIMask is the mask bit for the IMSI field on devices (b0001)
	IMSIMask = FieldMask(1) << iota
	// IMEIMask is the mask bit for the IMEI field on devices (b0010)
	IMEIMask
	// LocationMask is the mask bit for locations on devices (b0100)
	LocationMask
	// MSISDNMask is the mask bit for the MSISDNs on devices (b1000). This isn't
	// currently in use but for political reasons (tm) it is included.
	MSISDNMask
)

Variables

View Source
var (
	// AdminRole is the administrator role, ie with full access
	AdminRole = RoleID(1)
	// MemberRole is the member role, ie a member without administrative privileges
	MemberRole = RoleID(0)
)

Functions

func FieldNames

func FieldNames(v FieldMask) []string

FieldNames returns the bits that are set as an array of strings. The list contains human-readable names

func ValidInviteCode

func ValidInviteCode(code string) bool

ValidInviteCode checks if the code is valid

Types

type APN

type APN struct {
	ID   int
	Name string
}

APN is the APN configuration.

func NewAPN

func NewAPN(id int) APN

NewAPN creates a new APN instance

type Allocation

type Allocation struct {
	IP      net.IP
	IMSI    int64
	IMEI    int64
	ApnID   int
	NasID   int
	Created time.Time
}

Allocation represents an IP allocation

type AuthMethod

type AuthMethod int

AuthMethod is an enum for authentication methods

const (
	// AuthNone is "no auth method"
	AuthNone AuthMethod = iota

	// AuthGitHub is for GitHub authentication
	AuthGitHub

	// AuthConnectID is for CONNECT ID authentication
	AuthConnectID

	// AuthInternal is internal users. These are created through the management
	// API and have no external authentication. These users have a single API
	// token and nothing else.
	AuthInternal

	// AuthToken is token authentication
	AuthToken
)

func (AuthMethod) Login

func (a AuthMethod) Login() bool

Login returns true if the user is authenticated via some sort of login, ie not via tokens or internal methods. Some API resources will need regular logins (like the token management bits, managing tokens via tokens introduces corner cases and potential security risks so we require a logged-in user to manage the tokens)

type CoAPMetaData

type CoAPMetaData struct {
	Code string
	Path string
}

CoAPMetaData holds metadata for messages received on the CoAP interface

type Collection

type Collection struct {
	ID        CollectionKey
	TeamID    TeamKey
	FieldMask FieldMask
	Firmware  CollectionFirmwareMetadata
	Tags
}

Collection is a collection of devices. The name might be a bit generic but we have only *one* type of collection in the system -- the one with devices.

func NewCollection

func NewCollection() Collection

NewCollection creates a new collection

type CollectionFirmwareMetadata

type CollectionFirmwareMetadata struct {
	CurrentFirmwareID FirmwareKey
	TargetFirmwareID  FirmwareKey
	Management        FirmwareManagementSetting
}

CollectionFirmwareMetadata is the firmware settings for the collections. If the management is set to disabled or device the version fields will be ignored.

func NewCollectionFirmwareMetadata

func NewCollectionFirmwareMetadata() CollectionFirmwareMetadata

NewCollectionFirmwareMetadata creates a new empty metadata setting

type CollectionKey

type CollectionKey storageKey

CollectionKey is the identifer for Collection instances

func NewCollectionKeyFromString

func NewCollectionKeyFromString(id string) (CollectionKey, error)

NewCollectionKeyFromString creates a new CollectionKey from a string

func (CollectionKey) String

func (c CollectionKey) String() string

String returns the string representation of the key

type DataMessage

type DataMessage struct {
	Device    Device
	Received  time.Time
	Payload   []byte
	Transport MessageTransport
	UDP       UDPMetaData
	CoAP      CoAPMetaData
}

DataMessage is the type for messages passed to and from devices. Final content is TBD.

func NewDataMessage

func NewDataMessage(device Device, payload []byte, transport MessageTransport, udp UDPMetaData, coap CoAPMetaData) DataMessage

NewDataMessage creates a new DataMessage instance.

type Device

type Device struct {
	ID           DeviceKey
	IMSI         int64
	IMEI         int64
	CollectionID CollectionKey
	Network      DeviceNetworkMetadata
	Firmware     DeviceFirmwareMetadata
	Tags
}

Device is the entity that represent actual NB-IoT devices.

func NewDevice

func NewDevice() Device

NewDevice creates a new empty device

type DeviceFirmwareMetadata

type DeviceFirmwareMetadata struct {
	CurrentFirmwareID FirmwareKey // The current firmware version installed. 0 if it isn't set or is unknown
	TargetFirmwareID  FirmwareKey // The desired version of the firmware for the device. It might be the same as the current version
	FirmwareVersion   string      // From the device information resource
	SerialNumber      string      // From the device information resource
	ModelNumber       string      // From the device information resource
	Manufacturer      string      // From the device information resource
	State             DeviceFirmwareState
	StateMessage      string
}

DeviceFirmwareMetadata contains internal metadata about devices. The information is for internal housekeeping mostly and *might* be relevant for devices. The information is pulled from the LwM2M responses from the device.

type DeviceFirmwareState

type DeviceFirmwareState rune

DeviceFirmwareState is the state for the firmware update cycle. If the device is in the TimedOut or Rollback state it won't be updated. The state is changed to "pending" whenever the target firmware id is set on the device

func (DeviceFirmwareState) IsError

func (d DeviceFirmwareState) IsError() bool

IsError returns true if the firmware state represents an error

func (DeviceFirmwareState) String

func (d DeviceFirmwareState) String() string

type DeviceKey

type DeviceKey storageKey

DeviceKey is the identifier for Device instances

func NewDeviceKeyFromString

func NewDeviceKeyFromString(id string) (DeviceKey, error)

NewDeviceKeyFromString creates a new DeviceKey from a string representation

func (DeviceKey) String

func (d DeviceKey) String() string

String returns the string representation of the DeviceKey instance

type DeviceNetworkMetadata

type DeviceNetworkMetadata struct {
	AllocatedIP string
	AllocatedAt time.Time
	CellID      int64
	ApnID       int
	NasID       int
}

DeviceNetworkMetadata is the current state of the device.

type DownstreamMessage

type DownstreamMessage struct {
	ID        MessageKey       // ID of message
	ApnID     int              // APN ID (may be invalid if the message is cached by the core service)
	NasID     int              // APN ID
	IMSI      int64            // IMSI for destination device
	Transport MessageTransport // Transport to use
	Port      int              // Port number to use (UDP or CoAP)
	Path      string           // Path (CoAP)
	Payload   []byte           // Payload of message
}

DownstreamMessage is a downstream message; ie a message that should be sent to devices.

type ErrorMessage

type ErrorMessage map[string]string

ErrorMessage is error messages for end users. These are ideally a part of the entities package elsewhere since it *strictly* isn't a part of the model package but it is used in several other packages as well.

The error messages are presented as a JSON with field names and messages, ie a regular map.

type FieldMask

type FieldMask uint

FieldMask is the field masking bit used to mask fields

func (FieldMask) Apply

func (b FieldMask) Apply(systemMask FieldMask) FieldMask

Apply combines two field masks

func (FieldMask) IsSet

func (b FieldMask) IsSet(bit FieldMask) bool

IsSet checks if a field mask bit is set

func (*FieldMask) Set

func (b *FieldMask) Set(bit FieldMask, editMask FieldMask, set bool)

Set sets a single bit field

type FieldMaskParameters

type FieldMaskParameters struct {
	Forced  string `param:"desc=Read-only field mask for device fields"`
	Default string `param:"desc=Default field mask for device fields;default=location"`
}

FieldMaskParameters contains the system configuration for the field masks; system defaults and edit mask. The edit mask sets the allowed edits, in practice making the field mask read only for certain fields.

The EditMask field has bits set for all fields that must be masked, ie if set to 0xFFFF all fields will be masked and the API clients are unable to modfiy the mask

func (*FieldMaskParameters) DefaultFields

func (f *FieldMaskParameters) DefaultFields() FieldMask

DefaultFields returns the default field mask

func (*FieldMaskParameters) ForcedFields

func (f *FieldMaskParameters) ForcedFields() FieldMask

ForcedFields returns the field mask for forced fields

func (*FieldMaskParameters) Valid

func (f *FieldMaskParameters) Valid() error

Valid validates the forced and default field masks. The default field mask must be equal or more restrictive than the forced field mask.

type Firmware

type Firmware struct {
	ID           FirmwareKey // Image ID
	Version      string      // Unique for collection
	Filename     string      // Original file name - for informational purposes only
	Length       int         // Size of image (in bytes)
	SHA256       string      // SHA256 checksum of image. Computed when uploading. 64 hex characters (and 32 byte)
	Created      time.Time   // Time the image was created
	CollectionID CollectionKey
	Tags
}

Firmware is the metadata for a firmware image. Most fields are immutable, except the TeamID and Tags.

func NewFirmware

func NewFirmware() Firmware

NewFirmware creates a new empty Firmware instance

type FirmwareConfig

type FirmwareConfig struct {
	Management               FirmwareManagementSetting
	CollectionCurrentVersion FirmwareKey
	CollectionTargetVersion  FirmwareKey
	DeviceCurrentVersion     FirmwareKey
	DeviceTargetVersion      FirmwareKey
}

FirmwareConfig is a meta-type for firmware config; the fields are gathered into one type for convenience.

func (*FirmwareConfig) CurrentVersion

func (f *FirmwareConfig) CurrentVersion() FirmwareKey

CurrentVersion returns the currently running firmware version (or the one it should be running right now)

func (*FirmwareConfig) NeedsUpgrade

func (f *FirmwareConfig) NeedsUpgrade() bool

NeedsUpgrade returns true if the firmware should be upgraded

func (*FirmwareConfig) TargetVersion

func (f *FirmwareConfig) TargetVersion() FirmwareKey

TargetVersion runs the target firmware version

type FirmwareKey

type FirmwareKey storageKey

FirmwareKey is the identifier for firmware images

func NewFirmwareKeyFromString

func NewFirmwareKeyFromString(id string) (FirmwareKey, error)

NewFirmwareKeyFromString converts a string into a FirmwareKey

func (FirmwareKey) String

func (f FirmwareKey) String() string

type FirmwareManagementSetting

type FirmwareManagementSetting rune

FirmwareManagementSetting is the firmware management setting for the collection

type FirmwareUse

type FirmwareUse struct {
	FirmwareID FirmwareKey
	Current    []DeviceKey
	Targeted   []DeviceKey
}

FirmwareUse shows the firmware images in use for a collection

type Invite

type Invite struct {
	Code    string
	UserID  UserKey
	TeamID  TeamKey
	Created time.Time
}

Invite is a code, a creation date and an inviter (aka UserID)

func NewInvite

func NewInvite(user UserKey, team TeamKey) (Invite, error)

NewInvite creates a new invite

type Member

type Member struct {
	Role RoleID
	User User // For caching
}

Member is a (single) member in a team

func NewMember

func NewMember(user User, roleID RoleID) Member

NewMember creates a new Member instance

type MessageKey

type MessageKey storageKey

MessageKey is an identifier for messages

func NewMessageKeyFromString

func NewMessageKeyFromString(id string) (MessageKey, error)

NewMessageKeyFromString creates a new MessageKey from a string

func (MessageKey) String

func (m MessageKey) String() string

String returns the string representation of the message ID

type MessageTransport

type MessageTransport int

MessageTransport is the transport for (upstream) messages

func MessageTransportFromString

func MessageTransportFromString(s string) MessageTransport

MessageTransportFromString returns the MessageTransport type that matches. If nothing matches the unknown transport type is returned

func (MessageTransport) String

func (m MessageTransport) String() string

String returns the string representation of the transport

type NAS

type NAS struct {
	ID         int
	Identifier string
	CIDR       string
	ApnID      int
	// contains filtered or unexported fields
}

NAS represents a NAS with a range.

type NASRanges

type NASRanges struct {
	APN    APN
	Ranges []NAS
}

NASRanges is a helper struct to hold both APN ID and a collection of NAS IDs. This represents a *single* APN and not all available APNs TODO(stalehd): Remove this when ingres listeners are completed.

func NewNASRanges

func NewNASRanges(apnID int, name string, nasID int, identifier string, cidr string) NASRanges

NewNASRanges creates a new NASRanges instance

func (*NASRanges) ByIP

func (n *NASRanges) ByIP(ip net.IP) (NAS, bool)

ByIP locates the NAS by the IP address

func (*NASRanges) Find

func (n *NASRanges) Find(nasID int) (NAS, bool)

Find locates the matching NAS

func (*NASRanges) GetNasID

func (n *NASRanges) GetNasID(identifier string) int

GetNasID returns the NAS ID for the NAS identifier. It will return -1 if the identifier isn't found

type Output

type Output struct {
	ID                  OutputKey
	Type                string
	Config              OutputConfig
	CollectionID        CollectionKey
	Enabled             bool
	CollectionFieldMask FieldMask
	Tags
}

Output is data streams from outputs. Note that the CollectionFieldMask is not a field on the output table but for simplicity's sake this is retrieved with the rest of the output object.

func NewOutput

func NewOutput() Output

NewOutput creates a new Output instance

type OutputConfig

type OutputConfig map[string]interface{}

OutputConfig is a map of configuration values

func NewOutputConfig

func NewOutputConfig() OutputConfig

NewOutputConfig creates a new output configuration

func (OutputConfig) HasParameterOfType

func (o OutputConfig) HasParameterOfType(name string, expectedType reflect.Kind) (bool, bool)

HasParameterOfType checks if the parameter exists and if type type is correct

func (*OutputConfig) Scan

func (o *OutputConfig) Scan(src interface{}) error

Scan implements the sql.Scanner interface (to read from db fields). This makes it possible to write to and from the "tags" field in sql drivers

func (OutputConfig) Value

func (o OutputConfig) Value() (driver.Value, error)

Value implements the driver.Valuer interface (for writing to db fields)

type OutputKey

type OutputKey storageKey

OutputKey is the identifier for outputs

func NewOutputKeyFromString

func NewOutputKeyFromString(id string) (OutputKey, error)

NewOutputKeyFromString creates a new OutputKey from a string representation

func (OutputKey) String

func (d OutputKey) String() string

String returns the string representation of the DeviceKey instance

type OutputLogEntry

type OutputLogEntry struct {
	Message  string
	Time     time.Time
	Repeated uint8
}

OutputLogEntry is the log entries received from the outputs. Each output has a circular buffer with the 10 latest messages from the output. If there's multiple log messages with the same message repeated it will just have the Repeated field increased. Log entries are used by the end used to diagnose the output so the error messages should make sense for end users.

type OutputStatus

type OutputStatus struct {
	Forwarded   int
	Received    int
	ErrorCount  int
	Retransmits int
}

OutputStatus is used to report the internal state of the forwarder.

type RoleID

type RoleID uint8

RoleID is a single role.

func NewRoleIDFromString

func NewRoleIDFromString(s string) RoleID

NewRoleIDFromString converts a string into a role ID

func (RoleID) String

func (r RoleID) String() string

String returns the string representation of the role

type TagMapData

type TagMapData map[string]string

TagMapData is the tag types

func (*TagMapData) Scan

func (t *TagMapData) Scan(src interface{}) error

Scan implements the sql.Scanner interface (to read from db fields). This makes it possible to write to and from the "tags" field in sql drivers

func (TagMapData) Value

func (t TagMapData) Value() (driver.Value, error)

Value implements the driver.Valuer interface (for writing to db fields)

type Tags

type Tags struct {
	TagMap TagMapData
}

Tags are user-selectable attributes for entities.

func NewTags

func NewTags() Tags

NewTags makes a new Tags instance

func (*Tags) GetTag

func (t *Tags) GetTag(name string) string

GetTag returns the value of the property. If it doesnt't exist it will return a blank string

func (*Tags) IsValidTag

func (t *Tags) IsValidTag(name, value string) bool

IsValidTag checks if the name/value combination is valid

func (*Tags) SetTag

func (t *Tags) SetTag(name, value string)

SetTag sets a value. If the name already exists it will be overwritten. If the value is empty it will be removed

func (*Tags) SetTags

func (t *Tags) SetTags(other map[string]string)

SetTags replaces all tags

func (*Tags) TagData

func (t *Tags) TagData() map[string]string

TagData returns the tags as a map

func (*Tags) TagExists

func (t *Tags) TagExists(name string) bool

TagExists returns true if the named value exists

type Team

type Team struct {
	ID      TeamKey
	Members []Member
	Tags
}

The Team type is a group of users

func NewTeam

func NewTeam() Team

NewTeam creates a new Team instace

func (*Team) AddMember

func (t *Team) AddMember(newMember Member) bool

AddMember adds member to team. Not thread safe

func (*Team) GetMember

func (t *Team) GetMember(userID UserKey) Member

GetMember returns the member with the specified user ID. An empty member entity is returned if the member doesn't exist.

func (*Team) IsAdmin

func (t *Team) IsAdmin(userID UserKey) bool

IsAdmin returns true if user is admin of team. Not thread safe

func (*Team) IsMember

func (t *Team) IsMember(userID UserKey) bool

IsMember returns true if the specified user ID is a member of the team. Not thread safe.

func (*Team) RemoveMember

func (t *Team) RemoveMember(userID UserKey)

RemoveMember removes the user from the member list

func (*Team) UpdateMember

func (t *Team) UpdateMember(userID UserKey, roleID RoleID)

UpdateMember updates a member's role if the user exists

type TeamKey

type TeamKey storageKey

TeamKey is the ID for the team type

func NewTeamKeyFromString

func NewTeamKeyFromString(id string) (TeamKey, error)

NewTeamKeyFromString parses a key as a string

func (TeamKey) String

func (t TeamKey) String() string

String returns the string representation of the TeamKey

type Token

type Token struct {
	UserID   UserKey
	Resource string
	Write    bool
	Token    string
	Tags
}

Token is access tokens for the REST API

func NewToken

func NewToken() Token

NewToken creates a new token

func (*Token) GenerateToken

func (t *Token) GenerateToken() error

GenerateToken generates a new token. Note that this will overwrite the existing token

type UDPMetaData

type UDPMetaData struct {
	LocalPort  int
	RemotePort int
}

UDPMetaData holds metadata for messages received via UDP

type User

type User struct {
	ID            UserKey // User ID
	Email         string  // Always set for GH users
	Phone         string  // Not used by GH
	Name          string  // Name of user
	ExternalID    string  // Identifier for CONNECT ID users
	Deleted       bool    // Deleted flag. Not used ATM
	VerifiedEmail bool    // Always true for GH users, possibly false for CONNECT ID users
	VerifiedPhone bool    // Always false for GH users
	AvatarURL     string  // Avatar URL (GH only; TD does not support avatars)
	PrivateTeamID TeamKey // The private team for the user
	AuthType      AuthMethod
}

User is the struct representing system users.

func NewUser

func NewUser(id UserKey, identifier string, authType AuthMethod, teamID TeamKey) User

NewUser creates a new User instance

type UserKey

type UserKey storageKey

UserKey is the key type for users

func NewUserKeyFromString

func NewUserKeyFromString(id string) (UserKey, error)

NewUserKeyFromString converts the string into a UserKey instance

func (UserKey) String

func (u UserKey) String() string

Jump to

Keyboard shortcuts

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