model

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const ListOptionsModeDefault = "Default"
View Source
const ListOptionsModeListIds = "ListIds"
View Source
const ListOptionsModeSelection = "Selection"
View Source
const ListOptionsModeTextSearch = "TextSearch"
View Source
const PermissionMapping = `` /* 514-byte string literal not displayed */

Variables

View Source
var ErrAccessDenied = errors.New("access denied")
View Source
var ErrBadRequest = errors.New("bad request")
View Source
var ErrInvalidAuth = errors.New("invalid auth token")
View Source
var ErrNotFound = errors.New("not found")

Functions

func CreateMapping

func CreateMapping(config configuration.Config, kind string) (result map[string]interface{}, err error)

func GetErrCode

func GetErrCode(err error) (code int)

func GetErrFromCode

func GetErrFromCode(code int, msg string) error

Types

type AggregationResult

type AggregationResult[HitT any, AggrT any] struct {
	SearchResult[HitT]
	Aggregations map[string]AggrT `json:"aggregations"`
}

AggregationResult should be used if only one kind of aggregation is requested example: model.AggregationResult[Entry, TermsAggrT]{}

type AggregationsResult

type AggregationsResult[HitT any, AggrT any] struct {
	SearchResult[HitT]
	Aggregations AggrT `json:"aggregations"`
}

AggregationsResult should be used if multiple kinds of aggregations are requested example: model.AggregationsResult[Entry, struct{Foo TermsAggrT `json:"foo"`; Bar SometingElse `json:"bar"`}]{}

type AliasMapping

type AliasMapping = map[AliasName]AliasWrapper

type AliasName

type AliasName = string

type AliasWrapper

type AliasWrapper struct {
	Aliases map[IndexName]interface{} `json:"aliases"`
}

type CommandWithRights

type CommandWithRights struct {
	Command string              `json:"command"`
	Id      string              `json:"id"`
	Rights  *ResourceRightsBase `json:"rights"`
}

type CommandWrapper

type CommandWrapper struct {
	Command string `json:"command"`
	Id      string `json:"id"`
	Owner   string `json:"owner"`
}

type ConditionConfig

type ConditionConfig struct {
	Feature   string             `json:"feature"`
	Operation QueryOperationType `json:"operation"`
	Value     interface{}        `json:"value"`
	Ref       string             `json:"ref"`
}

type Done

type Done struct {
	ResourceKind string `json:"resource_kind"`
	ResourceId   string `json:"resource_id"`
	Handler      string `json:"handler"` // == github.com/SENERGY-Platform/permission-search
	Command      string `json:"command"` // PUT | DELETE | RIGHTS
}

type Entry

type Entry struct {
	Resource      string                 `json:"resource"`
	Features      map[string]interface{} `json:"features"`
	Annotations   map[string]interface{} `json:"annotations"`
	AdminUsers    []string               `json:"admin_users"`
	AdminGroups   []string               `json:"admin_groups"`
	ReadUsers     []string               `json:"read_users"`
	ReadGroups    []string               `json:"read_groups"`
	WriteUsers    []string               `json:"write_users"`
	WriteGroups   []string               `json:"write_groups"`
	ExecuteUsers  []string               `json:"execute_users"`
	ExecuteGroups []string               `json:"execute_groups"`
	Creator       string                 `json:"creator"`
}

func (*Entry) AddGroupRights

func (entry *Entry) AddGroupRights(group string, rights string)

func (*Entry) AddUserRights

func (entry *Entry) AddUserRights(user string, rights string)

func (*Entry) RemoveGroupRights

func (entry *Entry) RemoveGroupRights(group string)

func (*Entry) RemoveUserRights

func (entry *Entry) RemoveUserRights(user string)

func (*Entry) SetDefaultPermissions

func (entry *Entry) SetDefaultPermissions(config configuration.Config, kind string, owner string)

func (*Entry) SetResourceRights

func (this *Entry) SetResourceRights(rights ResourceRightsBase)

func (Entry) ToResourceRights

func (entry Entry) ToResourceRights() (result ResourceRights)

type EntryResult

type EntryResult struct {
	Creator           string                       `json:"creator"`
	Annotations       map[string]interface{}       `json:"annotations"`
	Permissions       map[string]bool              `json:"permissions"`
	PermissionHolders EntryResultPermissionHolders `json:"permission_holders"`
	Shared            bool                         `json:"shared"`
}

