forked from ppc64le-cloud/manageiq-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
groups.go
95 lines (84 loc) · 2.18 KB
/
groups.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package manageiq
import (
"encoding/json"
)
type MangeIQListResource struct {
Name string `json:"name"`
Count float64 `json:"count"`
SubCount float64 `json:"subcount"`
Pages float64 `json:"pages"`
Resources []Resource `json:"resources"`
Actions []Action `json:"actions"`
Links Links `json:"links"`
}
type Group struct {
CreatedOn string `json:"created_on"`
DetailedDescription string `json:"detailed_description"`
Actions []Action `json:"actions"`
GroupType string `json:"group_type"`
Sequence float64 `json:"sequence"`
UpdatedOn string `json:"updated_on"`
Settings string `json:"settings"`
TenantID string `json:"tenant_id"`
Href string `json:"href"`
ID string `json:"id"`
Description string `json:"description"`
}
type Groups struct {
MangeIQListResource
}
type Links struct {
Self string `json:"self"`
First string `json:"first"`
Last string `json:"last"`
}
type Action struct {
Name string `json:"name"`
Method string `json:"method"`
Href string `json:"href"`
}
type Resource struct {
Href string `json:"href"`
ID string `json:"id"`
Name string `json:"name"`
}
func (c *Client) GetGroups() (*Groups, error) {
builder := NewRequestBuilder(GET)
_, err := builder.ResolveRequestURL(c.Authenticator.GetBaseURL(), "/groups", nil, nil)
if err != nil {
return nil, err
}
req, err := builder.Build()
if err != nil {
return nil, err
}
resp, err := c.sendRequest(req, nil)
if err != nil {
return nil, err
}
g := &Groups{}
if err := json.Unmarshal(resp.RawResult, &g); err != nil {
return nil, err
}
return g, nil
}
func (c *Client) GetGroup(id string) (*Group, error) {
builder := NewRequestBuilder(GET)
_, err := builder.ResolveRequestURL(c.Authenticator.GetBaseURL(), "/groups/"+id, nil, nil)
if err != nil {
return nil, err
}
req, err := builder.Build()
if err != nil {
return nil, err
}
resp, err := c.sendRequest(req, nil)
if err != nil {
return nil, err
}
g := &Group{}
if err := json.Unmarshal(resp.RawResult, &g); err != nil {
return nil, err
}
return g, nil
}