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

Enable deleting a single exchange's topic permissions #147

Merged
merged 1 commit into from
Jan 28, 2020
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
4 changes: 4 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ Managing Topic Permissions
resp, err := rmqc.ClearTopicPermissionsIn("/", "my.user")
// => *http.Response, err

// revokes single permissions in vhost
resp, err := rmqc.DeleteTopicPermissionsIn("/", "my.user", "exchange")
// => *http.Response, err

Operations on cluster name
// Get cluster name
cn, err := rmqc.GetClusterName()
Expand Down
29 changes: 29 additions & 0 deletions rabbithole_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,35 @@ var _ = Describe("Rabbithole", func() {
})
})

Context("DELETE /topic-permissions/{vhost}/{user}/{exchange}", func() {
It("deletes one topic permissions", func() {
u := "temporary"

_, err := rmqc.PutUser(u, UserSettings{Password: "s3krE7"})
Ω(err).Should(BeNil())

awaitEventPropagation()
permissions := TopicPermissions{Exchange: "amq.topic", Write: "log.*", Read: "log.*"}
_, err = rmqc.UpdateTopicPermissionsIn("/", u, permissions)
Ω(err).Should(BeNil())
permissions = TopicPermissions{Exchange: "foobar", Write: "log.*", Read: "log.*"}
_, err = rmqc.UpdateTopicPermissionsIn("/", u, permissions)
Ω(err).Should(BeNil())

awaitEventPropagation()
_, err = rmqc.DeleteTopicPermissionsIn("/", u, "foobar")
Ω(err).Should(BeNil())

awaitEventPropagation()
xs, err := rmqc.ListTopicPermissions()
Ω(err).Should(BeNil())

Ω(len(xs)).Should(BeEquivalentTo(1))

rmqc.DeleteUser(u)
})
})

Context("PUT /exchanges/{vhost}/{exchange}", func() {
It("declares an exchange", func() {
vh := "rabbit/hole"
Expand Down
14 changes: 14 additions & 0 deletions topic_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,17 @@ func (c *Client) ClearTopicPermissionsIn(vhost, username string) (res *http.Resp

return res, nil
}

// DeleteTopicPermissionsIn delete topic-permissions of exchange for user in virtual host.
func (c *Client) DeleteTopicPermissionsIn(vhost, username string, exchange string) (res *http.Response, err error) {
req, err := newRequestWithBody(c, "DELETE", "topic-permissions/"+url.PathEscape(vhost)+"/"+url.PathEscape(username)+"/"+url.PathEscape(exchange), nil)
if err != nil {
return nil, err
}

if res, err = executeRequest(c, req); err != nil {
return nil, err
}

return res, nil
}