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
- Variables
- func Dedot(name string) string
- func MaybeParseAttr(field string) (string, string, error)
- func NewDeploymentsSelect(attrs []DeploymentsSelectAttribute) *deploymentsSel
- func NewDeploymentsSort(sc DeploymentsSortCriteria) *deploymentsSort
- func NewDevIDsFilter(ids []string) *devIDsFilter
- func NewFilter(fp FilterPredicate, arrOpts ArrayOpts, typeOpts Type) (*filter, error)
- func NewFilterEq(fp FilterPredicate) (*filterEq, error)
- func NewFilterExists(fp FilterPredicate) (*filterExists, error)
- func NewFilterIn(fp FilterPredicate) (*filterIn, error)
- func NewFilterNe(fp FilterPredicate) (*filterNe, error)
- func NewFilterNin(fp FilterPredicate) (*filterNin, error)
- func NewFilterRange(fp FilterPredicate, op string) (*filterRange, error)
- func NewFilterRegex(fp FilterPredicate) (*filterRegex, error)
- func NewGeoFilters(df *GeoDistanceFilter, bf *GeoBoundingBoxFilter) *geoFilters
- func NewSelect(attrs []SelectAttribute) *sel
- func NewSort(sc SortCriteria) *sort
- func Redot(name string) string
- func ToAttr(scope, name string, typ Type) string
- type AggregateDeploymentsParams
- type AggregateParams
- type AggregationTerm
- type Aggregations
- type ArrayOpts
- type BoundingBox
- type Deployment
- type DeploymentsAggregationTerm
- type DeploymentsFilterPredicate
- type DeploymentsSearchParams
- type DeploymentsSelectAttribute
- type DeploymentsSortCriteria
- type Device
- func (a *Device) AppendAttr(attr *InventoryAttribute) error
- func (a *Device) GetID() string
- func (a *Device) GetTenantID() string
- func (a *Device) GetUpdatedAt() time.Time
- func (d *Device) MarshalJSON() ([]byte, error)
- func (a *Device) SetID(val string) *Device
- func (a *Device) SetLastCheckIn(val time.Time) *Device
- func (a *Device) SetTenantID(val string) *Device
- func (a *Device) SetUpdatedAt(val time.Time) *Device
- type DeviceAggregation
- type DeviceAggregationItem
- type FilterAttribute
- type FilterPredicate
- type GeoBoundingBox
- type GeoBoundingBoxFilter
- type GeoDistance
- type GeoDistanceFilter
- type GeoPoint
- type InventoryAttribute
- func (a *InventoryAttribute) IsBool() bool
- func (a *InventoryAttribute) IsNum() bool
- func (a *InventoryAttribute) IsStr() bool
- func (a *InventoryAttribute) Map() (string, interface{})
- func (a *InventoryAttribute) SetBoolean(val bool) *InventoryAttribute
- func (a *InventoryAttribute) SetBooleans(val []bool) *InventoryAttribute
- func (a *InventoryAttribute) SetName(val string) *InventoryAttribute
- func (a *InventoryAttribute) SetNumeric(val float64) *InventoryAttribute
- func (a *InventoryAttribute) SetNumerics(val []float64) *InventoryAttribute
- func (a *InventoryAttribute) SetString(val string) *InventoryAttribute
- func (a *InventoryAttribute) SetStrings(val []string) *InventoryAttribute
- func (a *InventoryAttribute) SetVal(val interface{}) *InventoryAttribute
- type InventoryAttributes
- type Job
- type M
- type Mapping
- type Query
- type QueryPart
- type S
- type SearchParams
- type SelectAttribute
- type SortCriteria
- type Type
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 MaybeParseAttr ¶
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
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 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
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 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 (*Device) AppendAttr ¶
func (a *Device) AppendAttr(attr *InventoryAttribute) error
func (*Device) GetTenantID ¶
func (*Device) GetUpdatedAt ¶
func (*Device) MarshalJSON ¶
func (*Device) SetTenantID ¶
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 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 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 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 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)
type QueryPart ¶
QueryPart represents a bit of the ES query which knows how and where to insert itself
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 SortCriteria ¶
Click to show internal directories.
Click to hide internal directories.