model

package
v0.0.0-...-24c5a16 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

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.

Index

Constants

View Source
const (
	ScopeInventory = "inventory"
	ScopeIdentity  = "identity"
	ScopeSystem    = "system"
	ScopeTags      = "tags"
	ScopeMonitor   = "monitor"
)

scope prefixes

View Source
const (
	AttrNameID                     = "id"
	AttrNameGroup                  = "group"
	AttrNameStatus                 = "status"
	AttrNameCreatedAt              = "created_ts"
	AttrNameUpdatedAt              = "updated_ts"
	AttrNameLatestDeploymentStatus = "latest_deployment_status"
	AttrNameGeoLatitude            = "geo-lat"
	AttrNameGeoLongitude           = "geo-lon"
)

attributes

View Source
const (
	FieldNameID               = "id"
	FieldNameDeploymentID     = "deployment_id"
	FieldNameDeviceID         = "device_id"
	FieldNameDeploymentGroups = "deployment_groups"
	FieldNameTenantID         = "tenant_id"
	FieldNameLocation         = "location"
	FieldNameCheckIn          = "check_in_time"
)
View Source
const (
	SortOrderAsc  = "asc"
	SortOrderDesc = "desc"
)
View Source
const (
	ServiceDeviceauth  = "deviceauth"
	ServiceMonitor     = "devicemonitor"
	ServiceInventory   = "inventory"
	ServiceDeployments = "deployments"
)
View Source
const (
	ActionReindex           = "reindex"
	ActionReindexDeployment = "reindex_deployment"
)
View Source
const MaxMappingInventoryAttributes = 100

Variables

View Source
var (
	ErrArrayNotSupported = errors.New("filter doesn't support array values")
	ErrArrayRequired     = errors.New("filter supports only array values")
	ErrStrRequired       = errors.New("filter supports only string values")
	ErrNumRequired       = errors.New("filter supports only numeric values")
	ErrBoolRequired      = errors.New("filter supports only boolean values")
)

Functions

func Dedot

func Dedot(name string) string

Dedot replaces '.' in a name to make it digestible by ES

func MaybeParseAttr

func MaybeParseAttr(field string) (string, string, error)

maybeParseAttr decides if a given field is an attribute and parses it's name + scope

func NewDeploymentsSelect

func NewDeploymentsSelect(attrs []DeploymentsSelectAttribute) *deploymentsSel

func NewDeploymentsSort

func NewDeploymentsSort(sc DeploymentsSortCriteria) *deploymentsSort

func NewDevIDsFilter

func NewDevIDsFilter(ids []string) *devIDsFilter

func NewFilter

func NewFilter(fp FilterPredicate, arrOpts ArrayOpts, typeOpts Type) (*filter, error)

func NewFilterEq

func NewFilterEq(fp FilterPredicate) (*filterEq, error)

func NewFilterExists

func NewFilterExists(fp FilterPredicate) (*filterExists, error)

func NewFilterIn

func NewFilterIn(fp FilterPredicate) (*filterIn, error)

func NewFilterNe

func NewFilterNe(fp FilterPredicate) (*filterNe, error)

func NewFilterNin

func NewFilterNin(fp FilterPredicate) (*filterNin, error)

func NewFilterRange

func NewFilterRange(fp FilterPredicate, op string) (*filterRange, error)

func NewFilterRegex

func NewFilterRegex(fp FilterPredicate) (*filterRegex, error)

func NewGeoFilters

func NewGeoFilters(df *GeoDistanceFilter, bf *GeoBoundingBoxFilter) *geoFilters

func NewSelect

func NewSelect(attrs []SelectAttribute) *sel

func NewSort

func NewSort(sc SortCriteria) *sort

func Redot

func Redot(name string) string

Redot reverses dedotting

func ToAttr

func ToAttr(scope, name string, typ Type) string

toAttr composes the flat-style attribute name based on scope, name, and type

Types

type AggregateDeploymentsParams

type AggregateDeploymentsParams struct {
	Aggregations     []DeploymentsAggregationTerm `json:"aggregations"`
	Filters          []DeploymentsFilterPredicate `json:"filters"`
	DeploymentGroups []string                     `json:"-"`
	TenantID         string                       `json:"-"`
}

func (AggregateDeploymentsParams) Validate

func (sp AggregateDeploymentsParams) Validate() error

type AggregateParams

type AggregateParams struct {
	Aggregations         []AggregationTerm     `json:"aggregations"`
	Filters              []FilterPredicate     `json:"filters"`
	GeoDistanceFilter    *GeoDistanceFilter    `json:"geo_distance_filter"`
	GeoBoundingBoxFilter *GeoBoundingBoxFilter `json:"geo_bounding_box_filter"`
	Groups               []string              `json:"-"`
	TenantID             string                `json:"-"`
}

