influxdb-client 1.18.0.pre.3131 → 2.0.0.pre.3196

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73bf8b9baedd893accddf4d4a1523f33cf08402266d777ca65505425f087932d
4
- data.tar.gz: 669fc3647f594bc35e7e986681d124205a48cfcae3442c30ac02f38e4527b97c
3
+ metadata.gz: 33f286d2a281bd72623ee0284de96e20aebfc433a39642478c43f31d0258ee50
4
+ data.tar.gz: 98d9e3ddc4d6e892daa5bfeba7601af15e4c4da0440ad1ea8fa0d7740e38e21a
5
5
  SHA512:
6
- metadata.gz: faa26cfa1227c175a181a5a8b07f4d4bae703370a9e156db962a16fab59d8e068b85ee7baf00b3d77dd5ddb9f5db2ba7400009aefcc302f4655cca3412113cdd
7
- data.tar.gz: 321a5771affde50b2ebba68fed2bde826840f904b3a8f92c60885974d60adf57e260a207fe6cc15501c24ccee9a5eca4b39f91945f124e345d0487adf66e9c56
6
+ metadata.gz: f2f655f21aa5f143abc469b653a90bc9ca381371ad4c60d2bf35fc7019e0e1b6f8ce3d4403f30acaff03a134b0d31bc42c7001dc893dd5db9ad7d08b705dbfbc
7
+ data.tar.gz: 95f5b211418be1dd31067dd7f266cbb2a57dc8736e66147908ae6c5edf48036ed021ae299915b04c3d19783d1962f487623f01881bceb27dba08f8d60696170e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
- ## 1.18.0 [unreleased]
1
+ ## 2.0.0 [unreleased]
2
2
 
