2015-11-19 05:45:05 +00:00
|
|
|
package rabbithole
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
2019-11-06 13:15:06 +00:00
|
|
|
"net/url"
|
2015-11-19 05:45:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Federation definition: additional arguments
|
|
|
|
// added to the entities (queues, exchanges or both)
|
|
|
|
// that match a policy.
|
|
|
|
type FederationDefinition struct {
|
|
|
|
Uri string `json:"uri"`
|
|
|
|
Expires int `json:"expires"`
|
|
|
|
MessageTTL int32 `json:"message-ttl"`
|
|
|
|
MaxHops int `json:"max-hops"`
|
|
|
|
PrefetchCount int `json:"prefetch-count"`
|
|
|
|
ReconnectDelay int `json:"reconnect-delay"`
|
2017-03-31 00:03:13 +00:00
|
|
|
AckMode string `json:"ack-mode,omitempty"`
|
2015-11-19 05:45:05 +00:00
|
|
|
TrustUserId bool `json:"trust-user-id"`
|
2017-03-31 00:03:13 +00:00
|
|
|
Exchange string `json:"exchange"`
|
|
|
|
Queue string `json:"queue"`
|
2015-11-19 05:45:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Represents a configured Federation upstream.
|
|
|
|
type FederationUpstream struct {
|
|
|
|
Definition FederationDefinition `json:"value"`
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// PUT /api/parameters/federation-upstream/{vhost}/{upstream}
|
|
|
|
//
|
|
|
|
|
|
|
|
// Updates a federation upstream
|
|
|
|
func (c *Client) PutFederationUpstream(vhost string, upstreamName string, fDef FederationDefinition) (res *http.Response, err error) {
|
|
|
|
fedUp := FederationUpstream{
|
|
|
|
Definition: fDef,
|
|
|
|
}
|
|
|
|
body, err := json.Marshal(fedUp)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-11-06 13:15:06 +00:00
|
|
|
req, err := newRequestWithBody(c, "PUT", "parameters/federation-upstream/"+url.PathEscape(vhost)+"/"+url.PathEscape(upstreamName), body)
|
2015-11-19 05:45:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-11-06 13:15:06 +00:00
|
|
|
if res, err = executeRequest(c, req); err != nil {
|
2015-11-19 05:45:05 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// DELETE /api/parameters/federation-upstream/{vhost}/{name}
|
|
|
|
//
|
|
|
|
|
|
|
|
// Deletes a federation upstream.
|
|
|
|
func (c *Client) DeleteFederationUpstream(vhost, upstreamName string) (res *http.Response, err error) {
|
2019-11-06 13:15:06 +00:00
|
|
|
req, err := newRequestWithBody(c, "DELETE", "parameters/federation-upstream/"+url.PathEscape(vhost)+"/"+url.PathEscape(upstreamName), nil)
|
2015-11-19 05:45:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-11-06 13:15:06 +00:00
|
|
|
if res, err = executeRequest(c, req); err != nil {
|
2015-11-19 05:45:05 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|