func (AggregateParams) Validate

func (ap AggregateParams) Validate() error

type AggregationTerm

type AggregationTerm struct {
	Name         string            `json:"name"`
	Attribute    string            `json:"attribute"`
	Scope        string            `json:"scope"`
	Limit        int               `json:"limit"`
	Aggregations []AggregationTerm `json:"aggregations"`
}

func (AggregationTerm) Validate

func (f AggregationTerm) Validate() error

type Aggregations

type Aggregations map[string]interface{}

func BuildAggregations

func BuildAggregations(terms []AggregationTerm) (*Aggregations, error)

func BuildDeploymentsAggregations

func BuildDeploymentsAggregations(terms []DeploymentsAggregationTerm) (*Aggregations, error)

type ArrayOpts

type ArrayOpts int
const (
	ArrNotAllowed ArrayOpts = iota
	ArrAllowed
	ArrRequired
)

type BoundingBox

type BoundingBox struct {
	TopLeft     *GeoPoint `json:"top_left" bson:"top_left"`
	BottomRight *GeoPoint `json:"bottom_right" bson:"bottom_right"`
}

func (BoundingBox) Validate

func (bb BoundingBox) Validate() error

type Deployment

type Deployment struct {
	ID                          string                 `json:"id"`
	TenantID                    string                 `json:"tenant_id"`
	DeviceID                    string                 `json:"device_id"`
	DeploymentID                string                 `json:"deployment_id"`
	DeploymentName              string                 `json:"deployment_name"`
	DeploymentArtifactName      string                 `json:"deployment_artifact_name"`
	DeploymentType              string                 `json:"deployment_type"`
	DeploymentCreated           *time.Time             `json:"deployment_created"`
	DeploymentFilterID          string                 `json:"deployment_filter_id,omitempty"`
	DeploymentAllDevices        bool                   `json:"deployment_all_devices"`
	DeploymentForceInstallation bool                   `json:"deployment_force_installation"`
	DeploymentGroups            []string               `json:"deployment_groups,omitempty"`
	DeploymentPhased            bool                   `json:"deployment_phased"`
	DeploymentPhaseId           string                 `json:"deployment_phase_id,omitempty"`
	DeploymentRetries           uint                   `json:"deployment_retries"`
	DeploymentMaxDevices        uint                   `json:"deployment_max_devices"`
	DeploymentAutogenerateDelta bool                   `json:"deployment_autogenerate_deta"`
	DeviceCreated               *time.Time             `json:"device_created"`
	DeviceFinished              *time.Time             `json:"device_finished"`
	DeviceElapsedSeconds        uint                   `json:"device_elapsed_seconds"`
	DeviceDeleted               *time.Time             `json:"device_deleted,omitempty"`
	DeviceStatus                string                 `json:"device_status"`
	DeviceIsLogAvailable        bool                   `json:"device_is_log_available"`
	DeviceRetries               uint                   `json:"device_retries"`
	DeviceAttempts              uint                   `json:"device_attempts"`
	ImageID                     string                 `json:"image_id,omitempty"`
	ImageDescription            string                 `json:"image_description,omitempty"`
	ImageArtifactName           string                 `json:"image_artifact_name"`
	ImageDeviceTypes            []string               `json:"image_device_types"`
	ImageSigned                 bool                   `json:"image_signed"`
	ImageArtifactInfoFormat     string                 `json:"image_artifact_info_format,omitempty"`
	ImageArtifactInfoVersion    uint                   `json:"image_artifact_info_version,omitempty"`
	ImageProvides               map[string]string      `json:"image_provides,omitempty"`
	ImageDepends                map[string]interface{} `json:"image_depends,omitempty"`
	ImageClearsProvides         []string               `json:"image_clears_provides,omitempty"`
	ImageSize                   int64                  `json:"image_size,omitempty"`
}

type DeploymentsAggregationTerm

type DeploymentsAggregationTerm struct {
	Name         string                       `json:"name"`
	Attribute    string                       `json:"attribute"`
	Limit        int                          `json:"limit"`
	Aggregations []DeploymentsAggregationTerm `json:"aggregations"`
}

func (DeploymentsAggregationTerm) Validate

func (f DeploymentsAggregationTerm) Validate() error

type DeploymentsFilterPredicate

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

func (DeploymentsFilterPredicate) Validate

func (f DeploymentsFilterPredicate) Validate() error

func (DeploymentsFilterPredicate) ValueType

