Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ListVhostDefinitions #206

Merged
merged 1 commit into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions definitions.go
Original file line number Diff line number Diff line change
@@ -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"`
Expand Down Expand Up @@ -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
}
17 changes: 17 additions & 0 deletions rabbithole_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down