diff --git a/definitions.go b/definitions.go index 5aaba07..80dcc24 100644 --- a/definitions.go +++ b/definitions.go @@ -1,5 +1,7 @@ package rabbithole +import "net/url" + // ExportedDefinitions represents definitions exported from a RabbitMQ cluster type ExportedDefinitions struct { RabbitVersion string `json:"rabbit_version"` @@ -35,3 +37,21 @@ func (c *Client) ListDefinitions() (p *ExportedDefinitions, err error) { 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 +} diff --git a/rabbithole_test.go b/rabbithole_test.go index d6cf840..d9bb52f 100644 --- a/rabbithole_test.go +++ b/rabbithole_test.go @@ -3008,6 +3008,23 @@ var _ = Describe("RabbitMQ HTTP API client", func() { Ω(defs.Policies).ShouldNot(BeNil()) }) + It("returns definitions for a specific vhost", func() { + By("GET /definitions/vhost") + defs, err := rmqc.ListVhostDefinitions("rabbit/hole") + Ω(err).ShouldNot(HaveOccurred()) + Ω(defs).ShouldNot(BeNil()) + + Ω(defs.RabbitMQVersion).ShouldNot(BeNil()) + + // /definitions/vhost does not export vhosts or users + Ω(defs.Vhosts).Should(BeNil()) + Ω(defs.Users).Should(BeNil()) + + Ω(defs.Queues).ShouldNot(BeNil()) + Ω(defs.Parameters).Should(BeEmpty()) + Ω(defs.Policies).ShouldNot(BeNil()) + }) + It("returns exported global parameters", func() { By("GET /definitions") defs, err := rmqc.ListDefinitions()