-
Notifications
You must be signed in to change notification settings - Fork 4
/
agent.go
56 lines (43 loc) · 1.28 KB
/
agent.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
package cpln
import (
"fmt"
)
// Agent - Agent
type Agent struct {
Base
Status *AgentStatus `json:"status,omitempty"`
}
// AgentStatus - AgentStatus
type AgentStatus struct {
BootstrapConfig *AgentBootstrapConfig `json:"bootstrapConfig,omitempty"`
}
type AgentBootstrapConfig struct {
RegistrationToken *string `json:"registrationToken,omitempty"`
AgentId *string `json:"agentId,omitempty"`
AgentLink *string `json:"agentLink,omitempty"`
HubEndpoint *string `json:"hubEndpoint,omitempty"`
}
// GetAgent - Get Agent by name
func (c *Client) GetAgent(name string) (*Agent, int, error) {
agent, code, err := c.GetResource("agent/"+name, new(Agent))
if err != nil {
return nil, code, err
}
return agent.(*Agent), code, err
}
// CreateAgent - Create an Agent
func (c *Client) CreateAgent(agent Agent) (*Agent, int, error) {
return c.CreateResourceAgent(agent)
}
// UpdateAgent - Update an Agent
func (c *Client) UpdateAgent(agent Agent) (*Agent, int, error) {
code, err := c.UpdateResource(fmt.Sprintf("agent/%s", *agent.Name), agent)
if err != nil {
return nil, code, err
}
return c.GetAgent(*agent.Name)
}
// DeleteAgent - Delete Agent by name
func (c *Client) DeleteAgent(name string) error {
return c.DeleteResource(fmt.Sprintf("agent/%s", name))
}