forked from Velocidex/vfilter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
49 lines (41 loc) · 1.12 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package vfilter
import (
"context"
"github.com/Velocidex/ordereddict"
)
// A helper function to build a dict within the query.
// e.g. dict(foo=5, bar=6)
type _GetVersion struct {
Function string `vfilter:"optional,field=function"`
Plugin string `vfilter:"optional,field=plugin"`
}
func (self _GetVersion) Info(scope *Scope, type_map *TypeMap) *FunctionInfo {
return &FunctionInfo{
Name: "version",
Doc: "Gets the version of a VQL plugin or function.",
ArgType: type_map.AddType(scope, &_GetVersion{}),
}
}
func (self _GetVersion) Call(ctx context.Context, scope *Scope, args *ordereddict.Dict) Any {
arg := &_GetVersion{}
err := ExtractArgs(scope, args, arg)
if err != nil {
scope.Log("version: %s", err.Error())
return Null{}
}
if arg.Plugin != "" {
plugin, pres := scope.plugins[arg.Plugin]
if pres {
return plugin.Info(scope, nil).Version
}
return Null{}
} else if arg.Function != "" {
function, pres := scope.functions[arg.Function]
if pres {
return function.Info(scope, nil).Version
}
return Null{}
}
scope.Log("version: One of plugin or function should be specified")
return 0
}