From c8d7ab610ee8a86963dc3d9d3b41e76f64070255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20=C5=81asocha?= Date: Thu, 25 Jun 2020 14:26:02 +0200 Subject: [PATCH 1/2] Add support for more complex passwords used in URL configuration userinfo part of URI allows to use percent-encoded characters, which should be decoded. It is important in cases when the password is randomly-generated and includes characters which are allowed as influxdb password but are reserved characters in URI. --- lib/influxdb/config.rb | 4 ++-- spec/influxdb/config_spec.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/influxdb/config.rb b/lib/influxdb/config.rb index 412052b..eaa4330 100644 --- a/lib/influxdb/config.rb +++ b/lib/influxdb/config.rb @@ -148,8 +148,8 @@ def opts_from_non_params(url) {}.tap do |o| o[:host] = url.host if url.host o[:port] = url.port if url.port - o[:username] = url.user if url.user - o[:password] = url.password if url.password + o[:username] = URI.decode_www_form_component(url.user) if url.user + o[:password] = URI.decode_www_form_component(url.password) if url.password o[:database] = url.path[1..-1] if url.path.length > 1 o[:use_ssl] = url.scheme == "https".freeze diff --git a/spec/influxdb/config_spec.rb b/spec/influxdb/config_spec.rb index c81e513..894fbdc 100644 --- a/spec/influxdb/config_spec.rb +++ b/spec/influxdb/config_spec.rb @@ -159,6 +159,15 @@ expect(conf).not_to be_async end + context "with encoded values" do + let(:url) { "https://weird%24user:weird%25pass@influx.example.com:8765/testdb" } + + it "decode encoded values" do + expect(conf.username).to eq "weird$user" + expect(conf.password).to eq "weird%pass" + end + end + context "UDP" do let(:url) { "udp://test.localhost:2345?discard_write_errors=1" } specify { expect(conf).to be_udp } From 71935046b1e3b0aafa8594bb2ac7c786777c7e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20=C5=81asocha?= Date: Thu, 25 Jun 2020 14:28:17 +0200 Subject: [PATCH 2/2] Formatting --- lib/influxdb/config.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/influxdb/config.rb b/lib/influxdb/config.rb index eaa4330..2bab493 100644 --- a/lib/influxdb/config.rb +++ b/lib/influxdb/config.rb @@ -146,11 +146,11 @@ def opts_from_url(url) def opts_from_non_params(url) {}.tap do |o| - o[:host] = url.host if url.host - o[:port] = url.port if url.port - o[:username] = URI.decode_www_form_component(url.user) if url.user - o[:password] = URI.decode_www_form_component(url.password) if url.password - o[:database] = url.path[1..-1] if url.path.length > 1 + o[:host] = url.host if url.host + o[:port] = url.port if url.port + o[:username] = URI.decode_www_form_component(url.user) if url.user + o[:password] = URI.decode_www_form_component(url.password) if url.password + o[:database] = url.path[1..-1] if url.path.length > 1 o[:use_ssl] = url.scheme == "https".freeze o[:udp] = { host: o[:host], port: o[:port] } if url.scheme == "udp"