func (f DeploymentsFilterPredicate) ValueType() (Type, bool, error)

ValueType returns actual type info of the value: type, is_array, err

type DeploymentsSearchParams

type DeploymentsSearchParams struct {
	Page             int                          `json:"page"`
	PerPage          int                          `json:"per_page"`
	Filters          []DeploymentsFilterPredicate `json:"filters"`
	Sort             []DeploymentsSortCriteria    `json:"sort"`
	Attributes       []DeploymentsSelectAttribute `json:"attributes"`
	DeviceIDs        []string                     `json:"device_ids"`
	DeploymentIDs    []string                     `json:"deployment_ids"`
	DeploymentGroups []string                     `json:"-"`
	TenantID         string                       `json:"-"`
}

func (DeploymentsSearchParams) Validate

func (sp DeploymentsSearchParams) Validate() error

type DeploymentsSelectAttribute

type DeploymentsSelectAttribute struct {
	Attribute string `json:"attribute" bson:"attribute"`
}

type DeploymentsSortCriteria

type DeploymentsSortCriteria struct {
	Attribute string `json:"attribute"`
	Order     string `json:"order"`
}

type Device

type Device struct {
	ID                  *string             `json:"id"`
	TenantID            *string             `json:"tenant_id,omitempty"`
	Location            *string             `json:"location,omitempty"`
	IdentityAttributes  InventoryAttributes `json:"identity_attributes,omitempty"`
	InventoryAttributes InventoryAttributes `json:"inventory_attributes,omitempty"`
	MonitorAttributes   InventoryAttributes `json:"monitor_attributes,omitempty"`
	SystemAttributes    InventoryAttributes `json:"system_attributes,omitempty"`
	TagsAttributes      InventoryAttributes `json:"tags_attributes,omitempty"`
	UpdatedAt           *time.Time          `json:"updated_at,omitempty"`
	LastCheckInDate     *time.Time          `json:"check_in_time,omitempty"`
}

func NewDevice

func NewDevice(tenantID, id string) *Device

func (*Device) AppendAttr

func (a *Device) AppendAttr(attr *InventoryAttribute) error

func (*Device) GetID

func (a *Device) GetID() string

func (*Device) GetTenantID

func (a *Device) GetTenantID() string

func (*Device) GetUpdatedAt

func (a *Device) GetUpdatedAt() time.Time

func (*Device) MarshalJSON

func (d *Device) MarshalJSON() ([]byte, error)

func (*Device) SetID

func (a *Device) SetID(val string) *Device

func (*Device) SetLastCheckIn

func (a *Device) SetLastCheckIn(val time.Time) *Device

func (*Device) SetTenantID

func (a *Device) SetTenantID(val string) *Device

func (*Device) SetUpdatedAt

func (a *Device) SetUpdatedAt(val time.Time) *Device

type DeviceAggregation

type DeviceAggregation struct {
	Name       string                  `json:"name"`
	Items      []DeviceAggregationItem `json:"items"`
	OtherCount int                     `json:"other_count"`
}

type DeviceAggregationItem

type DeviceAggregationItem struct {
	Key          string              `json:"key"`
	Count        int                 `json:"count"`
	Aggregations []DeviceAggregation `json:"aggregations,omitempty"`
}

type FilterAttribute

