Skip to content

Commit

Permalink
escape symbols in names for lavinmqctl (#696)
Browse files Browse the repository at this point in the history
use URI.encode_www_form to escape symbols in vhost or queue names for laivnmqctl.
Before this if you want to create a vhost named "rabbit/hole", lavinmqctl crashes.
  • Loading branch information
kickster97 authored Jun 14, 2024
1 parent fd9043a commit 0224db4
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/lavinmqctl.cr
Original file line number Diff line number Diff line change
Expand Up @@ -352,23 +352,23 @@ class LavinMQCtl
vhost = @options["vhost"]? || "/"
queue = ARGV.shift?
abort @banner unless queue
resp = http.delete "/api/queues/#{URI.encode_www_form(vhost)}/#{queue}/contents", @headers
resp = http.delete "/api/queues/#{URI.encode_www_form(vhost)}/#{URI.encode_www_form(queue)}/contents", @headers
handle_response(resp, 204)
end

private def pause_queue
vhost = @options["vhost"]? || "/"
queue = ARGV.shift?
abort @banner unless queue
resp = http.put "/api/queues/#{URI.encode_www_form(vhost)}/#{queue}/pause", @headers
resp = http.put "/api/queues/#{URI.encode_www_form(vhost)}/#{URI.encode_www_form(queue)}/pause", @headers
handle_response(resp, 204)
end

private def resume_queue
vhost = @options["vhost"]? || "/"
queue = ARGV.shift?
abort @banner unless queue
resp = http.put "/api/queues/#{URI.encode_www_form(vhost)}/#{queue}/resume", @headers
resp = http.put "/api/queues/#{URI.encode_www_form(vhost)}/#{URI.encode_www_form(queue)}/resume", @headers
handle_response(resp, 204)
end

Expand Down Expand Up @@ -459,14 +459,14 @@ class LavinMQCtl
private def add_vhost
name = ARGV.shift?
abort @banner unless name
resp = http.put "/api/vhosts/#{name}", @headers
resp = http.put "/api/vhosts/#{URI.encode_www_form(name)}", @headers
handle_response(resp, 204)
end

private def delete_vhost
name = ARGV.shift?
abort @banner unless name
resp = http.delete "/api/vhosts/#{name}", @headers
resp = http.delete "/api/vhosts/#{URI.encode_www_form(name)}", @headers
handle_response(resp, 204)
end

Expand All @@ -482,15 +482,15 @@ class LavinMQCtl
}
end
body ||= {} of String => String
resp = http.post "/api/vhosts/#{name}/purge_and_close_consumers", @headers, body.to_json
resp = http.post "/api/vhosts/#{URI.encode_www_form(name)}/purge_and_close_consumers", @headers, body.to_json
handle_response(resp, 204)
end

private def clear_policy
vhost = @options["vhost"]? || "/"
name = ARGV.shift?
abort @banner unless name
resp = http.delete "/api/policies/#{URI.encode_www_form(vhost)}/#{name}", @headers
resp = http.delete "/api/policies/#{URI.encode_www_form(vhost)}/#{URI.encode_www_form(name)}", @headers
handle_response(resp, 204)
end

Expand Down Expand Up @@ -522,15 +522,15 @@ class LavinMQCtl
"apply-to": @options["apply-to"]? || "all",
"priority": @options["priority"]?.try &.to_i? || 0,
}
resp = http.put "/api/policies/#{URI.encode_www_form(vhost)}/#{name}", @headers, body.to_json
resp = http.put "/api/policies/#{URI.encode_www_form(vhost)}/#{URI.encode_www_form(name)}", @headers, body.to_json
handle_response(resp, 201, 204)
end

private def create_queue
name = ARGV.shift?
vhost = @options["vhost"]? || "/"
abort @banner unless name
url = "/api/queues/#{URI.encode_www_form(vhost)}/#{name}"
url = "/api/queues/#{URI.encode_www_form(vhost)}/#{URI.encode_www_form(name)}"
body = {
"auto_delete": @options.has_key?("auto_delete"),
"durable": @options.has_key?("durable"),
Expand All @@ -544,7 +544,7 @@ class LavinMQCtl
name = ARGV.shift?
vhost = @options["vhost"]? || "/"
abort @banner unless name
url = "/api/queues/#{URI.encode_www_form(vhost)}/#{name}"
url = "/api/queues/#{URI.encode_www_form(vhost)}/#{URI.encode_www_form(name)}"
resp = http.delete url
handle_response(resp, 204)
end
Expand All @@ -571,7 +571,7 @@ class LavinMQCtl
name = ARGV.shift?
vhost = @options["vhost"]? || "/"
abort @banner unless name && etype
url = "/api/exchanges/#{URI.encode_www_form(vhost)}/#{name}"
url = "/api/exchanges/#{URI.encode_www_form(vhost)}/#{URI.encode_www_form(name)}"
body = {
"type": etype,
"auto_delete": @options.has_key?("auto_delete"),
Expand All @@ -588,7 +588,7 @@ class LavinMQCtl
name = ARGV.shift?
vhost = @options["vhost"]? || "/"
abort @banner unless name
url = "/api/exchanges/#{URI.encode_www_form(vhost)}/#{name}"
url = "/api/exchanges/#{URI.encode_www_form(vhost)}/#{URI.encode_www_form(name)}"
resp = http.delete url
handle_response(resp, 204)
end
Expand Down

0 comments on commit 0224db4

Please sign in to comment.