Documentation
¶
Index ¶
- Variables
- func AddRuleToCache(rule ESRuleDoc)
- func Apply() middleware.Middleware
- func ApplyCustomData(responseBody []byte, data *string) ([]byte, error)
- func ApplyFilters(req *querytranslate.RSQuery, data *string) error
- func ApplyHideResult(responseBody []byte, data *string) ([]byte, error)
- func ApplyPromotedResult(requestBody querytranslate.RSQuery, responseBody []byte, data *string) ([]byte, error)
- func ApplyRemoveWords(req *querytranslate.RSQuery, data *string) error
- func ApplyReplaceSearch(req *querytranslate.RSQuery, data *string) error
- func ApplyReplaceWords(req *querytranslate.RSQuery, data *string) error
- func ApplySearchSettings(req *querytranslate.RSQuery, data *string) error
- func DeleteRuleToCache(ruleID string) bool
- func GetClientIP4(ip string) string
- func GetClientIP6(ip string) string
- func InjectKV(ctx *v8go.Context) error
- func IsIndexingRequest(req *http.Request) bool
- func NewContext(ctx context.Context, request ScriptRequest) context.Context
- func ParseFilters(filters []querytranslate.TermFilter) map[string]string
- func ParseTriggerExprToLowerCase(expression string) string
- func ParseTriggerExpression(expression string, triggerType TriggerType) string
- func RunCronRule(r *Rules, ruleDetails ESRuleDoc)
- func RunScript(scriptContext []byte, script string, timeout time.Duration) ([]byte, *[]string, error)
- func SetRulesToCache(rules []ESRuleDoc)
- func StoreValueInCacheWithObject(key, value string, cacheObject *ristretto.Cache) error
- func TriggerEnvsToMap(envs TriggerEnvironmentsToEvaluate) map[string]interface{}
- func UpdateRuleToCache(ruleID string, rule ESRuleDoc) bool
- func ValidateIndexTriggerExpression(expression string) error
- func ValidateTriggerExpression(expression string) error
- type Action
- type ActionType
- type CacheSyncScript
- type CronScriptOutput
- type CronScriptRequest
- type CronScriptResponse
- type ESRuleDoc
- type ESRuleRequestBody
- type FetchRequest
- type KV
- type MappingsMigration
- type PromotedResult
- type PromotedResultSuggestion
- type PromotedResultSuggestionDoc
- type RequestAction
- type RuleContext
- type Rules
- func (r *Rules) AlternateRoutes() []plugins.Route
- func (r *Rules) ESMiddleware() []middleware.Middleware
- func (r *Rules) InitFunc() error
- func (r *Rules) Name() string
- func (r *Rules) RSMiddleware() []middleware.Middleware
- func (r *Rules) ReInstantiateV8Context(global *v8go.ObjectTemplate)
- func (r *Rules) Routes() []plugins.Route
- type RunningJob
- type ScriptContext
- type ScriptData
- type ScriptRequest
- type ScriptRequestIn
- type ScriptResponse
- type ScriptResponseIn
- type SearchSettingsConfig
- type TimeFrame
- type Trigger
- type TriggerEnvironmentsToEvaluate
- type TriggerType
- type ValidateScriptError
- type ValidateScriptRequest
- type ValidateScriptRequestWrapper
- type ValidateScriptResponse
- type ValidateScriptResponseWrapper
Constants ¶
This section is empty.
Variables ¶
var MapToParseExpressionToStructKeys = map[string]string{
"$index": "Index",
"$filter": "Filter",
"$query": "Query",
"$type": "Type",
"$origin": "Origin",
"$referer": "Referer",
"$path": "Path",
"$category": "Category",
"$acl": "ACL",
"$ipv4": "IPv4",
"$ipv6": "IPv6",
"$customEvents": "CustomEvents",
}
var MapToParseIndexExpressionToStructKeys = map[string]string{
"$index": "Index",
"$type": "Type",
"$origin": "Origin",
"$referer": "Referer",
"$path": "Path",
"$category": "Category",
"$acl": "ACL",
"$ipv4": "IPv4",
"$ipv6": "IPv6",
"$customEvents": "CustomEvents",
}
Functions ¶
func Apply ¶
func Apply() middleware.Middleware
Apply middleware intercepts the reactivesearch requests and applies query rules to the search results.
func ApplyCustomData ¶
Applies the custom data
func ApplyFilters ¶
func ApplyFilters(req *querytranslate.RSQuery, data *string) error
Applies the filters
func ApplyHideResult ¶
Applies the hide results TODO: Not performance efficient when hits size is large
func ApplyPromotedResult ¶
func ApplyRemoveWords ¶
func ApplyRemoveWords(req *querytranslate.RSQuery, data *string) error
func ApplyReplaceSearch ¶
func ApplyReplaceSearch(req *querytranslate.RSQuery, data *string) error
Applies the replace search term
func ApplyReplaceWords ¶
func ApplyReplaceWords(req *querytranslate.RSQuery, data *string) error
func ApplySearchSettings ¶
func ApplySearchSettings(req *querytranslate.RSQuery, data *string) error
Applies the search settings
func DeleteRuleToCache ¶
DeleteRuleToCache deletes a rule from cache
func GetClientIP6 ¶
Returns an ip address without last 8 bits (1 byte)
func IsIndexingRequest ¶
IsIndexingRequest checks if the request is an indexing one and accordingly returns it.
func NewContext ¶
func NewContext(ctx context.Context, request ScriptRequest) context.Context
NewContext returns a new context with the given request body.
func ParseFilters ¶
func ParseFilters(filters []querytranslate.TermFilter) map[string]string
Normalizes the filter keys i.e replaces the '.' with '__'
func ParseTriggerExprToLowerCase ¶
ParseTriggerExprToLowerCase finds all the single/double quoted strings having space as prefix (or suffix) and converts them to lower case Check the TestParseTriggerExprToLowerCase test cases for more info
func ParseTriggerExpression ¶
func ParseTriggerExpression(expression string, triggerType TriggerType) string
ParseTriggerExpression parses the trigger expression and returns it as a string.
func RunCronRule ¶
Run the cron rule based on the passed script details. Thie method is called either: - when cron rule is created/updated - when server restarts
func TriggerEnvsToMap ¶
func TriggerEnvsToMap(envs TriggerEnvironmentsToEvaluate) map[string]interface{}
func UpdateRuleToCache ¶
UpdateRuleToCache updates a rule without overriding the previous values
func ValidateIndexTriggerExpression ¶
ValidateIndexTriggerExpression will validate the index trigger expression.
func ValidateTriggerExpression ¶
ValidateTriggerExpression will validate the expression for query type
Types ¶
type Action ¶
type Action struct {
Type *ActionType `json:"type,omitempty"`
Data *string `json:"data,omitempty"` // we store the stringified data in the ES
Script *string `json:"script,omitempty"` // script has different data type (binary)
DecodeScript *string
Request *ScriptRequest `json:"request,omitempty"`
Response *ScriptResponse `json:"response,omitempty"`
Environments map[string]interface{} `json:"envs,omitempty"`
}
type ActionType ¶
type ActionType int
const ( PromoteResult ActionType = iota // after HideResult // after CustomData // after ReplaceSearchTerm // before AddFilter // before SearchSettings // before RemoveWords // before ReplaceWords // before ReplaceSearchQuery // before Script )
func (ActionType) MarshalJSON ¶
func (o ActionType) MarshalJSON() ([]byte, error)
MarshalJSON is the implementation of the Marshaler interface for marshaling ActionType type.
func (ActionType) String ¶
func (o ActionType) String() string
String is the implementation of Stringer interface that returns the string representation of ActionType type.
func (*ActionType) UnmarshalJSON ¶
func (o *ActionType) UnmarshalJSON(bytes []byte) error
UnmarshalJSON is the implementation of the Unmarshaler interface for unmarshaling ActionType type.
type CacheSyncScript ¶
type CacheSyncScript struct {
// contains filtered or unexported fields
}
func (CacheSyncScript) Index ¶
func (s CacheSyncScript) Index() string
func (CacheSyncScript) PluginName ¶
func (s CacheSyncScript) PluginName() string
func (CacheSyncScript) SetCache ¶
func (s CacheSyncScript) SetCache(response *elastic.SearchResult) error
type CronScriptOutput ¶
type CronScriptOutput struct {
Category string `json:"category"`
Request *CronScriptRequest `json:"request"`
Response *CronScriptResponse `json:"response"`
ScriptTook *int `json:"scriptTook,omitempty"`
Console []string `json:"console_logs,omitempty"`
}
type CronScriptRequest ¶
type CronScriptRequest struct {
Context *RuleContext `json:"context"`
}
type CronScriptResponse ¶
type ESRuleDoc ¶
type ESRuleDoc struct {
ID *string `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
Order *int `json:"order,omitempty"`
UpdatedAt *int64 `json:"updated_at,omitempty"`
CreatedAt *int64 `json:"created_at,omitempty"`
Trigger *Trigger `json:"trigger,omitempty"`
Actions *[]Action `json:"actions,omitempty"`
ShowAdvanceEditor *bool `json:"show_advance_editor,omitempty"`
}
ESRuleDoc represents the shape of a rule doc stored in ES
func GetRuleFromCache ¶
GetRuleFromCache returns a rule by ID
func GetRulesFromCache ¶
func GetRulesFromCache() []ESRuleDoc
GetRulesFromCache returns a list of cached rules
func IsRuleExistsInCache ¶
IsRuleExistsInCache checks if a rule in present in cache
type ESRuleRequestBody ¶
type ESRuleRequestBody struct {
ID *string `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
Order *int `json:"order,omitempty"`
UpdatedAt *int64 `json:"updated_at,omitempty"`
CreatedAt *int64 `json:"created_at,omitempty"`
Trigger *Trigger `json:"trigger,omitempty"`
Actions *[]RequestAction `json:"actions,omitempty"`
ShowAdvanceEditor *bool `json:"show_advance_editor,omitempty"`
}
type FetchRequest ¶
type FetchRequest struct {
Body string `json:"body"`
Headers map[string]string `json:"headers"`
Method string `json:"method"`
Redirect string `json:"redirect"`
}
Request Body for fetch
type KV ¶
type KV struct {
// contains filtered or unexported fields
}
func (*KV) GetKVReadFunctionCallback ¶
func (kv *KV) GetKVReadFunctionCallback() v8go.FunctionCallback
GetKVReadFunctionCallback will return the callback function to be injected into v8go context.
This function will expose a way to fetch a value for a passed key.
func (*KV) GetKVWriteFunctionCallback ¶
func (kv *KV) GetKVWriteFunctionCallback() v8go.FunctionCallback
GetKVWriteFunctionCallback will return the callback function to be injected into v8go context.
This function will expose a way to store the passed value against the passed key in badger.
func (*KV) GetValueFromCache ¶
GetValueFromCache will read the value from the passed key
If the key is not found an empty string will be returned.
func (*KV) StoreValueInCache ¶
StoreValueInCache will store the passed value against the passed key in ristretto.
The TTL of the key will be set according to the cache preferences of the cluster.
type MappingsMigration ¶
type MappingsMigration struct {
// contains filtered or unexported fields
}
func (MappingsMigration) ConditionCheck ¶
func (m MappingsMigration) ConditionCheck() (bool, *util.Error)
func (MappingsMigration) IsAsync ¶
func (m MappingsMigration) IsAsync() bool
func (MappingsMigration) Script ¶
func (m MappingsMigration) Script() *util.Error
type PromotedResult ¶
type PromotedResultSuggestion ¶
type PromotedResultSuggestion struct {
Doc PromotedResultSuggestionDoc `json:"doc"`
}
type RequestAction ¶
type RequestAction struct {
Type *ActionType `json:"type,omitempty"`
Data *interface{} `json:"data,omitempty"` // we store the stringified data in the ES
Script *string `json:"script,omitempty"`
Request *ScriptRequest `json:"request,omitempty"`
Response *ScriptResponse `json:"response,omitempty"`
Environments map[string]interface{} `json:"envs,omitempty"`
}
type RuleContext ¶
type RuleContext struct {
Envs map[string]interface{} `json:"envs"`
}
type Rules ¶
type Rules struct {
// contains filtered or unexported fields
}
Rules plugin deals with managing query rules.
func Instance ¶
func Instance() *Rules
Instance returns the singleton instance of the plugin. Instance should be the only way (both within or outside the package) to fetch the instance of the plugin, in order to avoid stateless duplicates.
func (*Rules) AlternateRoutes ¶
Expose plugin specific routes
func (*Rules) ESMiddleware ¶
func (r *Rules) ESMiddleware() []middleware.Middleware
func (*Rules) InitFunc ¶
InitFunc initializes the dao, i.e. elasticsearch client, and should be executed only once in the lifetime of the plugin.
func (*Rules) RSMiddleware ¶
func (r *Rules) RSMiddleware() []middleware.Middleware
func (*Rules) ReInstantiateV8Context ¶
func (r *Rules) ReInstantiateV8Context(global *v8go.ObjectTemplate)
ReInstantiateV8Context cleans up any heap associated with the existing context and reinstantiates it
type RunningJob ¶
Store details about all the running cron jobs
type ScriptContext ¶
type ScriptContext struct {
Request ScriptRequest `json:"request"`
Response ScriptResponse `json:"response"`
Environments map[string]interface{} `json:"envs"`
}
type ScriptData ¶
type ScriptData struct {
Script string `json:"script"`
}
type ScriptRequest ¶
type ScriptRequest struct {
Body string `json:"body"`
Headers map[string]string `json:"headers"`
URL string `json:"url"`
Method string `json:"method"`
}
func FromContext ¶
func FromContext(ctx context.Context) (*ScriptRequest, error)
FromContext retrieves the Script context request stored against the rules.ctxKey from the context.
type ScriptRequestIn ¶
type ScriptResponse ¶
type ScriptResponseIn ¶
type SearchSettingsConfig ¶
type Trigger ¶
type Trigger struct {
Type *TriggerType `` /* 209-byte string literal not displayed */
Expression string `` /* 213-byte string literal not displayed */
TimeFrame *TimeFrame `` /* 134-byte string literal not displayed */
}
type TriggerEnvironmentsToEvaluate ¶
type TriggerEnvironmentsToEvaluate struct {
Index []string `json:"index,omitempty"`
Filter map[string]string `json:"filters,omitempty"`
Query string `json:"query,omitempty"`
Type string `json:"type,omitempty"` // search|term|suggestion|geo|range
Origin string `json:"origin,omitempty"` // https://my-search.domain.com
Referer string `json:"referer,omitempty"` // https://my-search.domain.com/path?q=hello
Path string `json:"path,omitempty"` // /_doc/nested_something
Method []string `json:"method,omitempty"` // GET/POST
URLValues map[string]string `json:"urlValues,omitempty"` // {'q': 'hello'}
Category string `json:"category,omitempty"` // docs
ACL string `json:"acl,omitempty"` // bulk
IPv4 string `json:"ipv4,omitempty"` // 29.120.12.12
IPv6 string `json:"ipv6,omitempty"` // 2001:db8:3333:4444:5555:6666:7777:8888
CustomEvents map[string]string `json:"customEvents,omitempty"` // { 'platform': 'mac' }
OpenAIConfig openai.OpenAIConfig `json:"openAIConfig,omitempty"`
}
TODO: Change the struct for filters to support multi value filters
func GetTriggerEnvs ¶
func GetTriggerEnvs(ctx context.Context, r *http.Request, environments querytranslate.QueryEnvs, triggerType TriggerType) (*TriggerEnvironmentsToEvaluate, error)
GetTriggerEnvs extracts the trigger environments to run the trigger.
type TriggerType ¶
type TriggerType int
const ( Always TriggerType = iota Filter Index Query Cron )
func (TriggerType) JSONSchema ¶
func (o TriggerType) JSONSchema() *jsonschema.Schema
func (TriggerType) MarshalJSON ¶
func (o TriggerType) MarshalJSON() ([]byte, error)
MarshalJSON is the implementation of the Marshaler interface for marshaling TiggerType type.
func (TriggerType) String ¶
func (o TriggerType) String() string
String is the implementation of Stringer interface that returns the string representation of TriggerType type.
func (TriggerType) Timeout ¶
func (o TriggerType) Timeout() time.Duration
Get the timeout in seconds for the passed trigger
func (*TriggerType) UnmarshalJSON ¶
func (o *TriggerType) UnmarshalJSON(bytes []byte) error
UnmarshalJSON is the implementation of the Unmarshaler interface for unmarshaling TiggerType type.
type ValidateScriptError ¶
type ValidateScriptError struct {
Code int `json:"code"`
Status string `json:"status"`
Message string `json:"message"`
}
ValidateScriptError is similar to what telemetry writes back when an error occurs but also contains a console field to indicate console logs
This struct should be used as value for the `error` field
type ValidateScriptRequest ¶
type ValidateScriptRequest struct {
Script string `json:"script"` // required
Envs map[string]interface{} `json:"envs"`
Request *ScriptRequest `json:"request"`
Response *ScriptResponse `json:"response"`
IsCron *bool `json:"isCron"`
}
type ValidateScriptRequestWrapper ¶
type ValidateScriptRequestWrapper struct {
Script string `json:"script"` // required
Envs map[string]interface{} `json:"envs"`
Request *ScriptRequestIn `json:"request"`
Response *ScriptResponseIn `json:"response"`
IsCron *bool `json:"isCron"`
}
type ValidateScriptResponse ¶
type ValidateScriptResponse struct {
Request *ScriptRequest `json:"request"`
Response *ScriptResponse `json:"response"`
ScriptTook int `json:"script_took"`
Console []string `json:"console_logs"`
}
type ValidateScriptResponseWrapper ¶
type ValidateScriptResponseWrapper struct {
Request *ScriptRequestIn `json:"request"`
Response *ScriptResponseIn `json:"response"`
ScriptTook int `json:"script_took"`
Console []string `json:"console_logs"`
}