forked from michaelklishin/rabbit-hole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
federation.go
105 lines (85 loc) · 3.2 KB
/
federation.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
104
105
package rabbithole
import (
"net/http"
"net/url"
)
// FederationDefinition represents settings
// that will be used by federation links.
type FederationDefinition struct {
Uri URISet `json:"uri"`
Expires int `json:"expires,omitempty"`
MessageTTL int32 `json:"message-ttl,omitempty"`
MaxHops int `json:"max-hops,omitempty"`
PrefetchCount int `json:"prefetch-count,omitempty"`
ReconnectDelay int `json:"reconnect-delay"`
AckMode string `json:"ack-mode,omitempty"`
TrustUserId bool `json:"trust-user-id"`
Exchange string `json:"exchange,omitempty"`
Queue string `json:"queue,omitempty"`
}
// FederationUpstream represents a configured federation upstream.
type FederationUpstream struct {
Name string `json:"name"`
Vhost string `json:"vhost"`
Component string `json:"component"`
Definition FederationDefinition `json:"value"`
}
// FederationUpstreamComponent is the name of the runtime parameter component
// used by federation upstreams.
const FederationUpstreamComponent string = "federation-upstream"
//
// GET /api/parameters/federation-upstream
//
// ListFederationUpstreams returns a list of all federation upstreams.
func (c *Client) ListFederationUpstreams() (ups []FederationUpstream, err error) {
req, err := newGETRequest(c, "parameters/"+FederationUpstreamComponent)
if err != nil {
return []FederationUpstream{}, err
}
if err = executeAndParseRequest(c, req, &ups); err != nil {
return []FederationUpstream{}, err
}
return ups, nil
}
//
// GET /api/parameters/federation-upstream/{vhost}
//
// ListFederationUpstreamsIn returns a list of all federation upstreams in a vhost.
func (c *Client) ListFederationUpstreamsIn(vhost string) (ups []FederationUpstream, err error) {
req, err := newGETRequest(c, "parameters/"+FederationUpstreamComponent+"/"+url.PathEscape(vhost))
if err != nil {
return []FederationUpstream{}, err
}
if err = executeAndParseRequest(c, req, &ups); err != nil {
return []FederationUpstream{}, err
}
return ups, nil
}
//
// GET /api/parameters/federation-upstream/{vhost}/{upstream}
//
// GetFederationUpstream returns information about a federation upstream.
func (c *Client) GetFederationUpstream(vhost, name string) (up *FederationUpstream, err error) {
req, err := newGETRequest(c, "parameters/"+FederationUpstreamComponent+"/"+url.PathEscape(vhost)+"/"+url.PathEscape(name))
if err != nil {
return nil, err
}
if err = executeAndParseRequest(c, req, &up); err != nil {
return nil, err
}
return up, nil
}
//
// PUT /api/parameters/federation-upstream/{vhost}/{upstream}
//
// PutFederationUpstream creates or updates a federation upstream configuration.
func (c *Client) PutFederationUpstream(vhost, name string, def FederationDefinition) (res *http.Response, err error) {
return c.PutRuntimeParameter(FederationUpstreamComponent, vhost, name, def)
}
//
// DELETE /api/parameters/federation-upstream/{vhost}/{name}
//
// DeleteFederationUpstream removes a federation upstream.
func (c *Client) DeleteFederationUpstream(vhost, name string) (res *http.Response, err error) {
return c.DeleteRuntimeParameter(FederationUpstreamComponent, vhost, name)
}