EntryResult is ment to be used in combination with a resource model is intended to be used with client.Query() example:

type Device struct{
	Id   string `json:"id"`
	Name string `json:"name"`
}

type DeviceResult struct {
	EntryResult
	Device
}

func main() {
	client.Query[DeviceResult](c, token, model.QueryMessage{Resource:"devices"})
	client.Query[Device](c, token, model.QueryMessage{Resource:"devices"})
}

type EntryResultPermissionHolders

type EntryResultPermissionHolders struct {
	AdminUsers   []string `json:"admin_users"`
	ReadUsers    []string `json:"read_users"`
	WriteUsers   []string `json:"write_users"`
	ExecuteUsers []string `json:"execute_users"`
}

type FeatureSelection

type FeatureSelection struct {
	Feature string
	Value   string
}

type Hit

type Hit[T any] struct {
	Index  string        `json:"_index"`
	Id     string        `json:"_id"`
	Score  interface{}   `json:"_score"`
	Source T             `json:"_source"`
	Sort   []interface{} `json:"sort"`
}

type Hits

type Hits[T any] struct {
	Total    Total       `json:"total"`
	MaxScore interface{} `json:"max_score"`
	Hits     []Hit[T]    `json:"hits"`
}

type IndexName

type IndexName = string

type ListAfter

type ListAfter struct {
	Id string `json:"id"`
}

type ListOptions

type ListOptions struct {
	QueryListCommons
	ListIds    []string
	TextSearch string
	Selection  *FeatureSelection
}

func (ListOptions) Mode

func (this ListOptions) Mode() (mode ListOptionsMode, err error)

func (ListOptions) QueryValues

func (this ListOptions) QueryValues() url.Values

func (ListOptions) Validate

func (this ListOptions) Validate() error

type ListOptionsMode

type ListOptionsMode = string

type OpenSearchGetResult

type OpenSearchGetResult struct {
	Index       string      `json:"_index"`
	Id          string      `json:"_id"`
	Version     int64       `json:"_version"`
	SeqNo       int64       `json:"_seq_no"`
	PrimaryTerm int64       `json:"_primary_term"`
	Found       bool        `json:"found"`
	Source      interface{} `json:"_source"`
}

type PermCommandMsg

type PermCommandMsg struct {
	Command  string `json:"command"`
	Kind     string
	Resource string
	User     string
	Group    string
	Right    string
}

type QueryCheckIds

type QueryCheckIds struct {
	Ids    []string `json:"ids"`
	Rights string   `json:"rights"`
}

type QueryFind

type QueryFind struct {
	QueryListCommons
	Search string     `json:"search"`
	Filter *Selection `json:"filter"`
}

type QueryListCommons

type QueryListCommons struct {
	Limit  int `json:"limit"`
	Offset int `json:"offset"`

	// After may only be set if offset is 0
	// this field must be used if offset + limit would exceed 10000
	// when set the results begin after the referenced id and sort value
	// the sort value is used to efficiently locate the start point
	After *ListAfter `json:"after"`

	Rights   string `json:"rights"`
	SortBy   string `json:"sort_by"`
	SortDesc bool   `json:"sort_desc"`

	// AddIdModifier is used to modify the resource id in the result
	// possible modifiers can be found and configured in the configuration.json under result_modifiers
	// example value: url.Values{"service_group_selection": {"a8ee3b1c-4cda-4f0d-9f55-4ef4882ce0af"}}
	AddIdModifier url.Values `json:"add_id_modifier,omitempty"`

	WithTotal bool `json:"with_total"`
}

func GetQueryListCommonsFromStrings

func GetQueryListCommonsFromStrings(limit string, offset string, sortBy string, sortDir string, rights string) (result QueryListCommons, err error)

func GetQueryListCommonsFromUrlQuery

func GetQueryListCommonsFromUrlQuery(queryParams url.Values) (result QueryListCommons, err error)

func (QueryListCommons) QueryValues

func (this QueryListCommons) QueryValues() (result url.Values)

func (QueryListCommons) Validate

func (this QueryListCommons) Validate() error

type QueryListIds

type QueryListIds struct {
	QueryListCommons
	Ids []string `json:"ids"`
}

type QueryMessage

