-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient_run.go
45 lines (36 loc) · 979 Bytes
/
client_run.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
package salt
import (
"context"
"net/http"
)
type Object map[string]any
type Command struct {
Arguments []string `json:"arg,omitempty"`
Batch string `json:"batch,omitempty"`
Client string `json:"client"`
Function string `json:"fun"`
Keywords Object `json:"kwarg,omitempty"`
Match string `json:"match,omitempty"`
Target string `json:"tgt,omitempty"`
TargetType string `json:"tgt_type,omitempty"`
Timeout int `json:"timeout,omitempty"`
}
func (c *Client) Run(ctx context.Context, cmd *Command, fn ReturnFunc) error {
format := FormatObject
// The "local" client is the most common.
if cmd.Client == "" {
cmd.Client = "local"
}
if cmd.Batch != "" {
cmd.Client = "local_batch"
}
if cmd.Client == "local_batch" {
format = FormatBatch
}
if cmd.Client == "runner" {
format = FormatRunner
}
return c.do(ctx, "POST", "/", cmd, func(r *http.Response) error {
return readReturn(r.Body, fn, format)
})
}