Skip to content

Commit

Permalink
Enable deleting a single exchange's topic permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
b@zi.is authored and b@zi.is committed Jan 27, 2020
1 parent 523174d commit c60cf57
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
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
}

0 comments on commit c60cf57

Please sign in to comment.