forked from michaelklishin/rabbit-hole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
definitions.go
103 lines (87 loc) · 2.97 KB
/
definitions.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
96
97
98
99
100
101
102
103
package rabbithole
import (
"encoding/json"
"net/http"
"net/url"
)
// ExportedDefinitions represents definitions exported from a RabbitMQ cluster
type ExportedDefinitions struct {
RabbitVersion string `json:"rabbit_version,omitempty"`
RabbitMQVersion string `json:"rabbitmq_version,omitempty"`
ProductName string `json:"product_name,omitempty"`
ProductVersion string `json:"product_version,omitempty"`
Users *[]UserInfo `json:"users,omitempty"`
Vhosts *[]VhostInfo `json:"vhosts,omitempty"`
Permissions *[]Permissions `json:"permissions,omitempty"`
TopicPermissions *[]TopicPermissionInfo `json:"topic_permissions,omitempty"`
Parameters *[]RuntimeParameter `json:"paramaters,omitempty"`
GlobalParameters *[]GlobalRuntimeParameter `json:"global_parameters,omitempty"`
Policies *[]PolicyDefinition `json:"policies"`
Queues *[]QueueInfo `json:"queues"`
Exchanges *[]ExchangeInfo `json:"exchanges"`
Bindings *[]BindingInfo `json:"bindings"`
}
//
// GET /api/definitions
//
// ListDefinitions returns a set of definitions exported from a RabbitMQ cluster.
func (c *Client) ListDefinitions() (p *ExportedDefinitions, err error) {
req, err := newGETRequest(c, "definitions")
if err != nil {
return nil, err
}
if err = executeAndParseRequest(c, req, &p); err != nil {
return nil, err
}
return p, nil
}
//
// GET /api/definitions/vhost
//
// ListVhostDefinitions returns a set of definitions for a specific vhost.
func (c *Client) ListVhostDefinitions(vhost string) (p *ExportedDefinitions, err error) {
req, err := newGETRequest(c, "definitions/"+url.QueryEscape(vhost))
if err != nil {
return nil, err
}
if err = executeAndParseRequest(c, req, &p); err != nil {
return nil, err
}
return p, nil
}
//
// POST /api/definitions
//
// UploadDefinitions uploads a set of definitions and returns an error indicating if the operation was a failure
func (c *Client) UploadDefinitions(p *ExportedDefinitions) (res *http.Response, err error) {
body, err := json.Marshal(p)
if err != nil {
return nil, err
}
req, err := newRequestWithBody(c, http.MethodPost, "definitions", body)
if err != nil {
return nil, err
}
if res, err = executeRequest(c, req); err != nil {
return nil, err
}
return res, nil
}
//
// POST /api/definitions/vhost
//
// UploadDefinitions uploads a set of definitions and returns an error indicating if the operation was a failure
func (c *Client) UploadVhostDefinitions(p *ExportedDefinitions, vhost string) (res *http.Response, err error) {
body, err := json.Marshal(p)
if err != nil {
return nil, err
}
req, err := newRequestWithBody(c, http.MethodPost, "definitions/"+url.QueryEscape(vhost), body)
if err != nil {
return nil, err
}
if res, err = executeRequest(c, req); err != nil {
return nil, err
}
return res, nil
}