model

package
v0.0.0-...-8508dec Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 10 Imported by: 6

Documentation

Overview

Copyright 2023 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2023 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Index

Constants

View Source
const (
	AttrScopeInventory = "inventory"
	AttrScopeIdentity  = "identity"
	AttrScopeSystem    = "system"
	AttrScopeTags      = "tags"
	AttrScopeMonitor   = "monitor"

	AttrNameID             = "id"
	AttrNameGroup          = "group"
	AttrNameUpdated        = "updated_ts"
	AttrNameCreated        = "created_ts"
	AttrNameTagsEtag       = "tags_etag"
	AttrNameNumberOfAlerts = "alert_count"
	AttrNameAlerts         = "alerts"
)

Variables

This section is empty.

Functions

func GetDeviceAttributeNameReplacer

func GetDeviceAttributeNameReplacer() *strings.Replacer

Types

type Device

type Device struct {
	//system-generated device ID
	ID DeviceID `json:"id" bson:"_id,omitempty"`

	//a map of attributes names and their values.
	Attributes DeviceAttributes `json:"attributes,omitempty" bson:"attributes,omitempty"`

	//device's group name
	Group GroupName `json:"-" bson:"group,omitempty"`

	CreatedTs time.Time `json:"-" bson:"created_ts,omitempty"`
	//Timestamp of the last attribute update.
	UpdatedTs *time.Time `json:"updated_ts,omitempty" bson:"updated_ts,omitempty"`

	//device object revision
	Revision uint `json:"-" bson:"revision,omitempty"`

	//tags attributes ETag
	TagsEtag string `json:"-" bson:"tags_etag,omitempty"`

	//text attribute for the full-text search
	Text string `json:"-" bson:"text,omitempty"`
}

Device wrapper

func (Device) MarshalBSON

func (d Device) MarshalBSON() ([]byte, error)

func (*Device) UnmarshalBSON

func (d *Device) UnmarshalBSON(b []byte) error

func (Device) Validate

func (d Device) Validate() error

type DeviceAttribute

type DeviceAttribute struct {
	Name        string      `json:"name" bson:",omitempty"`
	Description *string     `json:"description,omitempty" bson:",omitempty"`
	Value       interface{} `json:"value" bson:",omitempty"`
	Scope       string      `json:"scope" bson:",omitempty"`
	Timestamp   *time.Time  `json:"timestamp,omitempty" bson:",omitempty"`
}

func (DeviceAttribute) Validate

func (da DeviceAttribute) Validate() error

type DeviceAttributes

type DeviceAttributes []DeviceAttribute

wrapper for device attributes names and values

func (DeviceAttributes) MarshalBSONValue

func (d DeviceAttributes) MarshalBSONValue() (bsontype.Type, []byte, error)

MarshalBSONValue marshals the DeviceAttributes to a mongo-compatible document. That is, each attribute is given a unique field consisting of "<scope>-<name>".

func (DeviceAttributes) MarshalJSON

func (d DeviceAttributes) MarshalJSON() ([]byte, error)

MarshalJSON ensures that an empty array is returned if DeviceAttributes is empty.

func (*DeviceAttributes) UnmarshalBSONValue

func (d *DeviceAttributes) UnmarshalBSONValue(t bsontype.Type, b []byte) error

UnmarshalBSONValue correctly unmarshals DeviceAttributes from Device documents stored in the DB.

func (*DeviceAttributes) UnmarshalJSON

func (d *DeviceAttributes) UnmarshalJSON(b []byte) error

func (DeviceAttributes) Validate

func (d DeviceAttributes) Validate() error

type DeviceGroups

type DeviceGroups struct {
	Groups []string `json:"groups" bson:"-"`
}

type DeviceID

type DeviceID string
var NilDeviceID DeviceID //TODO: how to make it NilDeviceID:=DeviceID(primitive.NilObjectID)

func (DeviceID) String

func (did DeviceID) String() string

type DeviceUpdate

type DeviceUpdate struct {
	Id       DeviceID `json:"id"`
	Revision uint     `json:"revision"`
}

type Filter

type Filter struct {
	Id    string            `json:"id" bson:"_id"`
	Name  string            `json:"name" bson:"name"`
	Terms []FilterPredicate `json:"terms" bson:"terms"`
}

func (Filter) Validate

func (f Filter) Validate() error

type FilterAttribute

type FilterAttribute struct {
	Name  string `json:"name" bson:"name"`
	Scope string `json:"scope" bson:"scope"`
	Count int32  `json:"count" bson:"count"`
}

type FilterPredicate

type FilterPredicate struct {
	Scope     string      `json:"scope" bson:"scope"`
	Attribute string      `json:"attribute" bson:"attribute"`
	Type      string      `json:"type" bson:"type"`
	Value     interface{} `json:"value" bson:"value"`
}

func (FilterPredicate) Validate

func (f FilterPredicate) Validate() error

type GroupName

type GroupName string

func (GroupName) String

func (gn GroupName) String() string

func (GroupName) Validate

func (gn GroupName) Validate() error

type NewTenant

type NewTenant struct {
	ID string
}

type SearchParams

type SearchParams struct {
	Page       int               `json:"page"`
	PerPage    int               `json:"per_page"`
	Filters    []FilterPredicate `json:"filters"`
	Sort       []SortCriteria    `json:"sort"`
	Attributes []SelectAttribute `json:"attributes"`
	DeviceIDs  []string          `json:"device_ids"`
	Text       string            `json:"text"`
}

func (SearchParams) Validate

func (sp SearchParams) Validate() error

type SelectAttribute

type SelectAttribute struct {
	Scope     string `json:"scope" bson:"scope"`
	Attribute string `json:"attribute" bson:"attribute"`
}

type SortCriteria

type SortCriteria struct {
	Scope     string `json:"scope"`
	Attribute string `json:"attribute"`
	Order     string `json:"order"`
}

type UpdateResult

type UpdateResult struct {
	MatchedCount int64     `json:"matched_count,omitempty"`
	UpdatedCount int64     `json:"updated_count,omitempty"`
	CreatedCount int64     `json:"created_count,omitempty"`
	DeletedCount int64     `json:"deleted_count,omitempty"`
	Devices      []*Device `json:"-"`
}

Jump to

Keyboard shortcuts

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