3
+ ### Breaking Changes
4
+ Due to a security reason `Authorization` header is not forwarded when redirect leads to a different domain.
5
+ To overcome this limitation you have to set the client property `redirect_forward_authorization` to `true`.
6
+
7
+ ### Features
8
+ 1. [#89](https://github.com/influxdata/influxdb-client-ruby/pull/89): `Authorization` header is not forwarded when redirect leads to a different domain
9
+
10
+ ### Bug Fixes
11
+ 1. [#89](https://github.com/influxdata/influxdb-client-ruby/pull/89): Correct redirect location
12
+
3
13
  ## 1.17.0 [2021-08-20]
4
14
 
5
15
  ### Bug Fixes
data/README.md CHANGED
@@ -23,6 +23,7 @@ This repository contains the reference Ruby client for the InfluxDB 2.0.
23
23
  - [Management API](#management-api)
24
24
  - [Advanced Usage](#advanced-usage)
25
25
  - [Default Tags](#default-tags)
26
+ - [Proxy configuration](#proxy-configuration)
26
27
  - [Contributing](#contributing)
27
28
  - [License](#license)
28
29
 
@@ -93,6 +94,7 @@ client = InfluxDB2::Client.new('https://localhost:8086', 'my-token')
93
94
  | write_timeout | Number of seconds to wait for one block of data to be written | Integer | 10 |
94
95
  | read_timeout | Number of seconds to wait for one block of data to be read | Integer | 10 |
95
96
  | max_redirect_count | Maximal number of followed HTTP redirects | Integer | 10 |
97
+ | redirect_forward_authorization | Pass Authorization header to different domain during HTTP redirect. | bool | false |
96
98
  | use_ssl | Turn on/off SSL for HTTP communication | bool | true |
97
99
  | verify_mode | Sets the flags for the certification verification at beginning of SSL/TLS session. | `OpenSSL::SSL::VERIFY_NONE` or `OpenSSL::SSL::VERIFY_PEER` | none |
98
100
 
@@ -400,6 +402,20 @@ client.close!
400
402
 
401
403
  Server availability can be checked using the `client.health` method. That is equivalent of the [influx ping](https://v2.docs.influxdata.com/v2.0/reference/cli/influx/ping/).
402
404
 
405
+ ### Proxy configuration
406
+
407
+ You can configure the client to tunnel requests through an HTTP proxy. To configure the proxy use a `http_proxy` environment variable.
408
+
409
+ ```ruby
410
+ ENV['HTTP_PROXY'] = 'http://my-user:my-password@my-proxy:8099'
411
+ ```
412
+
413
+ Client automatically follows HTTP redirects. The default redirect policy is to follow up to 10 consecutive requests.
414
+ You can configure redirect counts by the client property: `max_redirect_count`.
415
+
416
+ Due to a security reason `Authorization` header is not forwarded when redirect leads to a different domain.
417
+ To overcome this limitation you have to set the client property `redirect_forward_authorization` to `true`.
418
+
403
419
  ### InfluxDB 1.8 API compatibility
404
420
 
405
421
  [InfluxDB 1.8.0 introduced forward compatibility APIs](https://docs.influxdata.com/influxdb/v1.8/tools/api/#influxdb-2-0-api-compatibility-endpoints) for InfluxDB 2.0. This allow you to easily move from InfluxDB 1.x to InfluxDB 2.0 Cloud or open source.
@@ -42,6 +42,8 @@ module InfluxDB2
42
42
  # @option options [Integer] :write_timeout Number of seconds to wait for one block of data to be written
43
43
  # @option options [Integer] :read_timeout Number of seconds to wait for one block of data to be read
44
44
  # @option options [Integer] :max_redirect_count Maximal number of followed HTTP redirects
45
+ # @option options [bool] :redirect_forward_authorization Pass Authorization header to different domain
46
+ # during HTTP redirect.
45
47
  # @option options [bool] :use_ssl Turn on/off SSL for HTTP communication
46
48
  # @option options [Integer] :verify_mode Sets the flags for the certification verification
47
49
  # at beginning of SSL/TLS session. Could be one of `OpenSSL::SSL::VERIFY_NONE` or `OpenSSL::SSL::VERIFY_PEER`.
@@ -73,21 +73,24 @@ module InfluxDB2
73
73
  _post(payload, uri, headers: headers.merge(HEADER_CONTENT_TYPE => 'text/plain'))
74
74
  end
75
75
 
76
- def _post(payload, uri, limit: @max_redirect_count, headers: {})
77
- _request(payload, uri, limit: limit, headers: headers, request: Net::HTTP::Post)
76
+ def _post(payload, uri, limit: @max_redirect_count, add_authorization: true, headers: {})
77
+ _request(payload, uri, limit: limit, add_authorization: add_authorization,
78
+ headers: headers, request: Net::HTTP::Post)
78
79
  end
79
80
 
80
- def _get(uri, limit: @max_redirect_count, headers: {})
81
- _request(nil, uri, limit: limit, headers: headers.merge('Accept' => 'application/json'), request: Net::HTTP::Get)
81
+ def _get(uri, limit: @max_redirect_count, add_authorization: true, headers: {})
82
+ _request(nil, uri, limit: limit, add_authorization: add_authorization,
83
+ headers: headers.merge('Accept' => 'application/json'), request: Net::HTTP::Get)
82
84
  end
83
85
 
84
- def _request(payload, uri, limit: @max_redirect_count, headers: {}, request: Net::HTTP::Post)
86
+ def _request(payload, uri, limit: @max_redirect_count, add_authorization: true, headers: {},
87
+ request: Net::HTTP::Post)
85
88
  raise InfluxError.from_message("Too many HTTP redirects. Exceeded limit: #{@max_redirect_count}") if limit.zero?
86
89
 
87
90
  http = _prepare_http_client(uri)
88
91
 
89
92
  request = request.new(uri.request_uri)
90
- request['Authorization'] = "Token #{@options[:token]}"
93
+ request['Authorization'] = "Token #{@options[:token]}" if add_authorization
91
94
  request['User-Agent'] = "influxdb-client-ruby/#{InfluxDB2::VERSION}"
92
95
  headers.each { |k, v| request[k] = v }
93
96
 
@@ -100,7 +103,16 @@ module InfluxDB2
100
103
  response
101
104
  when Net::HTTPRedirection then
102
105
  location = response['location']
103
- _post(payload, URI.parse(location), limit: limit - 1, headers: headers)
106
+ redirect_forward_authorization = @options[:redirect_forward_authorization] || false
107
+
108
+ uri_redirect = URI.parse(location)
109
+ uri_redirect.query = uri.query
110
+ uri_redirect.path = File.join(uri_redirect.path, uri.path)
111
+
112
+ redirect_forward_authorization ||= (uri_redirect.host == uri.host) && (uri_redirect.port == uri.port)
113
+
114
+ _post(payload, uri_redirect, limit: limit - 1, add_authorization: redirect_forward_authorization,
115
+ headers: headers)
104
116
  else
105
117
  raise InfluxError.from_response(response)
106
118
  end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module InfluxDB2
22
- VERSION = '1.18.0'.freeze
22
+ VERSION = '2.0.0'.freeze
23
23
  end
@@ -0,0 +1,145 @@
1
+ # The MIT License
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'test_helper'
22
+
23
+ class WriteApiTest < MiniTest::Test
24
+ def setup
25
+ WebMock.disable_net_connect!
26
+ end
27
+
28
+ def test_redirect_same
29
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
30
+ .to_return(status: 307, headers:
31
+ { 'location' => 'http://localhost:8086' })
32
+ .then.to_return(status: 204)
33
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
34
+ .to_return(status: 204)
35
+
36
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
37
+ bucket: 'my-bucket',
38
+ org: 'my-org',
39
+ precision: InfluxDB2::WritePrecision::NANOSECOND,
40
+ use_ssl: false)
41
+
42
+ client.create_write_api.write(data: 'h2o,location=west value=33i 15')
43
+
44
+ headers = {
45
+ 'Authorization' => 'Token my-token',
46
+ 'User-Agent' => "influxdb-client-ruby/#{InfluxDB2::VERSION}",
47
+ 'Content-Type' => 'text/plain'
48
+ }
49
+
50
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
51
+ times: 1, body: 'h2o,location=west value=33i 15', headers: headers)
52
+ end
53
+
54
+ def test_redirect_301
55
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
56
+ .to_return(status: 301, headers:
57
+ { 'location' => 'http://localhost:9090/' })
58
+ .then.to_return(status: 204)
59
+ stub_request(:any, 'http://localhost:9090/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
60
+ .to_return(status: 204)
61
+
62
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
63
+ bucket: 'my-bucket',
64
+ org: 'my-org',
65
+ precision: InfluxDB2::WritePrecision::NANOSECOND,
66
+ use_ssl: false)
67
+
68
+ client.create_write_api.write(data: 'h2o,location=west value=33i 15')
69
+
70
+ headers = {
71
+ 'Authorization' => 'Token my-token',
72
+ 'User-Agent' => "influxdb-client-ruby/#{InfluxDB2::VERSION}",
73
+ 'Content-Type' => 'text/plain'
74
+ }
75
+
76
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
77
+ times: 1, body: 'h2o,location=west value=33i 15', headers: headers)
78
+
79
+ assert_not_requested(:post, 'http://localhost:9090/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
80
+ times: 1, body: 'h2o,location=west value=33i 15', headers: headers)
81
+
82
+ assert_requested(:post, 'http://localhost:9090/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
83
+ times: 1, body: 'h2o,location=west value=33i 15')
84
+ end
85
+
86
+ def test_redirect_301_allow
87
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
88
+ .to_return(status: 301, headers:
89
+ { 'location' => 'http://localhost:9090/' })
90
+ .then.to_return(status: 204)
91
+ stub_request(:any, 'http://localhost:9090/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
92
+ .to_return(status: 204)
93
+
94
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
95
+ bucket: 'my-bucket',
96
+ org: 'my-org',
97
+ precision: InfluxDB2::WritePrecision::NANOSECOND,
98
+ use_ssl: false,
99
+ redirect_forward_authorization: true)
100
+
101
+ client.create_write_api.write(data: 'h2o,location=west value=33i 15')
102
+
103
+ headers = {
104
+ 'Authorization' => 'Token my-token',
105
+ 'User-Agent' => "influxdb-client-ruby/#{InfluxDB2::VERSION}",
106
+ 'Content-Type' => 'text/plain'
107
+ }
108
+
109
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
110
+ times: 1, body: 'h2o,location=west value=33i 15', headers: headers)
111
+
112
+ assert_requested(:post, 'http://localhost:9090/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
113
+ times: 1, body: 'h2o,location=west value=33i 15', headers: headers)
114
+ end
115
+
116
+ def test_redirect_different_path
117
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
118
+ .to_return(status: 301, headers:
119
+ { 'location' => 'http://localhost:8086/influxdb/' })
120
+ .then.to_return(status: 204)
121
+ stub_request(:any, 'http://localhost:8086/influxdb/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
122
+ .to_return(status: 204)
123
+
124
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
125
+ bucket: 'my-bucket',
126
+ org: 'my-org',
127
+ precision: InfluxDB2::WritePrecision::NANOSECOND,
128
+ use_ssl: false,
129
+ redirect_forward_authorization: true)
130
+
131
+ client.create_write_api.write(data: 'h2o,location=west value=33i 15')
132
+
133
+ headers = {
134
+ 'Authorization' => 'Token my-token',
135
+ 'User-Agent' => "influxdb-client-ruby/#{InfluxDB2::VERSION}",
136
+ 'Content-Type' => 'text/plain'
137
+ }
138
+
139
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
140
+ times: 1, body: 'h2o,location=west value=33i 15', headers: headers)
141
+
142
+ assert_requested(:post, 'http://localhost:8086/influxdb/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
143
+ times: 1, body: 'h2o,location=west value=33i 15', headers: headers)
144
+ end
145
+ end
@@ -201,7 +201,7 @@ class WriteApiTest < MiniTest::Test
201
201
  def test_follow_redirect
202
202
  stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
203
203
  .to_return(status: 307, headers:
204
- { 'location' => 'http://localhost:9090/api/v2/write?bucket=my-bucket&org=my-org&precision=ns' })
204
+ { 'location' => 'http://localhost:9090/' })
205
205
  .then.to_return(status: 204)
206
206
  stub_request(:any, 'http://localhost:9090/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
207
207
  .to_return(status: 204)
@@ -223,7 +223,7 @@ class WriteApiTest < MiniTest::Test
223
223
  def test_follow_redirect_max
224
224
  stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
225
225
  .to_return(status: 307, headers:
226
- { 'location' => 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns' })
226
+ { 'location' => 'http://localhost:8086/' })
227
227
 
228
228
  client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
229
229
  bucket: 'my-bucket',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.18.0.pre.3131
4
+ version: 2.0.0.pre.3196
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Bednar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-20 00:00:00.000000000 Z
11
+ date: 2021-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -161,6 +161,7 @@ files:
161
161
  - test/influxdb/query_api_integration_test.rb
162
162
  - test/influxdb/query_api_stream_test.rb
163
163
  - test/influxdb/query_api_test.rb
164
+ - test/influxdb/redirect_test.rb
164
165
  - test/influxdb/write_api_batching_test.rb
165
166
  - test/influxdb/write_api_integration_test.rb
166
167
  - test/influxdb/write_api_test.rb
@@ -201,6 +202,7 @@ test_files:
201
202
  - test/influxdb/query_api_integration_test.rb
202
203
  - test/influxdb/query_api_stream_test.rb
203
204
  - test/influxdb/query_api_test.rb
205
+ - test/influxdb/redirect_test.rb
204
206
  - test/influxdb/write_api_batching_test.rb
205
207
  - test/influxdb/write_api_integration_test.rb
206
208
  - test/influxdb/write_api_test.rb