type QueryMessage struct {
	Resource           string         `json:"resource"`
	Find               *QueryFind     `json:"find"`
	ListIds            *QueryListIds  `json:"list_ids"`
	CheckIds           *QueryCheckIds `json:"check_ids"`
	TermAggregate      *string        `json:"term_aggregate"`
	TermAggregateLimit int            `json:"term_aggregate_limit"`
}

type QueryOperationType

type QueryOperationType string
const (
	QueryEqualOperation             QueryOperationType = "=="
	QueryUnequalOperation           QueryOperationType = "!="
	QueryAnyValueInFeatureOperation QueryOperationType = "any_value_in_feature"
)

type ReindexIndexRef

type ReindexIndexRef struct {
	Index string `json:"index"`
}

type ReindexRequest

type ReindexRequest struct {
	Source ReindexIndexRef `json:"source"`
	Dest   ReindexIndexRef `json:"dest"`
}

type ReindexResult

type ReindexResult struct {
	Took             int  `json:"took"`
	TimedOut         bool `json:"timed_out"`
	Total            int  `json:"total"`
	Updated          int  `json:"updated"`
	Created          int  `json:"created"`
	Deleted          int  `json:"deleted"`
	Batches          int  `json:"batches"`
	VersionConflicts int  `json:"version_conflicts"`
	Noops            int  `json:"noops"`
	Retries          struct {
		Bulk   int `json:"bulk"`
		Search int `json:"search"`
	} `json:"retries"`
	ThrottledMillis      int           `json:"throttled_millis"`
	RequestsPerSecond    float64       `json:"requests_per_second"`
	ThrottledUntilMillis int           `json:"throttled_until_millis"`
	Failures             []interface{} `json:"failures"`
}

type ResourceRights

type ResourceRights struct {
	ResourceRightsBase
	ResourceId string                 `json:"resource_id"`
	Features   map[string]interface{} `json:"features"`
	Creator    string                 `json:"creator"`
}

type ResourceRightsBase

type ResourceRightsBase struct {
	UserRights  map[string]Right `json:"user_rights"`
	GroupRights map[string]Right `json:"group_rights"`
}

type ResourceVersion

type ResourceVersion struct {
	SeqNo       int64
	PrimaryTerm int64
}
type Right struct {
	Read         bool `json:"read"`
	Write        bool `json:"write"`
	Execute      bool `json:"execute"`
	Administrate bool `json:"administrate"`
}

type SearchResult

type SearchResult[T any] struct {
	Took     int  `json:"took"`
	TimedOut bool `json:"timed_out"`
	Shards   struct {
		Total      int `json:"total"`
		Successful int `json:"successful"`
		Skipped    int `json:"skipped"`
		Failed     int `json:"failed"`
	} `json:"_shards"`
	Hits Hits[T] `json:"hits"`
}

type Selection

type Selection struct {
	And       []Selection     `json:"and"`
	Or        []Selection     `json:"or"`
	Not       *Selection      `json:"not"`
	Condition ConditionConfig `json:"condition"`
}

type TermAggregationResultElement

type TermAggregationResultElement struct {
	Term  interface{} `json:"term"`
	Count int64       `json:"count"`
}

type TermsAggrT

type TermsAggrT struct {
	DocCountErrorUpperBound int64 `json:"doc_count_error_upper_bound"`
	SumOtherDocCount        int64 `json:"sum_other_doc_count"`
	Buckets                 []struct {
		Key      string `json:"key"`
		DocCount int64  `json:"doc_count"`
	} `json:"buckets"`
}

type Total

type Total struct {
	Value    int64  `json:"value"`
	Relation string `json:"relation"`
}

type UpdateAliasAction

type UpdateAliasAction struct {
	Remove *UpdateAliasIndexMapping `json:"remove,omitempty"`
	Add    *UpdateAliasIndexMapping `json:"add,omitempty"`
}

type UpdateAliasIndexMapping

type UpdateAliasIndexMapping struct {
	Index string `json:"index"`
	Alias string `json:"alias"`
}

type UpdateAliasRequest

type UpdateAliasRequest struct {
	Actions []UpdateAliasAction `json:"actions"`
}

type UserCommandMsg

type UserCommandMsg struct {
	Command string `json:"command"`
	Id      string `json:"id"`
}

Jump to

Keyboard shortcuts

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