elastomer-client 6.2.3 → 6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +4 -1
- data/.gitignore +1 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +3 -1
- data/elastomer-client.gemspec +2 -2
- data/gemfiles/faraday_1.gemfile +27 -0
- data/gemfiles/faraday_2.gemfile +30 -0
- data/lib/elastomer_client/client/rest_api_spec/api_spec_v8_19.rb +8721 -0
- data/lib/elastomer_client/client.rb +8 -4
- data/lib/elastomer_client/version.rb +1 -1
- data/test/client_test.rb +14 -45
- metadata +17 -8
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "addressable/template"
|
|
4
4
|
require "faraday"
|
|
5
|
-
require "
|
|
5
|
+
require "faraday/gzip"
|
|
6
6
|
require "multi_json"
|
|
7
7
|
require "semantic"
|
|
8
8
|
require "zlib"
|
|
@@ -132,7 +132,7 @@ module ElastomerClient
|
|
|
132
132
|
@connection ||= Faraday.new(url) do |conn|
|
|
133
133
|
conn.response(:parse_json)
|
|
134
134
|
# Request compressed responses from ES and decompress them
|
|
135
|
-
conn.
|
|
135
|
+
conn.request(:gzip)
|
|
136
136
|
conn.request(:encode_json)
|
|
137
137
|
conn.request(:limit_size, max_request_size:) if max_request_size
|
|
138
138
|
conn.request(:elastomer_compress, compression:) if compress_body
|
|
@@ -140,10 +140,14 @@ module ElastomerClient
|
|
|
140
140
|
conn.options[:timeout] = read_timeout
|
|
141
141
|
conn.options[:open_timeout] = open_timeout
|
|
142
142
|
|
|
143
|
+
# Faraday 2 removed the Connection#token_auth and #basic_auth helpers, and the
|
|
144
|
+
# :authorization middleware emits different header formats across Faraday majors.
|
|
145
|
+
# Set the Authorization header directly so the output is identical on 1.x and 2.x.
|
|
143
146
|
if token_auth?
|
|
144
|
-
conn.
|
|
147
|
+
conn.headers["Authorization"] = %(Token token="#{@token_auth}")
|
|
145
148
|
elsif basic_auth?
|
|
146
|
-
|
|
149
|
+
credentials = ["#{@basic_auth[:username]}:#{@basic_auth[:password]}"].pack("m0")
|
|
150
|
+
conn.headers["Authorization"] = "Basic #{credentials}"
|
|
147
151
|
end
|
|
148
152
|
|
|
149
153
|
@connection_block&.call(conn)
|
data/test/client_test.rb
CHANGED
|
@@ -13,15 +13,15 @@ describe ElastomerClient::Client do
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it "allows configuring the Faraday when a block is given" do
|
|
16
|
-
assert ElastomerClient::Client.new.connection.builder.handlers.none? { |handler| handler.klass ==
|
|
16
|
+
assert ElastomerClient::Client.new.connection.builder.handlers.none? { |handler| handler.klass == ElastomerClient::Middleware::OpaqueId }
|
|
17
17
|
|
|
18
18
|
c = ElastomerClient::Client.new do |connection|
|
|
19
19
|
assert_kind_of(Faraday::Connection, connection)
|
|
20
20
|
|
|
21
|
-
connection.
|
|
21
|
+
connection.request :opaque_id
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
assert c.connection.builder.handlers.any? { |handler| handler.klass ==
|
|
24
|
+
assert c.connection.builder.handlers.any? { |handler| handler.klass == ElastomerClient::Middleware::OpaqueId }
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
it "use Faraday's default adapter if none is specified" do
|
|
@@ -145,14 +145,9 @@ describe ElastomerClient::Client do
|
|
|
145
145
|
})
|
|
146
146
|
client = ElastomerClient::Client.new(**client_params)
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
basic_auth_spy = Spy.on(connection, :basic_auth).and_return(nil)
|
|
148
|
+
expected = "Basic #{["my_user:my_secret_password"].pack("m0")}"
|
|
150
149
|
|
|
151
|
-
|
|
152
|
-
client.ping
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
assert basic_auth_spy.has_been_called_with?("my_user", "my_secret_password")
|
|
150
|
+
assert_equal expected, client.connection.headers["Authorization"]
|
|
156
151
|
end
|
|
157
152
|
|
|
158
153
|
it "ignores basic authentication if password is missing" do
|
|
@@ -161,14 +156,7 @@ describe ElastomerClient::Client do
|
|
|
161
156
|
})
|
|
162
157
|
client = ElastomerClient::Client.new(**client_params)
|
|
163
158
|
|
|
164
|
-
|
|
165
|
-
basic_auth_spy = Spy.on(connection, :basic_auth).and_return(nil)
|
|
166
|
-
|
|
167
|
-
Faraday.stub(:new, $client_params[:url], connection) do
|
|
168
|
-
client.ping
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
refute_predicate basic_auth_spy, :has_been_called?
|
|
159
|
+
refute client.connection.headers.key?("Authorization")
|
|
172
160
|
end
|
|
173
161
|
|
|
174
162
|
it "ignores basic authentication if username is missing" do
|
|
@@ -177,28 +165,14 @@ describe ElastomerClient::Client do
|
|
|
177
165
|
})
|
|
178
166
|
client = ElastomerClient::Client.new(**client_params)
|
|
179
167
|
|
|
180
|
-
|
|
181
|
-
basic_auth_spy = Spy.on(connection, :basic_auth).and_return(nil)
|
|
182
|
-
|
|
183
|
-
Faraday.stub(:new, $client_params[:url], connection) do
|
|
184
|
-
client.ping
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
refute_predicate basic_auth_spy, :has_been_called?
|
|
168
|
+
refute client.connection.headers.key?("Authorization")
|
|
188
169
|
end
|
|
189
170
|
|
|
190
171
|
it "can use token authentication" do
|
|
191
172
|
client_params = $client_params.merge(token_auth: "my_secret_token")
|
|
192
173
|
client = ElastomerClient::Client.new(**client_params)
|
|
193
174
|
|
|
194
|
-
|
|
195
|
-
token_auth_spy = Spy.on(connection, :token_auth).and_return(nil)
|
|
196
|
-
|
|
197
|
-
Faraday.stub(:new, $client_params[:url], connection) do
|
|
198
|
-
client.ping
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
assert token_auth_spy.has_been_called_with?("my_secret_token")
|
|
175
|
+
assert_equal %(Token token="my_secret_token"), client.connection.headers["Authorization"]
|
|
202
176
|
end
|
|
203
177
|
|
|
204
178
|
it "prefers token authentication over basic" do
|
|
@@ -208,16 +182,7 @@ describe ElastomerClient::Client do
|
|
|
208
182
|
}, token_auth: "my_secret_token")
|
|
209
183
|
client = ElastomerClient::Client.new(**client_params)
|
|
210
184
|
|
|
211
|
-
|
|
212
|
-
basic_auth_spy = Spy.on(connection, :basic_auth).and_return(nil)
|
|
213
|
-
token_auth_spy = Spy.on(connection, :token_auth).and_return(nil)
|
|
214
|
-
|
|
215
|
-
Faraday.stub(:new, $client_params[:url], connection) do
|
|
216
|
-
client.ping
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
refute_predicate basic_auth_spy, :has_been_called?
|
|
220
|
-
assert token_auth_spy.has_been_called_with?("my_secret_token")
|
|
185
|
+
assert_equal %(Token token="my_secret_token"), client.connection.headers["Authorization"]
|
|
221
186
|
end
|
|
222
187
|
end
|
|
223
188
|
|
|
@@ -372,11 +337,15 @@ describe ElastomerClient::Client do
|
|
|
372
337
|
it "adding retry logic retries up to 2 times" do
|
|
373
338
|
retry_count = 0
|
|
374
339
|
|
|
340
|
+
# :retry maps to Faraday::Request::Retry on Faraday 1.x and Faraday::Retry::Middleware
|
|
341
|
+
# on Faraday 2.x (via faraday-retry). Look up whichever the running Faraday registers.
|
|
342
|
+
retry_klass = Faraday::Request.lookup_middleware(:retry)
|
|
343
|
+
|
|
375
344
|
retry_options = {
|
|
376
345
|
max: 2,
|
|
377
346
|
interval: 0.05,
|
|
378
347
|
methods: [:get],
|
|
379
|
-
exceptions:
|
|
348
|
+
exceptions: retry_klass::DEFAULT_EXCEPTIONS + [Faraday::ConnectionFailed],
|
|
380
349
|
retry_block: proc { |env, options, retries, exc| retry_count += 1 }
|
|
381
350
|
}
|
|
382
351
|
retry_client = ElastomerClient::Client.new(port: 9205) do |connection|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: elastomer-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 6.
|
|
4
|
+
version: 6.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tim Pease
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2026-06-25 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: addressable
|
|
@@ -31,28 +31,34 @@ dependencies:
|
|
|
31
31
|
requirements:
|
|
32
32
|
- - ">="
|
|
33
33
|
- !ruby/object:Gem::Version
|
|
34
|
-
version: '0
|
|
34
|
+
version: '1.0'
|
|
35
|
+
- - "<"
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '3'
|
|
35
38
|
type: :runtime
|
|
36
39
|
prerelease: false
|
|
37
40
|
version_requirements: !ruby/object:Gem::Requirement
|
|
38
41
|
requirements:
|
|
39
42
|
- - ">="
|
|
40
43
|
- !ruby/object:Gem::Version
|
|
41
|
-
version: '0
|
|
44
|
+
version: '1.0'
|
|
45
|
+
- - "<"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3'
|
|
42
48
|
- !ruby/object:Gem::Dependency
|
|
43
|
-
name:
|
|
49
|
+
name: faraday-gzip
|
|
44
50
|
requirement: !ruby/object:Gem::Requirement
|
|
45
51
|
requirements:
|
|
46
52
|
- - ">="
|
|
47
53
|
- !ruby/object:Gem::Version
|
|
48
|
-
version: '0
|
|
54
|
+
version: '1.0'
|
|
49
55
|
type: :runtime
|
|
50
56
|
prerelease: false
|
|
51
57
|
version_requirements: !ruby/object:Gem::Requirement
|
|
52
58
|
requirements:
|
|
53
59
|
- - ">="
|
|
54
60
|
- !ruby/object:Gem::Version
|
|
55
|
-
version: '0
|
|
61
|
+
version: '1.0'
|
|
56
62
|
- !ruby/object:Gem::Dependency
|
|
57
63
|
name: multi_json
|
|
58
64
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -120,6 +126,8 @@ files:
|
|
|
120
126
|
- docs/snapshots.md
|
|
121
127
|
- docs/templates.md
|
|
122
128
|
- elastomer-client.gemspec
|
|
129
|
+
- gemfiles/faraday_1.gemfile
|
|
130
|
+
- gemfiles/faraday_2.gemfile
|
|
123
131
|
- lib/elastomer_client/client.rb
|
|
124
132
|
- lib/elastomer_client/client/bulk.rb
|
|
125
133
|
- lib/elastomer_client/client/ccr.rb
|
|
@@ -141,6 +149,7 @@ files:
|
|
|
141
149
|
- lib/elastomer_client/client/rest_api_spec/api_spec_v8_13.rb
|
|
142
150
|
- lib/elastomer_client/client/rest_api_spec/api_spec_v8_17.rb
|
|
143
151
|
- lib/elastomer_client/client/rest_api_spec/api_spec_v8_18.rb
|
|
152
|
+
- lib/elastomer_client/client/rest_api_spec/api_spec_v8_19.rb
|
|
144
153
|
- lib/elastomer_client/client/rest_api_spec/api_spec_v8_7.rb
|
|
145
154
|
- lib/elastomer_client/client/rest_api_spec/rest_api.rb
|
|
146
155
|
- lib/elastomer_client/client/scroller.rb
|
|
@@ -212,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
212
221
|
- !ruby/object:Gem::Version
|
|
213
222
|
version: '0'
|
|
214
223
|
requirements: []
|
|
215
|
-
rubygems_version: 3.
|
|
224
|
+
rubygems_version: 3.4.10
|
|
216
225
|
signing_key:
|
|
217
226
|
specification_version: 4
|
|
218
227
|
summary: A library for interacting with Elasticsearch
|