type FilterAttribute struct {
	Scope string `json:"scope"`
	Name  string `json:"name"`
	Count int    `json:"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

func (FilterPredicate) ValueType

func (f FilterPredicate) ValueType() (Type, bool, error)

ValueType returns actual type info of the value: type, is_array, err

type GeoBoundingBox

type GeoBoundingBox struct {
	Location BoundingBox `json:"location" bson:"location"`
}

func (GeoBoundingBox) Validate

func (gbb GeoBoundingBox) Validate() error

type GeoBoundingBoxFilter

type GeoBoundingBoxFilter struct {
	GeoBoundingBox GeoBoundingBox `json:"geo_bounding_box" bson:"geo_bounding_box"`
}

func (GeoBoundingBoxFilter) Validate

func (gbbf GeoBoundingBoxFilter) Validate() error

type GeoDistance

type GeoDistance struct {
	Distance string    `json:"distance" bson:"distance"`
	Location *GeoPoint `json:"location" bson:"location"`
}

func (GeoDistance) Validate

func (gd GeoDistance) Validate() error

type GeoDistanceFilter

type GeoDistanceFilter struct {
	GeoDistance GeoDistance `json:"geo_distance" bson:"geo_distance"`
}

func (GeoDistanceFilter) Validate

func (gdf GeoDistanceFilter) Validate() error

type GeoPoint

type GeoPoint struct {
	Latitude  *float32 `json:"lat" bson:"lat"`
	Longitude *float32 `json:"lon" bson:"lon"`
}

func (GeoPoint) Validate

func (gp GeoPoint) Validate() error

type InventoryAttribute

type InventoryAttribute struct {
	Scope   string
	Name    string
	String  []string
	Numeric []float64
	Boolean []bool
}

func NewInventoryAttribute

func NewInventoryAttribute(s string) *InventoryAttribute

func (*InventoryAttribute) IsBool

func (a *InventoryAttribute) IsBool() bool

func (*InventoryAttribute) IsNum

func (a *InventoryAttribute) IsNum() bool

func (*InventoryAttribute) IsStr

func (a *InventoryAttribute) IsStr() bool

func (*InventoryAttribute) Map

func (a *InventoryAttribute) Map() (string, interface{})

func (*InventoryAttribute) SetBoolean

func (a *InventoryAttribute) SetBoolean(val bool) *InventoryAttribute

func (*InventoryAttribute) SetBooleans

func (a *InventoryAttribute) SetBooleans(val []bool) *InventoryAttribute

func (*InventoryAttribute) SetName

func (a *InventoryAttribute) SetName(val string) *InventoryAttribute

func (*InventoryAttribute) SetNumeric

func (a *InventoryAttribute) SetNumeric(val float64) *InventoryAttribute

func (*InventoryAttribute) SetNumerics

func (a *InventoryAttribute) SetNumerics(val []float64) *InventoryAttribute

func (*InventoryAttribute) SetString

func (a *InventoryAttribute) SetString(val string) *InventoryAttribute

func (*InventoryAttribute) SetStrings

func (a *InventoryAttribute) SetStrings(val []string) *InventoryAttribute

func (*InventoryAttribute) SetVal

func (a *InventoryAttribute) SetVal(val interface{}) *InventoryAttribute

SetVal inspects the 'val' type and sets the correct subtype field useful for translating from inventory attributes (interface{})

type InventoryAttributes

type InventoryAttributes []*InventoryAttribute

type Job

type Job struct {
	Action       string `json:"action"`
	RequestID    string `json:"request_id"`
	TenantID     string `json:"tenant_id"`
	ID           string `json:"id"`
	DeviceID     string `json:"device_id"`
	DeploymentID string `json:"deployment_id"`
	Service      string `json:"service"`
}

type M

type M map[string]interface{}

type Mapping

type Mapping struct {
	TenantID  string   `json:"tenant_id" bson:"tenant_id"`
	Inventory []string `json:"inventory" bson:"inventory"`
}

type Query

type Query interface {
	Must(condition interface{}) Query
	MustNot(condition interface{}) Query
	WithSize(size int) Query
	WithSort(sort interface{}) Query
	WithPage(page, per_page int) Query
	With(parts map[string]interface{}) Query
	WithGeoFilters(df *GeoDistanceFilter, bf *GeoBoundingBoxFilter) Query

	MarshalJSON() ([]byte, error)
}

Query represents the ES query general form:

{
  "query": {
    "bool": {
      "must": [...conditions...],
      "must_not": [...conditions...],
    }
  "sort": [...],
  "from": ...,
  "size": ...,
}

it exposes an API for query parts to insert themselves in the right place

func BuildDeploymentsQuery

func BuildDeploymentsQuery(params DeploymentsSearchParams) (Query, error)

func BuildQuery

func BuildQuery(params SearchParams) (Query, error)

func NewQuery

func NewQuery() Query

type QueryPart

type QueryPart interface {
	AddTo(q Query) Query
}

QueryPart represents a bit of the ES query which knows how and where to insert itself

type S

type S []interface{}

type SearchParams

type SearchParams struct {
	Page                 int                   `json:"page"`
	PerPage              int                   `json:"per_page"`
	Filters              []FilterPredicate     `json:"filters"`
	GeoDistanceFilter    *GeoDistanceFilter    `json:"geo_distance_filter"`
	GeoBoundingBoxFilter *GeoBoundingBoxFilter `json:"geo_bounding_box_filter"`
	Sort                 []SortCriteria        `json:"sort"`
	Attributes           []SelectAttribute     `json:"attributes"`
	DeviceIDs            []string              `json:"device_ids"`
	Groups               []string              `json:"-"`
	TenantID             string                `json:"-"`
}

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 Type

type Type int

common enum for some type introspections we'll need

const (
	TypeAny Type = iota
	TypeStr
	TypeNum
	TypeBool
)

Jump to

Keyboard shortcuts

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