Skip to content

Commit a57e4f9

Browse files
fix: restore CLI opts removed in config rewrite (#1833)
## Summary - Restore `--amqp-port`, `--mqtt-bind`, `--mqtt-port`, and `--mqtts-port` CLI flags unintentionally removed/renamed in #917 - Accept deprecated `[http]` INI section as alias for `[mgmt]` with deprecation warning - Add spec coverage for restored flags and `[http]` section alias
1 parent d0685dd commit a57e4f9

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

spec/config_spec.cr

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ describe LavinMQ::Config do
264264
"--http-bind=172.16.0.1",
265265
"--http-port=15673",
266266
"--http-unix-path=/tmp/http.sock",
267+
"--mqtt-bind=10.0.0.2",
268+
"--mqtt-port=1884",
269+
"--mqtts-port=8884",
267270
"--mqtt-unix-path=/tmp/mqtt.sock",
268271
"--https-port=15675",
269272
"--cert=/etc/ssl/cert.pem",
@@ -297,6 +300,9 @@ describe LavinMQ::Config do
297300
config.http_bind.should eq "172.16.0.1"
298301
config.http_port.should eq 15673
299302
config.http_unix_path.should eq "/tmp/http.sock"
303+
config.mqtt_bind.should eq "10.0.0.2"
304+
config.mqtt_port.should eq 1884
305+
config.mqtts_port.should eq 8884
300306
config.mqtt_unix_path.should eq "/tmp/mqtt.sock"
301307
config.https_port.should eq 15675
302308
config.tls_cert_path.should eq "/etc/ssl/cert.pem"
@@ -401,6 +407,23 @@ describe LavinMQ::Config do
401407
end
402408
end
403409

410+
it "accepts deprecated [http] section as alias for [mgmt]" do
411+
config_file = File.tempfile do |file|
412+
file.print <<-CONFIG
413+
[main]
414+
data_dir = /tmp/lavinmq-spec
415+
[http]
416+
port = 15699
417+
CONFIG
418+
end
419+
io = IO::Memory.new
420+
config = LavinMQ::Config.new(io)
421+
argv = ["-c", config_file.path]
422+
config.parse(argv)
423+
config.http_port.should eq 15699
424+
io.to_s.should match(/\[http\] is deprecated/)
425+
end
426+
404427
it "will not parse ini sections that do not exist" do
405428
config_file = File.tempfile do |file|
406429
file.print <<-CONFIG

src/lavinmq/config.cr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ module LavinMQ
116116
when {{section}}
117117
parse_section({{section}}, settings)
118118
{% end %}
119+
when "http"
120+
@io.puts "WARNING: Config section [http] is deprecated, use [mgmt] instead"
121+
parse_section("mgmt", settings)
119122
when .starts_with?("sni:") then parse_sni(section[4..], settings)
120123
when "replication"
121124
abort("#{file}: [replication] is deprecated and replaced with [clustering], see the README for more information")

src/lavinmq/config/options.cr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module LavinMQ
2828
@[CliOpt("-b BIND", "--bind=BIND", "IP address that both the AMQP and HTTP servers will listen on (default: 127.0.0.1)", ->parse_bind(String), section: "bindings")]
2929
property bind = "127.0.0.1"
3030

31-
@[CliOpt("-p PORT", "--port=PORT", "AMQP port to listen on (default: 5672)", section: "bindings")]
31+
@[CliOpt("-p PORT", "--amqp-port=PORT", "AMQP port to listen on (default: 5672)", section: "bindings")]
3232
@[IniOpt(ini_name: port, section: "amqp")]
3333
@[EnvOpt("LAVINMQ_AMQP_PORT")]
3434
property amqp_port = 5672
@@ -54,12 +54,15 @@ module LavinMQ
5454
@[EnvOpt("LAVINMQ_AMQPS_PORT")]
5555
property amqps_port = 5671
5656

57+
@[CliOpt("", "--mqtt-bind=BIND", "IP address that the MQTT server will listen on (default: 127.0.0.1)", section: "bindings")]
5758
@[IniOpt(ini_name: bind, section: "mqtt")]
5859
property mqtt_bind = "127.0.0.1"
5960

61+
@[CliOpt("", "--mqtt-port=PORT", "MQTT port to listen on (default: 1883)", section: "bindings")]
6062
@[IniOpt(ini_name: port, section: "mqtt")]
6163
property mqtt_port = 1883
6264

65+
@[CliOpt("", "--mqtts-port=PORT", "MQTTS port to listen on (default: 8883)", section: "bindings")]
6366
@[IniOpt(ini_name: tls_port, section: "mqtt")]
6467
property mqtts_port = 8883
6568

0 commit comments

Comments
 (0)