/
agent_error.go
50 lines (42 loc) · 1.33 KB
/
agent_error.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
package client
import (
"context"
"errors"
"net/http"
"net/url"
"strconv"
"github.com/calyptia/api/types"
)
func (c *Client) CreateAgentError(ctx context.Context, in types.CreateAgentError) (types.Created, error) {
var out types.Created
return out, c.do(ctx, http.MethodPost, "/v1/agents/"+in.AgentID+"/errors", in, &out)
}
func (c *Client) AgentErrors(ctx context.Context, in types.ListAgentErrors) (types.AgentErrors, error) {
var out types.AgentErrors
if in.AgentID == nil && in.FleetID == nil {
return out, errors.New("either agent ID or fleet ID required")
}
var path string
if in.AgentID != nil {
path = "/v1/agents/" + *in.AgentID + "/errors"
}
if in.FleetID != nil {
path = "/v1/fleets/" + *in.FleetID + "/agent_errors"
}
q := url.Values{}
if in.Dismissed != nil {
q.Set("dismissed", strconv.FormatBool(*in.Dismissed))
}
if in.Last != nil {
q.Set("last", strconv.Itoa(int(*in.Last)))
}
if in.Before != nil {
q.Set("before", *in.Before)
}
path += "?" + q.Encode()
return out, c.do(ctx, http.MethodGet, path, nil, &out.Items, withCursor(&out.EndCursor))
}
func (c *Client) DismissAgentError(ctx context.Context, in types.DismissAgentError) (types.DismissedAgentError, error) {
var out types.DismissedAgentError
return out, c.do(ctx, http.MethodPost, "/v1/agent_errors/"+in.AgentErrorID+"/dismiss", in, &out)
}