forked from defensestation/osquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
58 lines (52 loc) · 1.36 KB
/
options.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
50
51
52
53
54
55
56
57
58
package osquery
import (
"fmt"
"net/http"
opensearchapi "github.com/opensearch-project/opensearch-go/v4/opensearchapi"
)
type Options struct {
Indices []string
Header http.Header
Params interface{}
}
// ApplyOptions applies additional options to the request if provided.
// ApplyOptions applies additional options to the request if provided.
func ApplyOptions(req interface{}, options *Options) error {
if options == nil {
return nil
}
switch r := req.(type) {
case *opensearchapi.SearchReq:
if options.Indices != nil {
r.Indices = options.Indices // Correctly assigning to the field
}
if options.Header != nil {
r.Header = options.Header
}
if options.Params != nil {
params, ok := options.Params.(*opensearchapi.SearchParams)
if !ok {
return fmt.Errorf("invalid type for SearchParams")
}
r.Params = *params
}
case *opensearchapi.DocumentDeleteByQueryReq:
if options.Indices != nil {
r.Indices = options.Indices
}
if options.Header != nil {
r.Header = options.Header
}
if options.Params != nil {
params, ok := options.Params.(*opensearchapi.DocumentDeleteByQueryParams)
if !ok {
return fmt.Errorf("invalid type for DocumentDeleteByQueryParams")
}
r.Params = *params
}
// Add more cases for other request types as needed
default:
return fmt.Errorf("unsupported request type: %T", req)
}
return nil
}